From aa9fcc26b70d505ccff71eca9154f7de4cbef737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Wed, 13 Apr 2022 22:05:04 +0200 Subject: [PATCH] Remove useless DC bias in quantization TG-81 --- .../include/protocols/M17/M17Demodulator.h | 5 ++-- openrtx/src/protocols/M17/M17Demodulator.cpp | 25 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/openrtx/include/protocols/M17/M17Demodulator.h b/openrtx/include/protocols/M17/M17Demodulator.h index 19d86078..072ca2da 100644 --- a/openrtx/include/protocols/M17/M17Demodulator.h +++ b/openrtx/include/protocols/M17/M17Demodulator.h @@ -123,8 +123,8 @@ private: 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 float CONV_STATS_ALPHA = 0.01f; - static constexpr float QNT_STATS_ALPHA = 0.995f; + static constexpr float CONV_STATS_ALPHA = 0.001f; + static constexpr float QNT_STATS_ALPHA = 0.999f; static constexpr float CONV_THRESHOLD_FACTOR = 3.40; /** @@ -164,7 +164,6 @@ private: /* * Quantization statistics computation */ - float qnt_ema = 0.0f; ///< Exponential moving average from of the sliced samples. float qnt_max = 0.0f; ///< Max hold of the sliced samples float qnt_min = 0.0f; ///< Min hold of the sliced samples. diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index 95eb48c0..d36dea86 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -124,7 +124,6 @@ float M17Demodulator::getCorrelationStddev() void M17Demodulator::resetQuantizationStats() { - qnt_ema = 0.0f; qnt_max = 0.0f; qnt_min = 0.0f; } @@ -137,17 +136,12 @@ void M17Demodulator::updateQuantizationStats(int32_t offset) sample = basebandBridge[M17_BRIDGE_SIZE + offset]; else // Otherwise use regular data buffer sample = baseband.data[offset]; - // Compute symbols exponential moving average - float delta = (float) sample - qnt_ema; - qnt_ema += CONV_STATS_ALPHA * delta; - // Remove DC offset - int16_t s = sample - (int16_t) qnt_ema; - if (s > qnt_max) - qnt_max = s; + if (sample > qnt_max) + qnt_max = sample; else qnt_max *= QNT_STATS_ALPHA; - if (s < qnt_min) - qnt_min = s; + if (sample < qnt_min) + qnt_min = sample; else qnt_min *= QNT_STATS_ALPHA; } @@ -232,13 +226,11 @@ int8_t M17Demodulator::quantize(int32_t offset) sample = basebandBridge[M17_BRIDGE_SIZE + offset]; else // Otherwise use regular data buffer sample = baseband.data[offset]; - // DC offset removal - int16_t s = sample - static_cast< int16_t >(qnt_ema); - if (s > static_cast< int16_t >(qnt_max) / 2) + if (sample > static_cast< int16_t >(qnt_max) / 2) return +3; - else if (s < static_cast< int16_t >(qnt_min) / 2) + else if (sample < static_cast< int16_t >(qnt_min) / 2) return -3; - else if (s > 0) + else if (sample > 0) return +1; else return -1; @@ -301,11 +293,12 @@ bool M17Demodulator::update() if (!locked) { syncword = nextFrameSync(offset); - if (syncword.index != -1) // Lock was just acquired + if (syncword.index != -1) // Valid syncword found { locked = true; isLSF = syncword.lsf; offset = syncword.index + 1; + phase = 0; frameIndex = 0; } }