1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

Deep redesign: Valgrind optimization on NFM demod. Tuned NFM squelch.

This commit is contained in:
f4exb 2015-08-29 09:41:39 +02:00
parent cebedf1460
commit f121ba258b
3 changed files with 44 additions and 28 deletions

View File

@ -15,7 +15,7 @@ class SimpleAGC
public:
SimpleAGC() :
m_squelch(false),
m_squelchOpen(false),
m_fill(0),
m_cutoff(0),
m_clip(0),
@ -23,7 +23,7 @@ public:
{}
SimpleAGC(int historySize, Real initial, Real cutoff=0, Real clip=0) :
m_squelch(false),
m_squelchOpen(false),
m_fill(initial),
m_cutoff(cutoff),
m_clip(clip),
@ -40,9 +40,11 @@ public:
Real getValue()
{
if (m_moving_average.average() > m_clip) {
if (m_moving_average.average() > m_clip)
{
return m_moving_average.average();
} else {
} else
{
return m_clip;
}
}
@ -53,21 +55,24 @@ public:
{
m_moving_average.feed(value);
}
m_squelch = true;
}
void close()
void openedSquelch()
{
if (m_squelch)
m_squelchOpen = true;
}
void closedSquelch()
{
if (m_squelchOpen)
{
m_moving_average.fill(m_fill);
m_squelch = false;
//m_moving_average.fill(m_fill); // Valgrind optim
m_squelchOpen = false;
}
}
private:
bool m_squelch; // open for processing
bool m_squelchOpen; // open for processing
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
@ -107,12 +112,16 @@ public:
ci *= m_u0;
Real magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
m_moving_average.feed(magsq);
}
void openedSquelch()
{
m_u0 = m_R / m_moving_average.average();
}
void close()
void closedSquelch()
{
m_moving_average.fill(m_R);
//m_moving_average.fill(m_R); // Valgrind optim
m_u0 = 1.0;
}
@ -130,7 +139,7 @@ public:
m_u0(1.0),
m_R(1.0),
m_alpha(0.1),
m_squelch(false),
m_squelchOpen(true),
m_moving_average()
{}
@ -138,7 +147,7 @@ public:
m_u0(1.0),
m_R(R),
m_alpha(alpha),
m_squelch(false),
m_squelchOpen(true),
m_moving_average(historySize, m_R)
{}
@ -146,7 +155,7 @@ public:
{
m_R = R;
m_alpha = alpha;
m_squelch = false;
m_squelchOpen = true;
m_moving_average.resize(historySize, R);
}
@ -160,31 +169,36 @@ public:
ci *= m_u0;
Real magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
if (m_squelch && (magsq < m_moving_average.average()))
if (m_squelchOpen && (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_squelchOpen = true;
m_moving_average.feed(magsq);
}
m_u0 = m_R / m_moving_average.average();
}
void close()
void openedSquelch()
{
m_moving_average.fill(m_R);
m_u0 = m_R / m_moving_average.average();
m_squelchOpen = true;
}
void closedSquelch()
{
//m_moving_average.fill(m_R); // Valgrind optim
m_u0 = 1.0;
m_squelch = false;
m_squelchOpen = false;
}
private:
Real m_u0;
Real m_R; // objective magsq
Real m_alpha;
bool m_squelch;
bool m_squelchOpen;
MovingAverage<Real> m_moving_average; // Averaging engine. The stack length conditions the smoothness of AGC.
};

View File

@ -113,7 +113,7 @@ void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector
}
else
{
m_volumeAGC.close();
m_volumeAGC.closedSquelch();
sample = 0;
}

View File

@ -26,7 +26,7 @@
#include "dsp/pidcontroller.h"
#include "dsp/dspengine.h"
static const Real afSqTones[2] = {1200.0, 8000.0};
static const Real afSqTones[2] = {1200.0, 6000.0}; // {1200.0, 8000.0};
MESSAGE_CLASS_DEFINITION(NFMDemod::MsgConfigureNFMDemod, Message)
@ -54,9 +54,9 @@ NFMDemod::NFMDemod() :
m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
m_agcLevel = 0.003;
m_agcLevel = 0.003; // 0.003
//m_AGC.resize(480, m_agcLevel, 0, 0.1*m_agcLevel);
m_AGC.resize(240, m_agcLevel*m_agcLevel, 0.1);
m_AGC.resize(240, m_agcLevel*m_agcLevel, 0.3);
m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution
m_afSquelch.setCoefficients(24, 48000.0, 5, 1); // 4000 Hz span, 250us
@ -208,6 +208,8 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
demod *= m_running.m_volume;
sample = demod * ((1<<15)/301); // denominator = bandpass filter number of taps
}
m_AGC.openedSquelch();
}
else
{
@ -217,7 +219,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
m_ctcssIndex = 0;
}
m_AGC.close();
m_AGC.closedSquelch();
sample = 0;
}