- improved signal detection and thresholding
- no lag accu update if no signal - don't print packets git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@389 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+53
-14
@@ -25,6 +25,7 @@
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include "garage_impl.h"
|
||||
|
||||
#define WITH_PRINT_PACKETS 0
|
||||
#define WITH_DEBUG_MESSAGES 0
|
||||
#define WITH_DEBUG_FILE 0
|
||||
|
||||
@@ -47,6 +48,7 @@ garage_impl::garage_impl(int sampleRate, int samplesPerSym, float kLoopFilter, f
|
||||
, m_sampleRate(sampleRate)
|
||||
, m_samplesPerSym(samplesPerSym)
|
||||
, m_count(samplesPerSym)
|
||||
, m_isSignal(false)
|
||||
, m_baudRate((float)m_sampleRate/m_samplesPerSym)
|
||||
, m_kLoopFilter(kLoopFilter)
|
||||
, m_kThreshold(kThreshold)
|
||||
@@ -122,7 +124,7 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
float loopThreshold = m_kThreshold;
|
||||
float k_lead = 1.0e-1f;
|
||||
float k_lag = 1.0e-4f;
|
||||
float k_leak = 0;
|
||||
float rho_leak = 0.9999;
|
||||
float err = 0;
|
||||
|
||||
float alpha_sig = 0.5f/m_samplesPerSym;
|
||||
@@ -150,8 +152,23 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
m_dc_corr += alpha_thr*(m_vmax + m_vmin);
|
||||
|
||||
// Signal detection
|
||||
m_v_sig = (1.f-alpha_sig)*m_v_sig + alpha_sig*y*y;
|
||||
bool isSignal = m_v_sig >= loopThreshold;
|
||||
float yd = std::abs(y)-m_vmax;
|
||||
m_v_sig = (1.f-alpha_sig)*m_v_sig + alpha_sig*yd*yd;
|
||||
|
||||
if (!m_isSignal)
|
||||
{
|
||||
if (m_v_sig <= loopThreshold)
|
||||
{
|
||||
m_isSignal = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_v_sig > 1.2*loopThreshold)
|
||||
{
|
||||
m_isSignal = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Integrate and dump
|
||||
float k_id = 1.f/((1+m_lag_accu)*m_samplesPerSym);
|
||||
@@ -161,20 +178,26 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
float accu = m_id_accu;
|
||||
m_id_accu = 0;
|
||||
int bit_id = (int)(accu >= 0.0);
|
||||
out[outCount++] = (float)bit_id;
|
||||
if (isSignal)
|
||||
if (m_isSignal)
|
||||
{
|
||||
#if WITH_PRINT_PACKETS
|
||||
bitRecord(bit_id);
|
||||
if (m_pFile_bits)
|
||||
{
|
||||
fprintf(m_pFile_bits, "%f %f\n", (float)m_sampleCounter/m_sampleRate, accu);
|
||||
}
|
||||
#endif
|
||||
out[outCount++] = (float)bit_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
out[outCount++] = (float)0xFFFFFFFF;
|
||||
}
|
||||
if (m_pFile_bits)
|
||||
{
|
||||
fprintf(m_pFile_bits, "%f %f\n", (float)m_sampleCounter/m_sampleRate, accu);
|
||||
}
|
||||
}
|
||||
|
||||
// Zero crossing detector
|
||||
int bitChg = 0;
|
||||
if (isSignal)
|
||||
if (m_isSignal)
|
||||
{
|
||||
if (m_bitZeroCross == 1)
|
||||
{
|
||||
@@ -194,8 +217,9 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
}
|
||||
}
|
||||
|
||||
#if WITH_PRINT_PACKETS
|
||||
bitProcessGap(bitChg);
|
||||
|
||||
#endif
|
||||
// Calc error
|
||||
err = 0;
|
||||
if (bitChg)
|
||||
@@ -205,9 +229,19 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
|
||||
float vcorr = k_leadLag*k_lead*err + m_lag_accu;
|
||||
|
||||
// Lag part of loop filter
|
||||
m_lag_accu += k_leadLag*k_lag*err;
|
||||
m_lag_accu *= (1.f - k_leak);
|
||||
m_lag_accu *= rho_leak;
|
||||
if (m_isSignal)
|
||||
{
|
||||
if (m_lag_accu > -0.5f and m_lag_accu < 0.5f)
|
||||
{
|
||||
// Lag part of loop filter
|
||||
m_lag_accu += k_leadLag*k_lag*err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lag_accu = 0;
|
||||
}
|
||||
|
||||
m_baudRate = (float)m_sampleRate/((1+m_lag_accu)*m_samplesPerSym);
|
||||
|
||||
@@ -230,6 +264,11 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
|
||||
m_i += (1+vcorr);
|
||||
i_i = (int)m_i;
|
||||
|
||||
if (outCount >= noutput_items)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
inCount++;
|
||||
if (inCount >= ninput_items[0])
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@ class garage_impl : public garage
|
||||
int m_sampleRate;
|
||||
int m_samplesPerSym;
|
||||
int m_count;
|
||||
bool m_isSignal;
|
||||
float m_baudRate;
|
||||
float m_kLoopFilter;
|
||||
float m_kThreshold;
|
||||
|
||||
Reference in New Issue
Block a user