diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index baf3960ac..56bb0e861 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -68,6 +68,9 @@ SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) : m_magsqPeak = 0.0f; m_magsqCount = 0; + m_agc.setClampMax(32768.0*32768.0); + m_agc.setClamping(true); + SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen); DSBFilter = new fftfilt((2.0f * m_Bandwidth) / m_audioSampleRate, 2 * ssbFftLen); diff --git a/sdrbase/dsp/agc.cpp b/sdrbase/dsp/agc.cpp index e9c37027a..41799bb34 100644 --- a/sdrbase/dsp/agc.cpp +++ b/sdrbase/dsp/agc.cpp @@ -71,12 +71,14 @@ void MagAGC::resize(int historySize, Real R) m_stepUpCounter = 0; m_stepDownCounter = m_stepLength; AGC::resize(historySize, R); + m_moving_average.fill(0); } void MagAGC::setOrder(double R) { m_R2 = R*R; AGC::setOrder(R); + m_moving_average.fill(0); } void MagAGC::setThresholdEnable(bool enable) @@ -110,7 +112,7 @@ double MagAGC::feedAndGetValue(const Complex& ci) else { double u02 = m_R2 / m_moving_average.average(); - m_u0 = (u02 * m_magsq > m_clampMax) ? m_clampMax / sqrt(m_magsq) : sqrt(u02); + m_u0 = (u02 * m_magsq > m_clampMax) ? sqrt(m_clampMax / m_magsq) : sqrt(u02); } } else diff --git a/sdrbase/dsp/agc.h b/sdrbase/dsp/agc.h index ef99c7aec..a724b6374 100644 --- a/sdrbase/dsp/agc.h +++ b/sdrbase/dsp/agc.h @@ -24,7 +24,7 @@ public: protected: double m_u0; //!< AGC factor - double m_R; //!< objective mag + double m_R; //!< ordered magnitude MovingAverage m_moving_average; //!< Averaging engine. The stack length conditions the smoothness of AGC. int m_historySize; //!< Averaging length (attack) int m_count; //!< Samples counter @@ -61,8 +61,8 @@ private: int m_gateCounter; //!< threshold gate samples counter int m_stepDownDelay; //!< delay in samples before cutoff (release) bool m_clamping; //!< clamping active - double m_R2; //!< square of objective magnitude - double m_clampMax; //!< maximum to clamp to + double m_R2; //!< square of ordered magnitude + double m_clampMax; //!< maximum to clamp to as power value };