1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-27 10:19:15 -05:00
sdrangel/sdrbase/dsp/agc.cpp

140 lines
2.1 KiB
C++
Raw Normal View History

2015-09-07 17:31:34 -04:00
/*
* agc.cpp
*
* Created on: Sep 7, 2015
* Author: f4exb
*/
#include "dsp/agc.h"
AGC::AGC() :
m_u0(1.0),
m_R(1.0),
m_moving_average(),
m_historySize(0),
m_count(0)
{}
AGC::AGC(int historySize, Real R) :
m_u0(1.0),
m_R(R),
m_moving_average(historySize, m_R),
m_historySize(historySize),
m_count(0)
{}
AGC::~AGC()
{}
void AGC::resize(int historySize, Real R)
{
m_R = R;
m_moving_average.resize(historySize, R);
m_historySize = historySize;
m_count = 0;
}
Real AGC::getValue()
{
return m_u0;
}
2015-09-12 10:34:57 -04:00
Real AGC::getAverage()
2015-09-07 17:31:34 -04:00
{
2015-09-12 10:34:57 -04:00
return m_moving_average.average();
2015-09-07 17:31:34 -04:00
}
MagSquaredAGC::MagSquaredAGC() :
AGC(),
m_magsq(0.0)
2015-09-07 17:31:34 -04:00
{}
MagSquaredAGC::MagSquaredAGC(int historySize, Real R) :
AGC(historySize, R),
m_magsq(0.0)
2015-09-07 17:31:34 -04:00
{}
MagSquaredAGC::~MagSquaredAGC()
{}
void MagSquaredAGC::feed(Complex& ci)
{
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
m_moving_average.feed(m_magsq);
2015-09-12 10:34:57 -04:00
m_u0 = m_R / m_moving_average.average();
ci *= m_u0;
2015-09-07 17:31:34 -04:00
}
MagAGC::MagAGC() :
AGC(),
m_magsq(0.0)
2015-09-07 17:31:34 -04:00
{}
MagAGC::MagAGC(int historySize, Real R) :
AGC(historySize, R),
m_magsq(0.0)
2015-09-07 17:31:34 -04:00
{}
MagAGC::~MagAGC()
{}
void MagAGC::feed(Complex& ci)
{
m_magsq = sqrt(ci.real()*ci.real() + ci.imag()*ci.imag());
m_moving_average.feed(m_magsq);
2015-09-12 10:34:57 -04:00
m_u0 = m_R / m_moving_average.average();
ci *= m_u0;
2015-09-07 17:31:34 -04:00
}
AlphaAGC::AlphaAGC() :
AGC(),
m_alpha(0.5),
m_magsq(0.0),
2015-09-07 17:31:34 -04:00
m_squelchOpen(true)
{}
AlphaAGC::AlphaAGC(int historySize, Real R) :
AGC(historySize, R),
m_alpha(0.5),
m_magsq(0.0),
2015-09-07 17:31:34 -04:00
m_squelchOpen(true)
{}
AlphaAGC::AlphaAGC(int historySize, Real R, Real alpha) :
AGC(historySize, R),
m_alpha(alpha),
m_magsq(0.0),
2015-09-07 17:31:34 -04:00
m_squelchOpen(true)
{}
AlphaAGC::~AlphaAGC()
{}
void AlphaAGC::resize(int historySize, Real R, Real alpha)
{
m_R = R;
m_alpha = alpha;
m_squelchOpen = true;
m_moving_average.resize(historySize, R);
}
void AlphaAGC::feed(Complex& ci)
{
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
2015-09-07 17:31:34 -04:00
if (m_squelchOpen && (m_magsq))
2015-09-07 17:31:34 -04:00
{
m_moving_average.feed(m_moving_average.average() - m_alpha*(m_moving_average.average() - m_magsq));
2015-09-07 17:31:34 -04:00
}
else
{
//m_squelchOpen = true;
m_moving_average.feed(m_magsq);
2015-09-07 17:31:34 -04:00
}
2015-09-12 10:34:57 -04:00
ci *= m_u0;
2015-09-07 17:31:34 -04:00
}