- improvement: use Integrate and Dump filter

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@385 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-01-07 14:54:49 +00:00
parent 8329c50ec9
commit 417e081501
2 changed files with 46 additions and 37 deletions
+42 -34
View File
@@ -26,7 +26,7 @@
#include "garage_impl.h" #include "garage_impl.h"
#define WITH_DEBUG_MESSAGES 0 #define WITH_DEBUG_MESSAGES 0
#define WITH_DEBUG_FILE 0 #define WITH_DEBUG_FILE 1
namespace gr namespace gr
{ {
@@ -53,10 +53,11 @@ garage_impl::garage_impl(int sampleRate, int samplesPerSym, float kLoopFilter, f
, m_vmin(0) , m_vmin(0)
, m_vmax(0) , m_vmax(0)
, m_v_sig(0) , m_v_sig(0)
, m_v_sig_m(0.5f) , m_dc_corr(0)
, m_v_thr(0)
, m_lag_accu(0) , m_lag_accu(0)
, m_bit(0) , m_id_accu(0)
, m_id_bit(0)
, m_bitZeroCross(0)
, m_i(0) , m_i(0)
, m_gapDistance(8*m_samplesPerSym) , m_gapDistance(8*m_samplesPerSym)
, m_gapCounter(0) , 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) 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]; const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0]; float *out = (float *) output_items[0];
int outCount = 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+> // Do <+signal processing+>
int countReload = m_samplesPerSym-1; int countReload = m_samplesPerSym-1;
float alpha_thr = 0.5f; float alpha_thr = 0.002f;
float hyst_thr = 0.5f; float hyst_thr = 0.1f;
float k_leadLag = m_kLoopFilter; float k_leadLag = m_kLoopFilter;
float loopThreshold = m_kThreshold; float loopThreshold = m_kThreshold;
float k_lead = 1.0e-1f; 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 err = 0;
float alpha_sig = 0.5f/m_samplesPerSym; float alpha_sig = 0.5f/m_samplesPerSym;
float alpha_sig_m = alpha_sig/5;
int i_i = 0; int i_i = 0;
while ((i_i+1) < ninput_items[0]) while ((i_i+1) < ninput_items[0])
{ {
// Get next interpolated sample // Get next interpolated sample
float i_f = m_i - (float)i_i; 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 // Calculate threshold
m_v_thr = (fabs(m_vmax) - fabs(m_vmin))/2; m_vmin *= rho;
m_vmax *= rho;
if (y < m_vmin) if (y < m_vmin)
{ {
m_vmin = (1-alpha_thr)*m_vmin + alpha_thr*y; m_vmin = y;
} }
else if (y > m_vmax) 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 // Signal detection
float y_nodc = (y-m_v_thr); m_v_sig = (1.f-alpha_sig)*m_v_sig + alpha_sig*y*y;
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;
bool isSignal = m_v_sig >= loopThreshold; 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; int bitChg = 0;
if (isSignal) if (isSignal)
{ {
if (m_bitZeroCross == 1)
// Detect bit change
if (m_bit == 1)
{ {
if (y < (hyst_thr*m_v_thr)) if (y < -hyst_thr)
{ {
m_bit = 0; m_bitZeroCross = 0;
bitChg = 1; bitChg = 1;
} }
} }
else else
{ {
if (y > (hyst_thr*m_v_thr)) if (y > +hyst_thr)
{ {
m_bit = 1; m_bitZeroCross = 1;
bitChg = 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 // Sample bit at baud rate = fs/numSamplesPerSym
if (m_count == 0) if (m_count == 0)
{ {
out[outCount++] = (float)m_bit;
m_count = countReload; 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 else
{ {
@@ -214,7 +222,7 @@ int garage_impl::general_work (int noutput_items, gr_vector_int &ninput_items, g
if (m_pFile_y) 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++; m_sampleCounter++;
+4 -3
View File
@@ -40,10 +40,11 @@ class garage_impl : public garage
float m_vmin; float m_vmin;
float m_vmax; float m_vmax;
float m_v_sig; float m_v_sig;
float m_v_sig_m; float m_dc_corr;
float m_v_thr;
float m_lag_accu; float m_lag_accu;
int m_bit; float m_id_accu;
int m_id_bit;
int m_bitZeroCross;
float m_i; float m_i;
int m_gapDistance; int m_gapDistance;
int m_gapCounter; int m_gapCounter;