mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-09-26 14:56:33 -04:00
SSB demod: AGC step down
This commit is contained in:
parent
8452985061
commit
da6b60d48c
@ -5,6 +5,7 @@
|
|||||||
* Author: f4exb
|
* Author: f4exb
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include "dsp/agc.h"
|
#include "dsp/agc.h"
|
||||||
#include "util/smootherstep.h"
|
#include "util/smootherstep.h"
|
||||||
|
|
||||||
@ -48,13 +49,21 @@ MagSquaredAGC::MagSquaredAGC(int historySize, double R, double threshold) :
|
|||||||
m_magsq(0.0),
|
m_magsq(0.0),
|
||||||
m_threshold(threshold),
|
m_threshold(threshold),
|
||||||
m_gate(0),
|
m_gate(0),
|
||||||
m_stepCounter(0),
|
m_stepLength(std::min(2400, historySize/2)),
|
||||||
|
m_stepUpCounter(0),
|
||||||
|
m_stepDownCounter(0),
|
||||||
m_gateCounter(0)
|
m_gateCounter(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
MagSquaredAGC::~MagSquaredAGC()
|
MagSquaredAGC::~MagSquaredAGC()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void MagSquaredAGC::resize(int historySize, Real R)
|
||||||
|
{
|
||||||
|
m_stepLength = std::min(2400, historySize/2);
|
||||||
|
AGC::resize(historySize, R);
|
||||||
|
}
|
||||||
|
|
||||||
void MagSquaredAGC::feed(Complex& ci)
|
void MagSquaredAGC::feed(Complex& ci)
|
||||||
{
|
{
|
||||||
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||||
@ -91,16 +100,23 @@ double MagSquaredAGC::feedAndGetValue(const Complex& ci)
|
|||||||
|
|
||||||
if (m_count < m_moving_average.historySize())
|
if (m_count < m_moving_average.historySize())
|
||||||
{
|
{
|
||||||
if (m_stepCounter < 2400) {
|
m_stepDownCounter = m_stepLength;
|
||||||
m_stepCounter++;
|
|
||||||
|
if (m_stepUpCounter < m_stepLength) {
|
||||||
|
m_stepUpCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_u0 * StepFunctions::smootherstep(m_stepCounter/2400.0);
|
return m_u0 * StepFunctions::smootherstep(m_stepUpCounter/m_stepLength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_stepCounter = 0;
|
m_stepUpCounter = 0;
|
||||||
return 0.0;
|
|
||||||
|
if (m_stepDownCounter > 0) {
|
||||||
|
m_stepDownCounter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_u0 * StepFunctions::smootherstep(m_stepDownCounter/m_stepLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
//return (m_count < m_moving_average.historySize()) ? m_u0 : 0.0;
|
//return (m_count < m_moving_average.historySize()) ? m_u0 : 0.0;
|
||||||
@ -116,13 +132,21 @@ MagAGC::MagAGC(int historySize, double R, double threshold) :
|
|||||||
m_magsq(0.0),
|
m_magsq(0.0),
|
||||||
m_threshold(threshold),
|
m_threshold(threshold),
|
||||||
m_gate(0),
|
m_gate(0),
|
||||||
m_stepCounter(0),
|
m_stepLength(std::min(2400, historySize/2)),
|
||||||
|
m_stepUpCounter(0),
|
||||||
|
m_stepDownCounter(0),
|
||||||
m_gateCounter(0)
|
m_gateCounter(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
MagAGC::~MagAGC()
|
MagAGC::~MagAGC()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void MagAGC::resize(int historySize, Real R)
|
||||||
|
{
|
||||||
|
m_stepLength = std::min(2400, historySize/2);
|
||||||
|
AGC::resize(historySize, R);
|
||||||
|
}
|
||||||
|
|
||||||
void MagAGC::feed(Complex& ci)
|
void MagAGC::feed(Complex& ci)
|
||||||
{
|
{
|
||||||
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
m_magsq = ci.real()*ci.real() + ci.imag()*ci.imag();
|
||||||
@ -159,16 +183,23 @@ double MagAGC::feedAndGetValue(const Complex& ci)
|
|||||||
|
|
||||||
if (m_count < m_moving_average.historySize())
|
if (m_count < m_moving_average.historySize())
|
||||||
{
|
{
|
||||||
if (m_stepCounter < 480) {
|
m_stepDownCounter = m_stepLength;
|
||||||
m_stepCounter++;
|
|
||||||
|
if (m_stepUpCounter < m_stepLength) {
|
||||||
|
m_stepUpCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_u0 * StepFunctions::smootherstep(m_stepCounter/480.0);
|
return m_u0 * StepFunctions::smootherstep(m_stepUpCounter/m_stepLength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_stepCounter = 0;
|
m_stepUpCounter = 0;
|
||||||
return 0.0;
|
|
||||||
|
if (m_stepDownCounter > 0) {
|
||||||
|
m_stepDownCounter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_u0 * StepFunctions::smootherstep(m_stepDownCounter/m_stepLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
//return (m_count < m_moving_average.historySize()) ? m_u0 : 0.0;
|
//return (m_count < m_moving_average.historySize()) ? m_u0 : 0.0;
|
||||||
|
@ -34,6 +34,7 @@ class MagSquaredAGC : public AGC
|
|||||||
public:
|
public:
|
||||||
MagSquaredAGC(int historySize, double R, double threshold);
|
MagSquaredAGC(int historySize, double R, double threshold);
|
||||||
virtual ~MagSquaredAGC();
|
virtual ~MagSquaredAGC();
|
||||||
|
void resize(int historySize, Real R);
|
||||||
virtual void feed(Complex& ci);
|
virtual void feed(Complex& ci);
|
||||||
double feedAndGetValue(const Complex& ci);
|
double feedAndGetValue(const Complex& ci);
|
||||||
double getMagSq() const { return m_magsq; }
|
double getMagSq() const { return m_magsq; }
|
||||||
@ -41,10 +42,12 @@ public:
|
|||||||
void setGate(int gate) { m_gate = gate; }
|
void setGate(int gate) { m_gate = gate; }
|
||||||
private:
|
private:
|
||||||
double m_magsq;
|
double m_magsq;
|
||||||
double m_threshold; //!< squelch on magsq average with transition from +3dB
|
double m_threshold; //!< squelch on magsq average
|
||||||
int m_gate;
|
int m_gate; //!< power threshold gate in number of samples
|
||||||
int m_stepCounter;
|
int m_stepLength; //!< transition step length in number of samples
|
||||||
int m_gateCounter;
|
int m_stepUpCounter; //!< step up transition samples counter
|
||||||
|
int m_stepDownCounter; //!< step down transition samples counter
|
||||||
|
int m_gateCounter; //!< threshold gate samples counter
|
||||||
};
|
};
|
||||||
|
|
||||||
class MagAGC : public AGC
|
class MagAGC : public AGC
|
||||||
@ -52,6 +55,7 @@ class MagAGC : public AGC
|
|||||||
public:
|
public:
|
||||||
MagAGC(int historySize, double R, double threshold);
|
MagAGC(int historySize, double R, double threshold);
|
||||||
virtual ~MagAGC();
|
virtual ~MagAGC();
|
||||||
|
void resize(int historySize, Real R);
|
||||||
virtual void feed(Complex& ci);
|
virtual void feed(Complex& ci);
|
||||||
double feedAndGetValue(const Complex& ci);
|
double feedAndGetValue(const Complex& ci);
|
||||||
Real getMagSq() const { return m_magsq; }
|
Real getMagSq() const { return m_magsq; }
|
||||||
@ -60,9 +64,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
double m_magsq;
|
double m_magsq;
|
||||||
double m_threshold; //!< squelch on magsq average
|
double m_threshold; //!< squelch on magsq average
|
||||||
int m_gate;
|
int m_gate; //!< power threshold gate in number of samples
|
||||||
int m_stepCounter;
|
int m_stepLength; //!< transition step length in number of samples
|
||||||
int m_gateCounter;
|
int m_stepUpCounter; //!< step up transition samples counter
|
||||||
|
int m_stepDownCounter; //!< step down transition samples counter
|
||||||
|
int m_gateCounter; //!< threshold gate samples counter
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlphaAGC : public AGC
|
class AlphaAGC : public AGC
|
||||||
|
Loading…
Reference in New Issue
Block a user