1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-03 06:24:48 -04:00

SSB demod: reworked AGC to handle the threshold gate properly

This commit is contained in:
f4exb
2019-06-09 09:25:18 +02:00
parent 2cefa0ed69
commit fb0ec4a680
7 changed files with 60 additions and 57 deletions
+28 -35
View File
@@ -50,7 +50,7 @@ MagAGC::MagAGC(int historySize, double R, double threshold) :
m_stepLength(std::min(2400, historySize/2)), // max 50 ms (at 48 kHz)
m_stepDelta(1.0/m_stepLength),
m_stepUpCounter(0),
m_stepDownCounter(m_stepLength),
m_stepDownCounter(0),
m_gateCounter(0),
m_stepDownDelay(historySize),
m_clamping(false),
@@ -68,7 +68,7 @@ void MagAGC::resize(int historySize, int stepLength, Real R)
m_stepLength = stepLength;
m_stepDelta = 1.0 / m_stepLength;
m_stepUpCounter = 0;
m_stepDownCounter = m_stepLength;
m_stepDownCounter = 0;
AGC::resize(historySize, R);
m_moving_average.fill(0);
}
@@ -85,7 +85,7 @@ void MagAGC::setThresholdEnable(bool enable)
if (m_thresholdEnable != enable)
{
m_stepUpCounter = 0;
m_stepDownCounter = m_stepLength;
m_stepDownCounter = 0;
}
m_thresholdEnable = enable;
@@ -136,50 +136,55 @@ double MagAGC::feedAndGetValue(const Complex& ci)
if (m_thresholdEnable)
{
bool open = false;
if (m_magsq > m_threshold)
{
if (m_gateCounter < m_gate)
{
if (m_gateCounter < m_gate) {
m_gateCounter++;
}
else
{
m_count = 0;
} else {
open = true;
}
}
else
{
if (m_count < m_stepDownDelay) {
m_count++;
}
m_gateCounter = 0;
}
if (m_count < m_stepDownDelay)
if (open)
{
m_stepDownCounter = m_stepUpCounter;
m_count = m_stepDownDelay; // delay before step down (grace delay)
}
else
{
m_count--;
m_gateCounter = m_gate; // keep gate open during grace
}
if (m_stepUpCounter < m_stepLength)
if (m_count > 0) // up phase
{
m_stepDownCounter = m_stepUpCounter; // prepare for step down
if (m_stepUpCounter < m_stepLength) // step up
{
m_stepUpCounter++;
return hardLimiter(m_u0 * StepFunctions::smootherstep(m_stepUpCounter * m_stepDelta), m_magsq);
}
else
else // steady open
{
return hardLimiter(m_u0, m_magsq);
}
}
else
else // down phase
{
m_stepUpCounter = m_stepDownCounter;
m_stepUpCounter = m_stepDownCounter; // prepare for step up
if (m_stepDownCounter > 0)
if (m_stepDownCounter > 0) // step down
{
m_stepDownCounter--;
return hardLimiter(m_u0 * StepFunctions::smootherstep(m_stepDownCounter * m_stepDelta), m_magsq);
}
else
else // steady closed
{
return 0.0;
}
@@ -191,25 +196,13 @@ double MagAGC::feedAndGetValue(const Complex& ci)
}
}
float MagAGC::getStepDownValue() const
{
if (m_count < m_stepDownDelay)
{
return 1.0f;
}
else
{
return StepFunctions::smootherstep(m_stepDownCounter * m_stepDelta);
}
}
float MagAGC::getStepValue() const
{
if (m_count < m_stepDownDelay)
if (m_count > 0) // up phase
{
return StepFunctions::smootherstep(m_stepUpCounter * m_stepDelta); // step up
}
else
else // down phase
{
return StepFunctions::smootherstep(m_stepDownCounter * m_stepDelta); // step down
}