From 2f5cbd10928ca3a0cc94f3d26808df41f7206093 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 1 Dec 2023 17:24:28 +0100 Subject: [PATCH] SSB demod: further optimize AGC steep transitions mitigation --- plugins/channelrx/demodssb/ssbdemodsink.cpp | 9 +++++---- sdrbase/dsp/agc.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/demodssb/ssbdemodsink.cpp b/plugins/channelrx/demodssb/ssbdemodsink.cpp index ffb462960..56d04cbd1 100644 --- a/plugins/channelrx/demodssb/ssbdemodsink.cpp +++ b/plugins/channelrx/demodssb/ssbdemodsink.cpp @@ -177,11 +177,12 @@ void SSBDemodSink::processOneSample(Complex &ci) m_audioActive = delayedSample.real() != 0.0; m_magsqCur = std::norm(sideband[i]*agcVal); - // Prevent overload if squared magnitude variation is 90% full scale (0.9*.0.9 = 0.81) + // Prevent overload based on squared magnitude variation // Only if AGC is active - if (m_agcActive && (m_magsqCur - m_magsqPrev > m_agcTarget*m_agcTarget*8.1)) + if (m_agcActive && (std::abs(m_magsqCur - m_magsqPrev) > m_agcTarget*m_agcTarget*5.0)) { m_agc.reset(m_agcTarget*100.0); // Quench AGC at -20dB the target + m_agc.resetStepCounters(); m_squelchDelayLine.write(sideband[i]); } else @@ -198,7 +199,8 @@ void SSBDemodSink::processOneSample(Complex &ci) } else { - fftfilt::cmplx z = m_agcActive ? delayedSample * m_agc.getStepValue() : delayedSample; + // fftfilt::cmplx z = m_agcActive ? delayedSample * m_agc.getStepValue() : delayedSample; + fftfilt::cmplx& z = delayedSample; if (m_audioBinaual) { @@ -503,4 +505,3 @@ void SSBDemodSink::applySettings(const SSBDemodSettings& settings, bool force) m_agcActive = settings.m_agc; m_settings = settings; } - diff --git a/sdrbase/dsp/agc.h b/sdrbase/dsp/agc.h index 38b544a3e..ff721a6a6 100644 --- a/sdrbase/dsp/agc.h +++ b/sdrbase/dsp/agc.h @@ -64,6 +64,7 @@ public: int getStepDownDelay() const { return m_stepDownDelay; } float getStepValue() const; void setHardLimiting(bool hardLimiting) { m_hardLimiting = hardLimiting; } + void resetStepCounters() { m_stepUpCounter = 0; m_stepDownCounter = 0; } private: bool m_squared; //!< use squared magnitude (power) to compute AGC value