Switch M17 Rx sample rate to 5SPS

Due to the RRC computation sometimes violating the timing constraints,
we switched the M17 demodulator to 5 samples per symbol (24KHz), thus
dividing the processing time by four ar the number of samples halves as
well as the number of taps of the RRC.
Minor adaptation on the code followed.

TG-81
This commit is contained in:
Niccolò Izzo 2022-04-26 08:41:48 +02:00 committed by Silvano Seva
parent 63bd864674
commit 2d59658d60
6 changed files with 51 additions and 31 deletions

View File

@ -34,43 +34,62 @@ namespace M17
{ {
/* /*
* Coefficients for M17 RRC filter * Coefficients for M17 RRC filters
*/ */
static constexpr std::array<float, 81> rrc_taps = static constexpr std::array<float, 81> rrc_taps_48k =
{ {
-0.003195702904062073, -0.002930279157647190, -0.001940667871554463, -0.003195702904062073, -0.002930279157647190, -0.001940667871554463,
-0.000356087678023658, 0.001547011339077758, 0.003389554791179751, -0.000356087678023658, 0.001547011339077758, 0.003389554791179751,
0.004761898604225673, 0.005310860846138910, 0.004824746306020221, 0.004761898604225673, 0.005310860846138910, 0.004824746306020221,
0.003297923526848786, 0.000958710871218619, -0.001749908029791816, 0.003297923526848786, 0.000958710871218619, -0.001749908029791816,
-0.004238694106631223, -0.005881783042101693, -0.006150256456781309, -0.004238694106631223, -0.005881783042101693, -0.006150256456781309,
-0.004745376707651645, -0.001704189656473565, 0.002547854551539951, -0.004745376707651645, -0.001704189656473565, 0.002547854551539951,
0.007215575568844704, 0.011231038205363532, 0.013421952197060707, 0.007215575568844704, 0.011231038205363532, 0.013421952197060707,
0.012730475385624438, 0.008449554307303753, 0.000436744366018287, 0.012730475385624438, 0.008449554307303753, 0.000436744366018287,
-0.010735380379191660, -0.023726883538258272, -0.036498030780605324, -0.010735380379191660, -0.023726883538258272, -0.036498030780605324,
-0.046500883189991064, -0.050979050575999614, -0.047340680079891187, -0.046500883189991064, -0.050979050575999614, -0.047340680079891187,
-0.033554880492651755, -0.008513823955725943, 0.027696543159614194, -0.033554880492651755, -0.008513823955725943, 0.027696543159614194,
0.073664520037517042, 0.126689053778116234, 0.182990955139333916, 0.073664520037517042, 0.126689053778116234, 0.182990955139333916,
0.238080025892859704, 0.287235637987091563, 0.326040247765297220, 0.238080025892859704, 0.287235637987091563, 0.326040247765297220,
0.350895727088112619, 0.359452932027607974, 0.350895727088112619, 0.350895727088112619, 0.359452932027607974, 0.350895727088112619,
0.326040247765297220, 0.287235637987091563, 0.238080025892859704, 0.326040247765297220, 0.287235637987091563, 0.238080025892859704,
0.182990955139333916, 0.126689053778116234, 0.073664520037517042, 0.182990955139333916, 0.126689053778116234, 0.073664520037517042,
0.027696543159614194, -0.008513823955725943, -0.033554880492651755, 0.027696543159614194, -0.008513823955725943, -0.033554880492651755,
-0.047340680079891187, -0.050979050575999614, -0.046500883189991064, -0.047340680079891187, -0.050979050575999614, -0.046500883189991064,
-0.036498030780605324, -0.023726883538258272, -0.010735380379191660, -0.036498030780605324, -0.023726883538258272, -0.010735380379191660,
0.000436744366018287, 0.008449554307303753, 0.012730475385624438, 0.000436744366018287, 0.008449554307303753, 0.012730475385624438,
0.013421952197060707, 0.011231038205363532, 0.007215575568844704, 0.013421952197060707, 0.011231038205363532, 0.007215575568844704,
0.002547854551539951, -0.001704189656473565, -0.004745376707651645, 0.002547854551539951, -0.001704189656473565, -0.004745376707651645,
-0.006150256456781309, -0.005881783042101693, -0.004238694106631223, -0.006150256456781309, -0.005881783042101693, -0.004238694106631223,
-0.001749908029791816, 0.000958710871218619, 0.003297923526848786, -0.001749908029791816, 0.000958710871218619, 0.003297923526848786,
0.004824746306020221, 0.005310860846138910, 0.004761898604225673, 0.004824746306020221, 0.005310860846138910, 0.004761898604225673,
0.003389554791179751, 0.001547011339077758, -0.000356087678023658, 0.003389554791179751, 0.001547011339077758, -0.000356087678023658,
-0.001940667871554463, -0.002930279157647190, -0.003195702904062073, -0.001940667871554463, -0.002930279157647190, -0.003195702904062073,
}; };
static constexpr std::array<float, 41> rrc_taps_24k =
{
-0.00451938415438936, -0.00274450532197076, 0.00218779365365964,
0.00673430845820838, 0.00682318809319229, 0.00135581524631680,
-0.00599438920196964, -0.00869773330332975, -0.00241007626827605,
0.0102043146279916, 0.0189814134484353, 0.0119494155102909,
-0.0151820458389266, -0.0516157561976790, -0.0720949100387685,
-0.0474535336210882, 0.0391686342706687, 0.179164496628150,
0.336694345124862, 0.461088271869920, 0.508340710642860,
0.461088271869920, 0.336694345124862, 0.179164496628150,
0.0391686342706687, -0.0474535336210882, -0.0720949100387685,
-0.0516157561976790, -0.0151820458389266, 0.0119494155102909,
0.0189814134484353, 0.0102043146279916, -0.00241007626827605,
-0.00869773330332975, -0.00599438920196964, 0.00135581524631680,
0.00682318809319229, 0.00673430845820838, 0.00218779365365964,
-0.00274450532197076, -0.00451938415438936
};
/* /*
* FIR implementation of the RRC filter for baseband audio generation. * FIR implementations of the RRC filter for baseband audio generation.
*/ */
extern Fir< std::tuple_size< decltype(rrc_taps) >::value > rrc; extern Fir< std::tuple_size< decltype(rrc_taps_48k) >::value > rrc_48k;
extern Fir< std::tuple_size< decltype(rrc_taps_24k) >::value > rrc_24k;
} /* M17 */ } /* M17 */

