mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 09:18:54 -05:00
Changed AGC to enhanced NFM squelch
This commit is contained in:
parent
e66d9a417f
commit
3cdccd2cd0
@ -71,7 +71,121 @@ private:
|
||||
Real m_fill; // refill average at this level
|
||||
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.
|
||||
MovingAverage<Real> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
|
||||
};
|
||||
|
||||
|
||||
class EvenSimplerAGC
|
||||
{
|
||||
public:
|
||||
|
||||
EvenSimplerAGC() :
|
||||
m_u0(1.0),
|
||||
m_R(1.0),
|
||||
m_moving_average()
|
||||
{}
|
||||
|
||||
EvenSimplerAGC(int historySize, Real R) :
|
||||
m_u0(1.0),
|
||||
m_R(R),
|
||||
m_moving_average(historySize, m_R)
|
||||
{}
|
||||
|
||||
void resize(int historySize, Real R)
|
||||
{
|
||||
m_R = R;
|
||||
m_moving_average.resize(historySize, R);
|
||||
}
|
||||
|
||||
Real getValue()
|
||||
{
|
||||
return m_u0;
|
||||
}
|
||||
|
||||
void feed(Complex& ci)
|
||||
{
|
||||
ci *= m_u0;
|
||||
Real magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||
m_moving_average.feed(magsq);
|
||||
m_u0 = m_R / m_moving_average.average();
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
m_moving_average.fill(m_R);
|
||||
m_u0 = 1.0;
|
||||
}
|
||||
|
||||
private:
|
||||
Real m_u0;
|
||||
Real m_R; // objective magsq
|
||||
MovingAverage<Real> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
|
||||
};
|
||||
|
||||
class AlphaAGC
|
||||
{
|
||||
public:
|
||||
|
||||
AlphaAGC() :
|
||||
m_u0(1.0),
|
||||
m_R(1.0),
|
||||
m_alpha(0.1),
|
||||
m_squelch(false),
|
||||
m_moving_average()
|
||||
{}
|
||||
|
||||
AlphaAGC(int historySize, Real R, Real alpha) :
|
||||
m_u0(1.0),
|
||||
m_R(R),
|
||||
m_alpha(alpha),
|
||||
m_squelch(false),
|
||||
m_moving_average(historySize, m_R)
|
||||
{}
|
||||
|
||||
void resize(int historySize, Real R, Real alpha)
|
||||
{
|
||||
m_R = R;
|
||||
m_alpha = alpha;
|
||||
m_squelch = false;
|
||||
m_moving_average.resize(historySize, R);
|
||||
}
|
||||
|
||||
Real getValue()
|
||||
{
|
||||
return m_u0;
|
||||
}
|
||||
|
||||
void feed(Complex& ci)
|
||||
{
|
||||
ci *= m_u0;
|
||||
Real magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||
|
||||
if (m_squelch && (magsq < m_moving_average.average()))
|
||||
{
|
||||
m_moving_average.feed(m_moving_average.average() - m_alpha*(m_moving_average.average() - magsq));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_squelch = true;
|
||||
m_moving_average.feed(magsq);
|
||||
}
|
||||
|
||||
m_u0 = m_R / m_moving_average.average();
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
m_moving_average.fill(m_R);
|
||||
m_u0 = 1.0;
|
||||
m_squelch = false;
|
||||
}
|
||||
|
||||
private:
|
||||
Real m_u0;
|
||||
Real m_R; // objective magsq
|
||||
Real m_alpha;
|
||||
bool m_squelch;
|
||||
MovingAverage<Real> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
|
||||
};
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include "dsp/dsptypes.h"
|
||||
|
||||
class MovingAverage {
|
||||
template<class Type> class MovingAverage {
|
||||
public:
|
||||
MovingAverage() :
|
||||
m_history(),
|
||||
@ -13,23 +13,23 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
MovingAverage(int historySize, Real initial) :
|
||||
MovingAverage(int historySize, Type initial) :
|
||||
m_history(historySize, initial),
|
||||
m_sum(historySize * initial),
|
||||
m_sum((float) historySize * initial),
|
||||
m_ptr(0)
|
||||
{
|
||||
}
|
||||
|
||||
void resize(int historySize, Real initial)
|
||||
void resize(int historySize, Type initial)
|
||||
{
|
||||
m_history.resize(historySize);
|
||||
for(size_t i = 0; i < m_history.size(); i++)
|
||||
m_history[i] = initial;
|
||||
m_sum = m_history.size() * initial;
|
||||
m_sum = (float) m_history.size() * initial;
|
||||
m_ptr = 0;
|
||||
}
|
||||
|
||||
void feed(Real value)
|
||||
void feed(Type value)
|
||||
{
|
||||
m_sum -= m_history[m_ptr];
|
||||
m_history[m_ptr] = value;
|
||||
@ -39,21 +39,21 @@ public:
|
||||
m_ptr = 0;
|
||||
}
|
||||
|
||||
void fill(Real value)
|
||||
void fill(Type value)
|
||||
{
|
||||
for(size_t i = 0; i < m_history.size(); i++)
|
||||
m_history[i] = value;
|
||||
m_sum = m_history.size() * value;
|
||||
m_sum = (float) m_history.size() * value;
|
||||
}
|
||||
|
||||
Real average() const
|
||||
Type average() const
|
||||
{
|
||||
return m_sum / (Real)m_history.size();
|
||||
return m_sum / (float) m_history.size();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<Real> m_history;
|
||||
Real m_sum;
|
||||
std::vector<Type> m_history;
|
||||
Type m_sum;
|
||||
uint m_ptr;
|
||||
};
|
||||
|
||||
|
@ -117,7 +117,7 @@ private:
|
||||
|
||||
Real m_lastArgument;
|
||||
Complex m_lastSample;
|
||||
MovingAverage m_movingAverage;
|
||||
MovingAverage<Real> m_movingAverage;
|
||||
SimpleAGC m_volumeAGC;
|
||||
|
||||
AudioVector m_audioBuffer;
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static const Real afSqTones[2] = {2000.0, 8000.0};
|
||||
static const Real afSqTones[2] = {1200.0, 8000.0};
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(NFMDemod::MsgConfigureNFMDemod, Message)
|
||||
|
||||
@ -53,10 +53,11 @@ NFMDemod::NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
|
||||
|
||||
m_movingAverage.resize(16, 0);
|
||||
m_agcLevel = 0.003;
|
||||
m_AGC.resize(4096, m_agcLevel, 0, 0.1*m_agcLevel);
|
||||
//m_AGC.resize(480, m_agcLevel, 0, 0.1*m_agcLevel);
|
||||
m_AGC.resize(240, m_agcLevel*m_agcLevel, 0.1);
|
||||
|
||||
m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution
|
||||
m_afSquelch.setCoefficients(24, 48000.0, 1, 1); // 4000 Hz span, 250us
|
||||
m_afSquelch.setCoefficients(24, 48000.0, 5, 1); // 4000 Hz span, 250us
|
||||
m_afSquelch.setThreshold(0.001);
|
||||
}
|
||||
|
||||
@ -117,8 +118,10 @@ void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
|
||||
|
||||
qint16 sample;
|
||||
|
||||
m_AGC.feed(abs(ci));
|
||||
ci *= (m_agcLevel / m_AGC.getValue());
|
||||
//m_AGC.feed(abs(ci));
|
||||
//ci *= (m_agcLevel / m_AGC.getValue());
|
||||
|
||||
m_AGC.feed(ci);
|
||||
|
||||
// demod
|
||||
/*
|
||||
|
@ -145,8 +145,8 @@ private:
|
||||
Real m_lastArgument;
|
||||
Complex m_m1Sample;
|
||||
Complex m_m2Sample;
|
||||
MovingAverage m_movingAverage;
|
||||
SimpleAGC m_AGC;
|
||||
MovingAverage<Real> m_movingAverage;
|
||||
AlphaAGC m_AGC;
|
||||
Real m_agcLevel; // AGC will aim to this level
|
||||
Real m_agcFloor; // AGC will not go below this level
|
||||
|
||||
|
@ -122,7 +122,7 @@ private:
|
||||
Real m_lastArgument;
|
||||
Complex m_m1Sample; // x^-1 sample
|
||||
Complex m_m2Sample; // x^-1 sample
|
||||
MovingAverage m_movingAverage;
|
||||
MovingAverage<Real> m_movingAverage;
|
||||
|
||||
AudioVector m_audioBuffer;
|
||||
uint m_audioBufferFill;
|
||||
|
@ -189,7 +189,7 @@ void AFSquelch::evaluate()
|
||||
|
||||
if (open)
|
||||
{
|
||||
if (attackCount < samplesAttack)
|
||||
if (samplesAttack && (attackCount < samplesAttack))
|
||||
{
|
||||
attackCount++;
|
||||
}
|
||||
@ -201,7 +201,7 @@ void AFSquelch::evaluate()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (decayCount < samplesDecay)
|
||||
if (samplesDecay && (decayCount < samplesDecay))
|
||||
{
|
||||
decayCount++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user