From dc816397130deb42c4b613fddccc4c56a285b986 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 28 Oct 2025 21:44:13 +0100 Subject: [PATCH] M17: Demodulator: improve symbol deviation estimation Using the DevEstimator class to obtain a better estimation of the outer symbol deviation: now values are estimated using a full frame instead of just the outer symbols of a syncword. Signed-off-by: Silvano Seva --- openrtx/include/protocols/M17/M17Demodulator.hpp | 3 ++- openrtx/src/protocols/M17/M17Demodulator.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/openrtx/include/protocols/M17/M17Demodulator.hpp b/openrtx/include/protocols/M17/M17Demodulator.hpp index e32eb8e7..914988e8 100644 --- a/openrtx/include/protocols/M17/M17Demodulator.hpp +++ b/openrtx/include/protocols/M17/M17Demodulator.hpp @@ -40,6 +40,7 @@ #include "protocols/M17/M17Constants.hpp" #include "protocols/M17/Correlator.hpp" #include "protocols/M17/Synchronizer.hpp" +#include "protocols/M17/DevEstimator.hpp" namespace M17 { @@ -183,13 +184,13 @@ private: uint8_t missedSyncs; ///< Counter of missed synchronizations uint32_t initCount; ///< Downcounter for initialization uint32_t syncCount; ///< Downcounter for resynchronization - std::pair < int32_t, int32_t > outerDeviation; ///< Deviation of outer symbols float corrThreshold; ///< Correlation threshold struct dcBlock dcBlock; ///< State of the DC removal filter Correlator < M17_SYNCWORD_SYMBOLS, SAMPLES_PER_SYMBOL > correlator; Synchronizer < M17_SYNCWORD_SYMBOLS, SAMPLES_PER_SYMBOL > streamSync{{ -3, -3, -3, -3, +3, +3, -3, +3 }}; Iir < 3 > sampleFilter{sfNum, sfDen}; + DevEstimator devEstimator; }; } /* M17 */ diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index 5fa0d01f..3d97798f 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -290,6 +290,7 @@ bool M17Demodulator::update(const bool invertPhase) void M17Demodulator::quantize(stream_sample_t sample) { + auto outerDeviation = devEstimator.outerDeviation(); int8_t symbol; if(sample > (2 * outerDeviation.first)/3) @@ -314,6 +315,7 @@ void M17Demodulator::quantize(stream_sample_t sample) if(frameIndex >= M17_FRAME_SYMBOLS) { + devEstimator.update(); std::swap(readyFrame, demodFrame); frameIndex = 0; newFrame = true; @@ -345,8 +347,9 @@ void M17Demodulator::syncedState() { // Set sampling point and deviation, zero frame symbol count samplingPoint = streamSync.samplingIndex(); - outerDeviation = correlator.maxDeviation(samplingPoint); + auto deviation = correlator.maxDeviation(samplingPoint); frameIndex = 0; + devEstimator.init(deviation); // Quantize the syncword taking data from the correlator // memory. @@ -375,6 +378,7 @@ void M17Demodulator::lockedState(int16_t sample) // Quantize and update frame at each sampling point quantize(sample); + devEstimator.sample(sample); // When we have reached almost the end of a frame, switch // to syncpoint update. @@ -387,8 +391,10 @@ void M17Demodulator::lockedState(int16_t sample) void M17Demodulator::syncUpdateState(int16_t sample) { // Keep filling the ongoing frame! - if(sampleIndex == samplingPoint) + if(sampleIndex == samplingPoint) { quantize(sample); + devEstimator.sample(sample); + } // Find the new correlation peak int32_t syncThresh = static_cast< int32_t >(corrThreshold * 33.0f); @@ -402,7 +408,6 @@ void M17Demodulator::syncUpdateState(int16_t sample) // Valid sync found: update deviation and sample // point, then go back to locked state if(hd <= 1) { - outerDeviation = correlator.maxDeviation(samplingPoint); samplingPoint = streamSync.samplingIndex(); missedSyncs = 0; demodState = DemodState::LOCKED;