Cleaned up quantization average
Now average is computed over all the syncword symbols, for each syncword as a simple average. TG-81
This commit is contained in:
parent
5fe5b0e578
commit
ef61c532a3
|
|
@ -220,7 +220,7 @@ private:
|
||||||
* @param offset: index value to be added to the exponential moving
|
* @param offset: index value to be added to the exponential moving
|
||||||
* average/variance computation
|
* average/variance computation
|
||||||
*/
|
*/
|
||||||
void updateQuantizationStats(int32_t offset);
|
void updateQuantizationStats(int32_t frame_index, int32_t symbol_index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the convolution between a stride of samples starting from
|
* Computes the convolution between a stride of samples starting from
|
||||||
|
|
|
||||||
|
|
@ -130,49 +130,27 @@ void M17Demodulator::resetQuantizationStats()
|
||||||
qnt_neg_avg = 0.0f;
|
qnt_neg_avg = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17Demodulator::updateQuantizationStats(int32_t offset)
|
void M17Demodulator::updateQuantizationStats(int32_t frame_index,
|
||||||
|
int32_t symbol_index)
|
||||||
{
|
{
|
||||||
// If offset is negative use bridge buffer
|
int16_t sample = baseband.data[symbol_index];
|
||||||
int16_t sample = 0;
|
|
||||||
if (offset < 0) // When we are at negative offsets use bridge buffer
|
|
||||||
sample = basebandBridge[M17_BRIDGE_SIZE + offset];
|
|
||||||
else // Otherwise use regular data buffer
|
|
||||||
sample = baseband.data[offset];
|
|
||||||
if (sample > 0)
|
if (sample > 0)
|
||||||
{
|
|
||||||
qnt_pos_fifo.push_front(sample);
|
qnt_pos_fifo.push_front(sample);
|
||||||
// FIFO not full, compute traditional average
|
else
|
||||||
if (qnt_pos_fifo.size() <= QNT_SMA_WINDOW)
|
qnt_neg_fifo.push_front(sample);
|
||||||
{
|
// If we reached end of the syncword, compute average and reset queue
|
||||||
|
if(frame_index == M17_SYNCWORD_SYMBOLS - 1)
|
||||||
|
{
|
||||||
int32_t acc = 0;
|
int32_t acc = 0;
|
||||||
for(auto e : qnt_pos_fifo)
|
for(auto e : qnt_pos_fifo)
|
||||||
acc += e;
|
acc += e;
|
||||||
qnt_pos_avg = acc / static_cast<float>(qnt_pos_fifo.size());
|
qnt_pos_avg = acc / static_cast<float>(qnt_pos_fifo.size());
|
||||||
}
|
acc = 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
qnt_pos_avg += 1 / static_cast<float>(QNT_SMA_WINDOW) *
|
|
||||||
(sample - qnt_pos_fifo.back());
|
|
||||||
qnt_pos_fifo.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qnt_neg_fifo.push_front(sample);
|
|
||||||
// FIFO not full, compute traditional average
|
|
||||||
if (qnt_neg_fifo.size() <= QNT_SMA_WINDOW)
|
|
||||||
{
|
|
||||||
int32_t acc = 0;
|
|
||||||
for(auto e : qnt_neg_fifo)
|
for(auto e : qnt_neg_fifo)
|
||||||
acc += e;
|
acc += e;
|
||||||
qnt_neg_avg = acc / static_cast<float>(qnt_neg_fifo.size());
|
qnt_neg_avg = acc / static_cast<float>(qnt_neg_fifo.size());
|
||||||
}
|
qnt_pos_fifo.clear();
|
||||||
else
|
qnt_neg_fifo.clear();
|
||||||
{
|
|
||||||
qnt_neg_avg += 1 / static_cast<float>(QNT_SMA_WINDOW) *
|
|
||||||
(sample - qnt_neg_fifo.back());
|
|
||||||
qnt_neg_fifo.pop_back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,9 +221,9 @@ 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];
|
||||||
if (sample > static_cast< int16_t >(qnt_pos_avg / 2.1))
|
if (sample > static_cast< int16_t >(qnt_pos_avg / 2.0))
|
||||||
return +3;
|
return +3;
|
||||||
else if (sample < static_cast< int16_t >(qnt_neg_avg / 2.1))
|
else if (sample < static_cast< int16_t >(qnt_neg_avg / 2.0))
|
||||||
return -3;
|
return -3;
|
||||||
else if (sample > 0)
|
else if (sample > 0)
|
||||||
return +1;
|
return +1;
|
||||||
|
|
@ -337,7 +315,7 @@ bool M17Demodulator::update()
|
||||||
+ (M17_SAMPLES_PER_SYMBOL * decoded_syms);
|
+ (M17_SAMPLES_PER_SYMBOL * decoded_syms);
|
||||||
// Update quantization stats only on syncwords
|
// Update quantization stats only on syncwords
|
||||||
if (frame_index < M17_SYNCWORD_SYMBOLS)
|
if (frame_index < M17_SYNCWORD_SYMBOLS)
|
||||||
updateQuantizationStats(symbol_index);
|
updateQuantizationStats(frame_index, symbol_index);
|
||||||
int8_t symbol = quantize(symbol_index);
|
int8_t symbol = quantize(symbol_index);
|
||||||
|
|
||||||
// Log quantization
|
// Log quantization
|
||||||
|
|
@ -349,8 +327,8 @@ bool M17Demodulator::update()
|
||||||
demod_log log = {
|
demod_log log = {
|
||||||
baseband.data[symbol_index + i],
|
baseband.data[symbol_index + i],
|
||||||
0,0.0,symbol_index + i,
|
0,0.0,symbol_index + i,
|
||||||
qnt_pos_avg / 2.1f,
|
qnt_pos_avg / 2.0f,
|
||||||
qnt_neg_avg / 2.1f,
|
qnt_neg_avg / 2.0f,
|
||||||
symbol,
|
symbol,
|
||||||
frame_index};
|
frame_index};
|
||||||
appendLog(&log);
|
appendLog(&log);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue