From 417e081501e3ef25f89441d54871b42f0027d072 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 7 Jan 2019 14:54:49 +0000 Subject: [PATCH] - improvement: use Integrate and Dump filter git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@385 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- gr-jay/lib/garage_impl.cc | 76 +++++++++++++++++++++------------------ gr-jay/lib/garage_impl.h | 7 ++-- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/gr-jay/lib/garage_impl.cc b/gr-jay/lib/garage_impl.cc index 0dd1c87..da229a5 100644 --- a/gr-jay/lib/garage_impl.cc +++ b/gr-jay/lib/garage_impl.cc @@ -26,7 +26,7 @@ #include "garage_impl.h" #define WITH_DEBUG_MESSAGES 0 -#define WITH_DEBUG_FILE 0 +#define WITH_DEBUG_FILE 1 namespace gr { @@ -53,10 +53,11 @@ garage_impl::garage_impl(int sampleRate, int samplesPerSym, float kLoopFilter, f , m_vmin(0) , m_vmax(0) , m_v_sig(0) -, m_v_sig_m(0.5f) -, m_v_thr(0) +, m_dc_corr(0) , m_lag_accu(0) -, m_bit(0) +, m_id_accu(0) +, m_id_bit(0) +, m_bitZeroCross(0) , m_i(0) , m_gapDistance(8*m_samplesPerSym) , m_gapCounter(0) @@ -107,7 +108,7 @@ void garage_impl::forecast (int noutput_items, gr_vector_int &ninput_items_requi int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - float rho = 1e-4; + float rho = 0.999f; const float *in = (const float *) input_items[0]; float *out = (float *) output_items[0]; int outCount = 0; @@ -115,8 +116,8 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g // Do <+signal processing+> int countReload = m_samplesPerSym-1; - float alpha_thr = 0.5f; - float hyst_thr = 0.5f; + float alpha_thr = 0.002f; + float hyst_thr = 0.1f; float k_leadLag = m_kLoopFilter; float loopThreshold = m_kThreshold; float k_lead = 1.0e-1f; @@ -125,52 +126,68 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g float err = 0; float alpha_sig = 0.5f/m_samplesPerSym; - float alpha_sig_m = alpha_sig/5; int i_i = 0; while ((i_i+1) < ninput_items[0]) { // Get next interpolated sample float i_f = m_i - (float)i_i; - float y = (1.f-i_f)*in[i_i] + i_f*in[i_i+1]; + float y = (1.f-i_f)*in[i_i] + i_f*in[i_i+1] - m_dc_corr; // Calculate threshold - m_v_thr = (fabs(m_vmax) - fabs(m_vmin))/2; + m_vmin *= rho; + m_vmax *= rho; if (y < m_vmin) { - m_vmin = (1-alpha_thr)*m_vmin + alpha_thr*y; + m_vmin = y; } else if (y > m_vmax) { - m_vmax = (1-alpha_thr)*m_vmax + alpha_thr*y; + m_vmax = y; } - m_vmin = m_vmin + rho*(m_v_thr - m_vmin); - m_vmax = m_vmax + rho*(m_v_thr - m_vmax); + // Calculate DC offset correction + m_dc_corr += alpha_thr*(m_vmax + m_vmin); + // Signal detection - float y_nodc = (y-m_v_thr); - m_v_sig = (1.f-alpha_sig)*m_v_sig + alpha_sig*y_nodc*y_nodc; - m_v_sig_m = (1.f-alpha_sig_m)*m_v_sig_m + alpha_sig_m*y; + m_v_sig = (1.f-alpha_sig)*m_v_sig + alpha_sig*y*y; bool isSignal = m_v_sig >= loopThreshold; + // Integrate and dump + float k_id = 1.f/((1+m_lag_accu)*m_samplesPerSym); + m_id_accu += k_id*y; + if (m_count == m_samplesPerSym/2) + { + int bit_id = (int)(m_id_accu >= 0.0); + m_id_accu = 0; + out[outCount++] = (float)bit_id; + if (isSignal) + { + bitRecord(bit_id); + if (m_pFile_bits) + { + fprintf(m_pFile_bits, "%f %f\n", (float)m_sampleCounter/m_sampleRate, y); + } + } + } + + // Zero crossing detector int bitChg = 0; if (isSignal) { - - // Detect bit change - if (m_bit == 1) + if (m_bitZeroCross == 1) { - if (y < (hyst_thr*m_v_thr)) + if (y < -hyst_thr) { - m_bit = 0; + m_bitZeroCross = 0; bitChg = 1; } } else { - if (y > (hyst_thr*m_v_thr)) + if (y > +hyst_thr) { - m_bit = 1; + m_bitZeroCross = 1; bitChg = 1; } } @@ -196,16 +213,7 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g // Sample bit at baud rate = fs/numSamplesPerSym if (m_count == 0) { - out[outCount++] = (float)m_bit; m_count = countReload; - if (isSignal) - { - bitRecord(m_bit); - if (m_pFile_bits) - { - fprintf(m_pFile_bits, "%f %f\n", (float)m_sampleCounter/m_sampleRate, y); - } - } } else { @@ -214,7 +222,7 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g if (m_pFile_y) { - fprintf(m_pFile_y, "%f %f %f %f\n", (float)m_sampleCounter/m_sampleRate, y, m_v_thr, vcorr); + fprintf(m_pFile_y, "%f %f %f %f\n", (float)m_sampleCounter/m_sampleRate, y, m_v_sig, m_id_accu); } m_sampleCounter++; diff --git a/gr-jay/lib/garage_impl.h b/gr-jay/lib/garage_impl.h index 9f87eec..2990962 100644 --- a/gr-jay/lib/garage_impl.h +++ b/gr-jay/lib/garage_impl.h @@ -40,10 +40,11 @@ class garage_impl : public garage float m_vmin; float m_vmax; float m_v_sig; - float m_v_sig_m; - float m_v_thr; + float m_dc_corr; float m_lag_accu; - int m_bit; + float m_id_accu; + int m_id_bit; + int m_bitZeroCross; float m_i; int m_gapDistance; int m_gapCounter;