View File

@ -115,7 +115,7 @@ private:
static constexpr size_t M17_SYMBOL_RATE = 4800; static constexpr size_t M17_SYMBOL_RATE = 4800;
static constexpr size_t M17_FRAME_SYMBOLS = 192; static constexpr size_t M17_FRAME_SYMBOLS = 192;
static constexpr size_t M17_SYNCWORD_SYMBOLS = 8; static constexpr size_t M17_SYNCWORD_SYMBOLS = 8;
static constexpr size_t M17_RX_SAMPLE_RATE = 48000; static constexpr size_t M17_RX_SAMPLE_RATE = 24000;
static constexpr size_t M17_SAMPLES_PER_SYMBOL = M17_RX_SAMPLE_RATE / M17_SYMBOL_RATE; static constexpr size_t M17_SAMPLES_PER_SYMBOL = M17_RX_SAMPLE_RATE / M17_SYMBOL_RATE;
static constexpr size_t M17_FRAME_BYTES = M17_FRAME_SYMBOLS / 4; static constexpr size_t M17_FRAME_BYTES = M17_FRAME_SYMBOLS / 4;
@ -123,7 +123,7 @@ private:
static constexpr size_t M17_SAMPLE_BUF_SIZE = M17_FRAME_SAMPLES / 2; static constexpr size_t M17_SAMPLE_BUF_SIZE = M17_FRAME_SAMPLES / 2;
static constexpr size_t M17_BRIDGE_SIZE = M17_SAMPLES_PER_SYMBOL * M17_SYNCWORD_SYMBOLS; static constexpr size_t M17_BRIDGE_SIZE = M17_SAMPLES_PER_SYMBOL * M17_SYNCWORD_SYMBOLS;
static constexpr float CONV_STATS_ALPHA = 0.001f; static constexpr float CONV_STATS_ALPHA = 0.005f;
static constexpr float CONV_THRESHOLD_FACTOR = 3.40; static constexpr float CONV_THRESHOLD_FACTOR = 3.40;
static constexpr int16_t QNT_SMA_WINDOW = 8; static constexpr int16_t QNT_SMA_WINDOW = 8;

View File

@ -20,4 +20,5 @@
#include <M17/M17DSP.h> #include <M17/M17DSP.h>
Fir< std::tuple_size< decltype(M17::rrc_taps) >::value > M17::rrc(M17::rrc_taps); Fir< std::tuple_size< decltype(M17::rrc_taps_48k) >::value > M17::rrc_48k(M17::rrc_taps_48k);
Fir< std::tuple_size< decltype(M17::rrc_taps_24k) >::value > M17::rrc_24k(M17::rrc_taps_24k);

View File

@ -103,7 +103,7 @@ void M17Demodulator::stopBasebandSampling()
void M17Demodulator::resetCorrelationStats() void M17Demodulator::resetCorrelationStats()
{ {
conv_emvar = 80000000.0f; conv_emvar = 40000000.0f;
} }
/** /**
@ -307,7 +307,7 @@ bool M17Demodulator::update()
for(size_t i = 0; i < baseband.len; i++) for(size_t i = 0; i < baseband.len; i++)
{ {
float elem = static_cast< float >(baseband.data[i]); float elem = static_cast< float >(baseband.data[i]);
baseband.data[i] = static_cast< int16_t >(M17::rrc(elem)); baseband.data[i] = static_cast< int16_t >(M17::rrc_24k(elem));
} }
// Process the buffer // Process the buffer
@ -324,7 +324,7 @@ bool M17Demodulator::update()
{ {
syncDetected = true; syncDetected = true;
isLSF = syncword.lsf; isLSF = syncword.lsf;
offset = syncword.index + 4; offset = syncword.index + 1;
phase = 0; phase = 0;
frame_index = 0; frame_index = 0;
} }

View File

@ -99,7 +99,7 @@ void M17Modulator::generateBaseband()
for(size_t i = 0; i < M17_FRAME_SAMPLES_48K; i++) for(size_t i = 0; i < M17_FRAME_SAMPLES_48K; i++)
{ {
float elem = static_cast< float >(idleBuffer[i]); float elem = static_cast< float >(idleBuffer[i]);
idleBuffer[i] = static_cast< int16_t >((M17::rrc(elem) * M17_RRC_GAIN) idleBuffer[i] = static_cast< int16_t >((M17::rrc_48k(elem) * M17_RRC_GAIN)
- M17_RRC_OFFSET); - M17_RRC_OFFSET);
} }
} }

View File

@ -37,7 +37,7 @@ int main()
audio_enableMic(); audio_enableMic();
streamId id = inputStream_start(SOURCE_RTX, PRIO_TX, sampleBuf, numSamples, streamId id = inputStream_start(SOURCE_RTX, PRIO_TX, sampleBuf, numSamples,
BUF_LINEAR, 48000); BUF_LINEAR, 24000);
sleepFor(3u, 0u); sleepFor(3u, 0u);
platform_ledOn(GREEN); platform_ledOn(GREEN);