From 90b8b4cc8c53c963f8b0cf4bbc50277c031c3213 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 8 Oct 2009 21:40:16 -0700 Subject: [PATCH] Working on allowing fractional samples per symbol. --- .../src/lib/filter/gr_pfb_clock_sync_ccf.cc | 57 +- .../src/lib/filter/gr_pfb_clock_sync_ccf.h | 20 +- .../src/lib/filter/gr_pfb_clock_sync_ccf.i | 7 +- gnuradio-examples/grc/demod/pam_timing.grc | 858 ++++++++++-------- 4 files changed, 519 insertions(+), 423 deletions(-) diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc index 7dc5715d..a75b20d3 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc @@ -36,11 +36,13 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size, - float init_phase) + float init_phase, + float max_rate_deviation) { return gr_pfb_clock_sync_ccf_sptr (new gr_pfb_clock_sync_ccf (sps, gain, taps, filter_size, - init_phase)); + init_phase, + max_rate_deviation)); } int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)}; @@ -48,11 +50,13 @@ std::vector iosig(ios, ios+sizeof(ios)/sizeof(int)); gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size, - float init_phase) + float init_phase, + float max_rate_deviation) : gr_block ("pfb_clock_sync_ccf", gr_make_io_signature (1, 1, sizeof(gr_complex)), gr_make_io_signaturev (1, 4, iosig)), - d_updated (false), d_sps(sps) + d_updated (false), d_sps(sps), d_nfilters(filter_size), + d_max_dev(max_rate_deviation), d_start_count(0) { d_nfilters = filter_size; @@ -63,10 +67,8 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain, set_alpha(gain); set_beta(0.25*gain*gain); d_k = d_nfilters / 2; - d_filtnum = (int)floor(d_k); d_rate = 0; - d_start_count = 0; - + d_filtnum = (int)floor(d_k); d_filters = std::vector(d_nfilters); d_diff_filters = std::vector(d_nfilters); @@ -97,7 +99,7 @@ gr_pfb_clock_sync_ccf::set_taps (const std::vector &newtaps, std::vector< std::vector > &ourtaps, std::vector &ourfilter) { - unsigned int i,j; + int i,j; unsigned int ntaps = newtaps.size(); d_taps_per_filter = (unsigned int)ceil((double)ntaps/(double)d_nfilters); @@ -233,62 +235,65 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, // We need this many to process one output int nrequired = ninput_items[0] - d_taps_per_filter; - int i = 0, count = d_start_count; - float error; - float error_r, error_i; + int i = 0, count = (int)floor(d_sample_num); + float error, error_r, error_i; // produce output as long as we can and there are enough input samples while((i < noutput_items) && (count < nrequired)) { - - // FIXME: prevent this from asserting - assert(d_filtnum < d_nfilters); out[i] = d_filters[d_filtnum]->filter(&in[count]); - error_r = out[i].real() * d_diff_filters[d_filtnum]->filter(&in[count]).real(); - error_i = out[i].imag() * d_diff_filters[d_filtnum]->filter(&in[count]).imag(); + gr_complex diff = d_diff_filters[d_filtnum]->filter(&in[count]); + error_r = out[i].real() * diff.real(); + error_i = out[i].imag() * diff.imag(); error = error_i + error_r; d_k = d_k + d_alpha*error + d_rate; d_rate = d_rate + d_beta*error; d_filtnum = (int)floor(d_k); + // Keep the current filter number in [0, d_nfilters] + // If we've run beyond the last filter, wrap around and go to next sample + // If we've go below 0, wrap around and go to previous sample while(d_filtnum >= d_nfilters) { d_k -= d_nfilters; d_filtnum -= d_nfilters; - count++; + d_sample_num += 1.0; } while(d_filtnum < 0) { d_k += d_nfilters; d_filtnum += d_nfilters; - count--; + d_sample_num -= 1.0; } // Keep our rate within a good range - d_rate = gr_branchless_clip(d_rate, 1.5); + d_rate = gr_branchless_clip(d_rate, d_max_dev); i++; - count += d_sps; + d_sample_num += d_sps; + count = (int)floor(d_sample_num); if(output_items.size() > 2) { err[i] = error; outrate[i] = d_rate; outk[i] = d_k; } - - //printf("error: %f k: %f rate: %f\n", - // error, d_k, d_rate); } // Set the start index at the next entrance to the work function // if we stop because we run out of input items, jump ahead in the // next call to work. Otherwise, we can start at zero. + /* if(count > nrequired) { - d_start_count = count - (nrequired); + //d_start_count = count - (nrequired); + d_sample_num -= nrequired; consume_each(ninput_items[0]-d_taps_per_filter); } else { - d_start_count = 0; + d_sample_num -= floor(d_sample_num); consume_each(count); } - + */ + d_sample_num -= floor(d_sample_num); + consume_each(count); + return i; } diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h index 41e5d7b2..84e174b1 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h @@ -31,7 +31,8 @@ typedef boost::shared_ptr gr_pfb_clock_sync_ccf_sptr; gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size=32, - float init_phase=0); + float init_phase=0, + float max_rate_deviation=1.5); class gr_fir_ccf; @@ -53,12 +54,14 @@ class gr_pfb_clock_sync_ccf : public gr_block friend gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size, - float init_phase); + float init_phase, + float max_rate_deviation); bool d_updated; - unsigned int d_sps; + float d_sps; float d_alpha; float d_beta; + float d_sample_num; int d_nfilters; std::vector d_filters; std::vector d_diff_filters; @@ -66,9 +69,10 @@ class gr_pfb_clock_sync_ccf : public gr_block std::vector< std::vector > d_dtaps; float d_k; float d_rate; + float d_max_dev; int d_filtnum; + int d_taps_per_filter; unsigned int d_start_count; - unsigned int d_taps_per_filter; /*! * Build the polyphase filterbank timing synchronizer. @@ -76,7 +80,8 @@ class gr_pfb_clock_sync_ccf : public gr_block gr_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size, - float init_phase); + float init_phase, + float max_rate_deviation); void create_diff_taps(const std::vector &newtaps, std::vector &difftaps); @@ -107,6 +112,11 @@ public: { d_beta = beta; } + + void set_max_rate_deviation(float m) + { + d_max_dev = m; + } int general_work (int noutput_items, gr_vector_int &ninput_items, diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i index 78591547..9957c33b 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i @@ -25,7 +25,8 @@ GR_SWIG_BLOCK_MAGIC(gr,pfb_clock_sync_ccf); gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size=32, - float init_phase=0); + float init_phase=0, + float max_rate_deviation=1.5); class gr_pfb_clock_sync_ccf : public gr_block { @@ -33,7 +34,8 @@ class gr_pfb_clock_sync_ccf : public gr_block gr_pfb_clock_sync_ccf (float sps, float gain, const std::vector &taps, unsigned int filter_size, - float init_phase); + float init_phase, + float max_rate_deviation); public: ~gr_pfb_clock_sync_ccf (); @@ -48,4 +50,5 @@ class gr_pfb_clock_sync_ccf : public gr_block void print_diff_taps(); void set_alpha(float alpha); void set_beta(float beta); + void set_max_rate_deviation(float m); }; diff --git a/gnuradio-examples/grc/demod/pam_timing.grc b/gnuradio-examples/grc/demod/pam_timing.grc index a0dc6642..d51adb1f 100644 --- a/gnuradio-examples/grc/demod/pam_timing.grc +++ b/gnuradio-examples/grc/demod/pam_timing.grc @@ -1,6 +1,6 @@ - Wed Oct 7 20:47:05 2009 + Thu Oct 8 21:29:27 2009 options @@ -56,29 +56,6 @@ 0 - - variable - - id - samp_rate - - - _enabled - True - - - value - 320000 - - - _coordinate - (128, 9) - - - _rotation - 0 - - gr_uchar_to_float @@ -338,154 +315,6 @@ 0 - - variable - - id - rrctaps - - - _enabled - True - - - value - firdes.root_raised_cosine(nfilts,1.0,1.0/(spb*nfilts), .35, 11*spb*nfilts) - - - _coordinate - (513, 679) - - - _rotation - 0 - - - - root_raised_cosine_filter - - id - root_raised_cosine_filter_0_0 - - - _enabled - True - - - type - interp_fir_filter_fff - - - decim - 1 - - - interp - spb - - - gain - 2*spb - - - samp_rate - 1.0 - - - sym_rate - 1./spb - - - alpha - 0.35 - - - ntaps - 11*spb - - - _coordinate - (559, 303) - - - _rotation - 0 - - - - root_raised_cosine_filter - - id - root_raised_cosine_filter_0 - - - _enabled - True - - - type - interp_fir_filter_fff - - - decim - 1 - - - interp - spb - - - gain - 2*spb - - - samp_rate - 1.0 - - - sym_rate - 1./spb - - - alpha - 0.35 - - - ntaps - 11*spb - - - _coordinate - (557, 140) - - - _rotation - 0 - - - - gr_float_to_complex - - id - gr_float_to_complex_0 - - - _enabled - True - - - vlen - 1 - - - _coordinate - (897, 272) - - - _rotation - 0 - - variable_slider @@ -541,34 +370,11 @@ 0 - - variable - - id - nfilts - - - _enabled - True - - - value - 32 - - - _coordinate - (435, 686) - - - _rotation - 0 - - variable_slider id - beta + interpratio _enabled @@ -576,19 +382,19 @@ label - Timing Beta + Timing Offset value - 20e-3 + 1.00 min - 0.0 + 0.9 max - 0.1 + 1.1 num_steps @@ -612,7 +418,7 @@ _coordinate - (668, 5) + (40, 684) _rotation @@ -620,42 +426,46 @@ - variable_slider + wxgui_scopesink2 id - alpha + wxgui_scopesink2_0_0_0 _enabled True - label - Timing Alpha + type + float - value - 2 + title + Scope Plot - min - 0 + samp_rate + samp_rate - max - 10 + v_scale + 9 - num_steps - 1000 + t_scale + 0 - style - wx.SL_HORIZONTAL + ac_couple + False - converver - float_converter + xy_mode + False + + + num_inputs + 1 grid_pos @@ -663,11 +473,11 @@ notebook - + notebook_0,1 _coordinate - (552, 4) + (1115, 961) _rotation @@ -678,7 +488,7 @@ wxgui_scopesink2 id - wxgui_scopesink2_0 + wxgui_scopesink2_0_0_0_0 _enabled @@ -686,7 +496,7 @@ type - complex + float title @@ -698,7 +508,7 @@ v_scale - 0 + 1.25 t_scale @@ -722,11 +532,11 @@ notebook - + notebook_0,2 _coordinate - (1133, 325) + (1113, 844) _rotation @@ -734,42 +544,81 @@ - variable_slider + wxgui_scopesink2 id - freq_offset + wxgui_scopesink2_0_0 _enabled True - label - Frequency Offset + type + float - value - 0 + title + Error - min - -0.5 + samp_rate + samp_rate - max - 0.5 + v_scale + .5 - num_steps - 1000 + t_scale + 0 + + + ac_couple + False + + + xy_mode + False + + + num_inputs + 1 + + + grid_pos + + + + notebook + notebook_0,0 + + + _coordinate + (1113, 724) + + + _rotation + 0 + + + + notebook + + id + notebook_0 + + + _enabled + True style - wx.SL_HORIZONTAL + wx.NB_TOP - converver - float_converter + labels + ['error', 'phase', 'freq', 'FFT', 'Costas error'] grid_pos @@ -781,7 +630,7 @@ _coordinate - (293, 684) + (729, 769) _rotation @@ -792,7 +641,7 @@ variable id - spb + samp_rate _enabled @@ -800,11 +649,11 @@ value - 4 + 32000 _coordinate - (436, 752) + (128, 9) _rotation @@ -812,10 +661,10 @@ - wxgui_fftsink2 + gr_throttle id - wxgui_fftsink2_0 + gr_throttle_0 _enabled @@ -826,64 +675,184 @@ complex - title - FFT Plot + samples_per_second + samp_rate - samp_rate - samp_rate + vlen + 1 - baseband_freq + _coordinate + (1129, 462) + + + _rotation 0 + + + gr_costas_loop_cc - y_per_div - 10 + id + gr_costas_loop_cc_0 - y_divs - 10 + _enabled + False - ref_level - 50 + alpha + alpha_0 - ref_scale - 2.0 + beta + beta_0 - fft_size - 1024 + max_freq + 5 - fft_rate - 30 + min_freq + -5 - peak_hold - False + order + 4 - average - False + _coordinate + (299, 453) - avg_alpha + _rotation + 0 + + + + variable_slider + + id + freq_offset + + + _enabled + True + + + label + Frequency Offset + + + value 0 + + min + -0.5 + + + max + 0.5 + + + num_steps + 1000 + + + style + wx.SL_HORIZONTAL + + + converver + float_converter + grid_pos notebook - notebook_0,3 + _coordinate - (517, 767) + (293, 684) + + + _rotation + 0 + + + + variable + + id + rrctaps + + + _enabled + True + + + value + firdes.root_raised_cosine(nfilts,1.0,1.0/(spb*nfilts), .35, int(11*spb*nfilts)) + + + _coordinate + (513, 679) + + + _rotation + 0 + + + + root_raised_cosine_filter + + id + root_raised_cosine_filter_0_0 + + + _enabled + True + + + type + interp_fir_filter_fff + + + decim + 1 + + + interp + spb_gen + + + gain + 2*spb_gen + + + samp_rate + 1.0 + + + sym_rate + 1./spb_gen + + + alpha + 0.35 + + + ntaps + 11*spb_gen + + + _coordinate + (564, 301) _rotation @@ -894,7 +863,7 @@ variable_slider id - interpratio + alpha _enabled @@ -902,19 +871,19 @@ label - Timing Offset + Timing Alpha value - 1.00 + 0 min - 0.9 + 0 max - 1.1 + 10 num_steps @@ -938,18 +907,18 @@ _coordinate - (40, 684) + (552, 4) _rotation - 180 + 0 variable_slider id - beta_0 + beta _enabled @@ -957,11 +926,11 @@ label - Freq Beta + Timing Beta value - 0.001 + 0 min @@ -969,7 +938,7 @@ max - 0.01 + 0.1 num_steps @@ -993,7 +962,7 @@ _coordinate - (919, 7) + (668, 5) _rotation @@ -1008,7 +977,7 @@ _enabled - True + False label @@ -1056,46 +1025,42 @@ - wxgui_scopesink2 + variable_slider id - wxgui_scopesink2_0_0_0 + beta_0 _enabled - True - - - type - float + False - title - Scope Plot + label + Freq Beta - samp_rate - samp_rate + value + 0.001 - v_scale - 9 + min + 0.0 - t_scale - 0 + max + 0.01 - ac_couple - False + num_steps + 1000 - xy_mode - False + style + wx.SL_HORIZONTAL - num_inputs - 1 + converver + float_converter grid_pos @@ -1103,22 +1068,22 @@ notebook - notebook_0,1 + _coordinate - (1115, 961) + (919, 7) _rotation - 0 + 180 wxgui_scopesink2 id - wxgui_scopesink2_0_0_0_0 + wxgui_scopesink2_0 _enabled @@ -1126,7 +1091,7 @@ type - float + complex title @@ -1138,7 +1103,7 @@ v_scale - 1.25 + 0 t_scale @@ -1162,11 +1127,11 @@ notebook - notebook_0,2 + _coordinate - (1113, 844) + (1145, 258) _rotation @@ -1177,7 +1142,7 @@ wxgui_scopesink2 id - wxgui_scopesink2_0_0 + wxgui_scopesink2_0_0_1 _enabled @@ -1185,7 +1150,7 @@ type - float + complex title @@ -1221,11 +1186,11 @@ notebook - notebook_0,0 + notebook_0,4 _coordinate - (1113, 724) + (1107, 533) _rotation @@ -1233,58 +1198,96 @@ - wxgui_scopesink2 + variable id - wxgui_scopesink2_0_0_1 + spb_gen _enabled True - type - complex + value + 4 - title - Error + _coordinate + (119, 841) - samp_rate - samp_rate + _rotation + 0 + + + gr_float_to_complex - v_scale - .5 + id + gr_float_to_complex_0 - t_scale + _enabled + True + + + vlen + 1 + + + _coordinate + (904, 184) + + + _rotation 0 + + + root_raised_cosine_filter - ac_couple - False + id + root_raised_cosine_filter_0 - xy_mode - False + _enabled + True - num_inputs + type + interp_fir_filter_fff + + + decim 1 - grid_pos - + interp + spb_gen - notebook - notebook_0,4 + gain + 2*spb_gen + + + samp_rate + 1.0 + + + sym_rate + 1./spb_gen + + + alpha + 0.35 + + + ntaps + 11*spb_gen _coordinate - (1111, 518) + (557, 140) _rotation @@ -1292,34 +1295,22 @@ - notebook + variable id - notebook_0 + spb _enabled True - style - wx.NB_TOP - - - labels - ['error', 'phase', 'freq', 'FFT', 'Costas error'] - - - grid_pos - - - - notebook - + value + 4.01 _coordinate - (729, 769) + (32, 842) _rotation @@ -1334,7 +1325,7 @@ _enabled - True + False noise_voltage @@ -1350,7 +1341,7 @@ taps - 1.0 + 1.0j + 1.0 seed @@ -1358,7 +1349,38 @@ _coordinate - (65, 542) + (59, 543) + + + _rotation + 0 + + + + blks2_pfb_arb_resampler_ccf + + id + blks2_pfb_arb_resampler_ccf_0 + + + _enabled + True + + + rate + float(spb)/float(spb_gen) + + + taps + firdes.low_pass(320, 320, 0.45, 0.1) + + + size + 320 + + + _coordinate + (874, 374) _rotation @@ -1409,69 +1431,101 @@ - gr_throttle + wxgui_fftsink2 id - gr_throttle_0 + wxgui_fftsink2_0 _enabled - True + False type complex - samples_per_second + title + FFT Plot + + + samp_rate samp_rate - vlen - 1 + baseband_freq + 0 - _coordinate - (1129, 462) + y_per_div + 10 - _rotation + y_divs + 10 + + + ref_level + 50 + + + ref_scale + 2.0 + + + fft_size + 1024 + + + fft_rate + 30 + + + peak_hold + False + + + average + False + + + avg_alpha 0 - - - gr_costas_loop_cc - id - gr_costas_loop_cc_0 + grid_pos + - _enabled - True + notebook + notebook_0,3 - alpha - alpha_0 + _coordinate + (517, 767) - beta - beta_0 + _rotation + 0 + + + variable - max_freq - 5 + id + nfilts - min_freq - -5 + _enabled + True - order - 4 + value + 64 _coordinate - (916, 473) + (435, 686) _rotation @@ -1569,14 +1623,20 @@ 0 - gr_float_to_complex_0 - gr_channel_model_0 + gr_channel_model_0 + wxgui_fftsink2_0 0 0 gr_channel_model_0 - wxgui_fftsink2_0 + gr_costas_loop_cc_0 + 0 + 0 + + + gr_costas_loop_cc_0 + gr_pfb_clock_sync_ccf_0 0 0 @@ -1586,6 +1646,12 @@ 1 0 + + gr_pfb_clock_sync_ccf_0 + gr_throttle_0 + 0 + 0 + gr_channel_model_0 gr_pfb_clock_sync_ccf_0 @@ -1593,14 +1659,26 @@ 0 - gr_pfb_clock_sync_ccf_0 - gr_costas_loop_cc_0 + gr_float_to_complex_0 + blks2_pfb_arb_resampler_ccf_0 0 0 - gr_costas_loop_cc_0 - gr_throttle_0 + blks2_pfb_arb_resampler_ccf_0 + gr_channel_model_0 + 0 + 0 + + + blks2_pfb_arb_resampler_ccf_0 + wxgui_scopesink2_0_0_1 + 0 + 0 + + + blks2_pfb_arb_resampler_ccf_0 + gr_pfb_clock_sync_ccf_0 0 0 -- 2.30.2