Remove useless DC bias in quantization

TG-81
pull/68/head
Niccolò Izzo 2022-04-13 22:05:04 +02:00 zatwierdzone przez Silvano Seva
rodzic d1651a702c
commit aa9fcc26b7
2 zmienionych plików z 11 dodań i 19 usunięć

Wyświetl plik

@ -123,8 +123,8 @@ private:
static constexpr size_t M17_SAMPLE_BUF_SIZE = M17_FRAME_SAMPLES / 2; static constexpr size_t M17_SAMPLE_BUF_SIZE = M17_FRAME_SAMPLES / 2;
static constexpr size_t M17_BRIDGE_SIZE = M17_SAMPLES_PER_SYMBOL * M17_SYNCWORD_SYMBOLS; static constexpr size_t M17_BRIDGE_SIZE = M17_SAMPLES_PER_SYMBOL * M17_SYNCWORD_SYMBOLS;
static constexpr float CONV_STATS_ALPHA = 0.01f; static constexpr float CONV_STATS_ALPHA = 0.001f;
static constexpr float QNT_STATS_ALPHA = 0.995f; static constexpr float QNT_STATS_ALPHA = 0.999f;
static constexpr float CONV_THRESHOLD_FACTOR = 3.40; static constexpr float CONV_THRESHOLD_FACTOR = 3.40;
/** /**
@ -164,7 +164,6 @@ private:
/* /*
* Quantization statistics computation * Quantization statistics computation
*/ */
float qnt_ema = 0.0f; ///< Exponential moving average from of the sliced samples.
float qnt_max = 0.0f; ///< Max hold of the sliced samples float qnt_max = 0.0f; ///< Max hold of the sliced samples
float qnt_min = 0.0f; ///< Min hold of the sliced samples. float qnt_min = 0.0f; ///< Min hold of the sliced samples.

Wyświetl plik

@ -124,7 +124,6 @@ float M17Demodulator::getCorrelationStddev()
void M17Demodulator::resetQuantizationStats() void M17Demodulator::resetQuantizationStats()
{ {
qnt_ema = 0.0f;
qnt_max = 0.0f; qnt_max = 0.0f;
qnt_min = 0.0f; qnt_min = 0.0f;
} }
@ -137,17 +136,12 @@ void M17Demodulator::updateQuantizationStats(int32_t offset)
sample = basebandBridge[M17_BRIDGE_SIZE + offset]; sample = basebandBridge[M17_BRIDGE_SIZE + offset];
else // Otherwise use regular data buffer else // Otherwise use regular data buffer
sample = baseband.data[offset]; sample = baseband.data[offset];
// Compute symbols exponential moving average if (sample > qnt_max)
float delta = (float) sample - qnt_ema; qnt_max = sample;
qnt_ema += CONV_STATS_ALPHA * delta;
// Remove DC offset
int16_t s = sample - (int16_t) qnt_ema;
if (s > qnt_max)
qnt_max = s;
else else
qnt_max *= QNT_STATS_ALPHA; qnt_max *= QNT_STATS_ALPHA;
if (s < qnt_min) if (sample < qnt_min)
qnt_min = s; qnt_min = sample;
else else
qnt_min *= QNT_STATS_ALPHA; qnt_min *= QNT_STATS_ALPHA;
} }
@ -232,13 +226,11 @@ int8_t M17Demodulator::quantize(int32_t offset)
sample = basebandBridge[M17_BRIDGE_SIZE + offset]; sample = basebandBridge[M17_BRIDGE_SIZE + offset];
else // Otherwise use regular data buffer else // Otherwise use regular data buffer
sample = baseband.data[offset]; sample = baseband.data[offset];
// DC offset removal if (sample > static_cast< int16_t >(qnt_max) / 2)
int16_t s = sample - static_cast< int16_t >(qnt_ema);
if (s > static_cast< int16_t >(qnt_max) / 2)
return +3; return +3;
else if (s < static_cast< int16_t >(qnt_min) / 2) else if (sample < static_cast< int16_t >(qnt_min) / 2)
return -3; return -3;
else if (s > 0) else if (sample > 0)
return +1; return +1;
else else
return -1; return -1;
@ -301,11 +293,12 @@ bool M17Demodulator::update()
if (!locked) if (!locked)
{ {
syncword = nextFrameSync(offset); syncword = nextFrameSync(offset);
if (syncword.index != -1) // Lock was just acquired if (syncword.index != -1) // Valid syncword found
{ {
locked = true; locked = true;
isLSF = syncword.lsf; isLSF = syncword.lsf;
offset = syncword.index + 1; offset = syncword.index + 1;
phase = 0;
frameIndex = 0; frameIndex = 0;
} }
} }