From b680b1120676663e007f774f5a3e3b2e19743bfb Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 16 Feb 2018 00:43:21 +0100 Subject: [PATCH] AM demod: fixed volume AGC --- sdrbase/dsp/agc.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/sdrbase/dsp/agc.h b/sdrbase/dsp/agc.h index 101df8eab..1c107bd88 100644 --- a/sdrbase/dsp/agc.h +++ b/sdrbase/dsp/agc.h @@ -70,43 +70,46 @@ template class SimpleAGC { public: - SimpleAGC(Real cutoff=0, Real clip=0) : - m_squelchOpen(false), + SimpleAGC(Real initial, Real cutoff=0, Real clip=0) : m_cutoff(cutoff), - m_clip(clip) - {} + m_clip(clip), + m_moving_average(AvgSize, initial) + { + } - void resize(Real cutoff=0, Real clip=0) + void resize(Real initial, Real cutoff=0, Real clip=0) { m_cutoff = cutoff; m_clip = clip; + m_moving_average.resize(AvgSize, initial); } + void fill(double value) + { + m_moving_average.fill(value); + } + Real getValue() { - if ((Real) m_moving_average > m_clip) - { - return (Real) m_moving_average; - } else - { + if ((Real) m_moving_average.average() > m_clip) { + return (Real) m_moving_average.average(); + } else { return m_clip; } } void feed(Real value) { - if (value > m_cutoff) - { - m_moving_average(value); + if (value > m_cutoff) { + m_moving_average.feed(value); } } private: - bool m_squelchOpen; // open for processing Real m_cutoff; // consider samples only above this level Real m_clip; // never go below this level - //MovingAverage m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC. - MovingAverageUtil m_moving_average; + MovingAverage m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC. + //MovingAverageUtil m_moving_average; }; #endif /* INCLUDE_GPL_DSP_AGC_H_ */