From c1ab962946bb05b8a20a0f19dd294eb3b3056142 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 12 Oct 2009 17:55:17 -0400 Subject: [PATCH] This splits the rate into a fractional an integer value, which allows the loop to adjust the fractional rate while the integer rate keeps the increments moving properly. Allows the max rate deviation to be independent of the integer rate. Scaling of the differential taps also allows alpha and beta to operate independent of the rate when fractional samples per symbol are used. Slightly more tolerant to large signal values, but they still should be close to +/-1. --- .../src/lib/filter/gr_pfb_clock_sync_ccf.cc | 20 +- .../src/lib/filter/gr_pfb_clock_sync_ccf.h | 2 + gnuradio-examples/grc/demod/pam_timing.grc | 760 ++++++++++-------- 3 files changed, 428 insertions(+), 354 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 43412f25..433b7d61 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 @@ -68,6 +68,8 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float gain, set_beta(0.25*gain*gain); d_k = init_phase; d_rate = (sps-floor(sps))*(double)d_nfilters; + d_rate_i = (int)floor(d_rate); + d_rate_f = d_rate - (float)d_rate_i; d_filtnum = (int)floor(d_k); d_filters = std::vector(d_nfilters); @@ -137,13 +139,23 @@ void gr_pfb_clock_sync_ccf::create_diff_taps(const std::vector &newtaps, std::vector &difftaps) { + float maxtap = 1e-20; difftaps.clear(); difftaps.push_back(0); //newtaps[0]); for(unsigned int i = 1; i < newtaps.size()-1; i++) { float tap = newtaps[i+1] - newtaps[i-1]; difftaps.push_back(tap); + if(tap > maxtap) { + maxtap = tap; + } } difftaps.push_back(0);//-newtaps[newtaps.size()-1]); + + // Scale the differential taps; helps scale error term to better update state + // FIXME: should this be scaled this way or use the same gain as the taps? + for(unsigned int i = 0; i < difftaps.size(); i++) { + difftaps[i] /= maxtap; + } } void @@ -250,18 +262,18 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, error = (error_i + error_r) / 2.0; // average error from I&Q channel // Run the control loop to update the current phase (k) and tracking rate - d_k = d_k + d_alpha*error + d_rate; - d_rate = d_rate + d_beta*error; + d_k = d_k + d_alpha*error + d_rate_i + d_rate_f; + d_rate_f = d_rate_f + d_beta*error; // Keep our rate within a good range - d_rate = gr_branchless_clip(d_rate, d_max_dev); + d_rate_f = gr_branchless_clip(d_rate_f, d_max_dev); i++; count += (int)floor(d_sps); if(output_items.size() > 2) { err[i] = error; - outrate[i] = d_rate; + outrate[i] = d_rate_f; outk[i] = d_k; } } 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 778db59e..a07192a7 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 @@ -69,6 +69,8 @@ class gr_pfb_clock_sync_ccf : public gr_block std::vector< std::vector > d_dtaps; float d_k; float d_rate; + float d_rate_i; + float d_rate_f; float d_max_dev; int d_filtnum; int d_taps_per_filter; diff --git a/gnuradio-examples/grc/demod/pam_timing.grc b/gnuradio-examples/grc/demod/pam_timing.grc index 907233ac..4e2a2f86 100644 --- a/gnuradio-examples/grc/demod/pam_timing.grc +++ b/gnuradio-examples/grc/demod/pam_timing.grc @@ -1,6 +1,6 @@ - Fri Oct 9 14:51:58 2009 + Mon Oct 12 17:54:59 2009 options @@ -94,61 +94,6 @@ 0 - - variable_slider - - id - noise_amp - - - _enabled - True - - - label - Channel Noise - - - value - 0 - - - min - 0 - - - max - 1.0 - - - num_steps - 1000 - - - style - wx.SL_HORIZONTAL - - - converver - float_converter - - - grid_pos - - - - notebook - - - - _coordinate - (168, 684) - - - _rotation - 0 - - variable @@ -251,22 +196,18 @@ - variable_slider + random_source_x id - alpha + random_source_x_0 _enabled True - label - Timing Alpha - - - value - 0 + type + byte min @@ -274,31 +215,19 @@ max - 10 - - - num_steps - 1000 - - - style - wx.SL_HORIZONTAL - - - converver - float_converter + pam_amp - grid_pos - + num_samps + 10000 - notebook - + repeat + True _coordinate - (552, 4) + (13, 80) _rotation @@ -306,77 +235,92 @@ - variable_slider + random_source_x id - beta + random_source_x_0_0 _enabled True - label - Timing Beta + type + byte - value + min 0 - min - 0.0 + max + pam_amp - max - 0.1 + num_samps + 10000 - num_steps - 1000 + repeat + True - style - wx.SL_HORIZONTAL + _coordinate + (15, 245) - converver - float_converter + _rotation + 0 + + + const_source_x - grid_pos - + id + const_source_x_0 - notebook - + _enabled + True + + + type + float + + + const + -0.5*(pam_amp-1) _coordinate - (668, 5) + (213, 197) _rotation - 180 + 0 - variable + const_source_x id - spb_gen + const_source_x_0_0 _enabled True - value - 4 + type + float + + + const + -0.5*(pam_amp-1) _coordinate - (119, 841) + (200, 360) _rotation @@ -384,42 +328,46 @@ - variable_slider + wxgui_scopesink2 id - interpratio + wxgui_scopesink2_0_0_0_0 _enabled True - label - Timing Offset + type + float - value - 1.00 + title + Scope Plot - min - 0.9 + samp_rate + samp_rate - max - 1.1 + v_scale + 1.25 - num_steps - 1000 + t_scale + 0 - style - wx.SL_HORIZONTAL + ac_couple + False - converver - float_converter + xy_mode + False + + + num_inputs + 1 grid_pos @@ -427,22 +375,22 @@ notebook - + notebook_0,2 _coordinate - (40, 684) + (1111, 767) _rotation - 180 + 0 - random_source_x + wxgui_scopesink2 id - random_source_x_0 + wxgui_scopesink2_0_0_0 _enabled @@ -450,27 +398,47 @@ type - byte + float - min + title + Scope Plot + + + samp_rate + samp_rate + + + v_scale + 9 + + + t_scale 0 - max - pam_amp + ac_couple + False - num_samps - 10000 + xy_mode + False - repeat - True + num_inputs + 1 + + + grid_pos + + + + notebook + notebook_0,1 _coordinate - (13, 80) + (1112, 881) _rotation @@ -478,38 +446,38 @@ - random_source_x + gr_channel_model id - random_source_x_0_0 + gr_channel_model_0 _enabled True - type - byte + noise_voltage + noise_amp - min - 0 + freq_offset + freq_offset - max - pam_amp + epsilon + interpratio - num_samps - 10000 + taps + 1.0 - repeat - True + seed + 42 _coordinate - (15, 245) + (59, 543) _rotation @@ -517,10 +485,10 @@ - const_source_x + gr_throttle id - const_source_x_0 + gr_throttle_0 _enabled @@ -528,15 +496,19 @@ type - float + complex - const - -0.5*(pam_amp-1) + samples_per_second + samp_rate + + + vlen + 1 _coordinate - (213, 197) + (290, 575) _rotation @@ -544,26 +516,34 @@ - const_source_x + notebook id - const_source_x_0_0 + notebook_0 _enabled True - type - float + style + wx.NB_TOP - const - -0.5*(pam_amp-1) + labels + ['error', 'phase', 'freq', 'Resampled Signal'] + + + grid_pos + + + + notebook + _coordinate - (200, 360) + (729, 769) _rotation @@ -574,7 +554,7 @@ wxgui_scopesink2 id - wxgui_scopesink2_0_0 + wxgui_scopesink2_0_0_1 _enabled @@ -582,7 +562,7 @@ type - float + complex title @@ -618,11 +598,11 @@ notebook - notebook_0,0 + notebook_0,3 _coordinate - (1110, 651) + (1115, 358) _rotation @@ -630,10 +610,10 @@ - wxgui_scopesink2 + gr_add_xx id - wxgui_scopesink2_0_0_0_0 + gr_add_xx_0 _enabled @@ -644,44 +624,70 @@ float - title - Scope Plot + num_inputs + 2 - samp_rate - samp_rate + vlen + 1 - v_scale - 1.25 + _coordinate + (440, 167) - t_scale + _rotation 0 + + + gr_add_xx + + id + gr_add_xx_0_1 + - ac_couple - False + _enabled + True - xy_mode - False + type + float num_inputs + 2 + + + vlen 1 - grid_pos - + _coordinate + (430, 330) - notebook - notebook_0,2 + _rotation + 0 + + + + gr_float_to_complex + + id + gr_float_to_complex_0 + + + _enabled + True + + + vlen + 1 _coordinate - (1111, 767) + (590, 184) _rotation @@ -692,7 +698,7 @@ wxgui_scopesink2 id - wxgui_scopesink2_0_0_0 + wxgui_scopesink2_0 _enabled @@ -700,7 +706,7 @@ type - float + complex title @@ -712,7 +718,7 @@ v_scale - 9 + 0 t_scale @@ -736,11 +742,11 @@ notebook - notebook_0,1 + _coordinate - (1112, 881) + (1116, 500) _rotation @@ -748,38 +754,22 @@ - gr_channel_model + variable id - gr_channel_model_0 + nfilts _enabled True - noise_voltage - noise_amp - - - freq_offset - freq_offset - - - epsilon - interpratio - - - taps - 1.0 - - - seed - 42 + value + 32 _coordinate - (59, 543) + (435, 686) _rotation @@ -787,30 +777,46 @@ - gr_throttle + gr_pfb_clock_sync_ccf id - gr_throttle_0 + gr_pfb_clock_sync_ccf_0 _enabled True - type - complex + sps + spb - samples_per_second - samp_rate + alpha + alpha - vlen - 1 + beta + beta + + + taps + rrctaps + + + filter_size + nfilts + + + init_phase + 16 + + + max_dev + 1.5 _coordinate - (290, 575) + (512, 527) _rotation @@ -818,22 +824,42 @@ - notebook + variable_slider id - notebook_0 + noise_amp _enabled True + + label + Channel Noise + + + value + 0 + + + min + 0 + + + max + 1.0 + + + num_steps + 1000 + style - wx.NB_TOP + wx.SL_HORIZONTAL - labels - ['error', 'phase', 'freq', 'Resampled Signal'] + converver + float_converter grid_pos @@ -845,7 +871,7 @@ _coordinate - (729, 769) + (168, 684) _rotation @@ -853,46 +879,42 @@ - wxgui_scopesink2 + variable_slider id - wxgui_scopesink2_0_0_1 + interpratio _enabled - True - - - type - complex + True - title - Error + label + Timing Offset - samp_rate - samp_rate + value + 1.00 - v_scale - .5 + min + 0.99 - t_scale - 0 + max + 1.01 - ac_couple - False + num_steps + 1000 - xy_mode - False + style + wx.SL_HORIZONTAL - num_inputs - 1 + converver + float_converter grid_pos @@ -900,22 +922,22 @@ notebook - notebook_0,3 + _coordinate - (1115, 358) + (40, 684) _rotation - 0 + 180 variable id - spb + spb_gen _enabled @@ -923,11 +945,11 @@ value - 4.1 + 4 _coordinate - (32, 842) + (119, 841) _rotation @@ -935,61 +957,109 @@ - gr_add_xx + variable_slider id - gr_add_xx_0 + beta _enabled True - type - float + label + Timing Beta - num_inputs - 2 + value + 0 - vlen - 1 + min + 0.0 + + + max + 0.1 + + + num_steps + 1000 + + + style + wx.SL_HORIZONTAL + + + converver + float_converter + + + grid_pos + + + + notebook + _coordinate - (440, 167) + (668, 5) _rotation - 0 + 180 - gr_add_xx + variable_slider id - gr_add_xx_0_1 + alpha _enabled True - type - float + label + Timing Alpha - num_inputs - 2 + value + 0 - vlen + min + 0 + + + max 1 + + num_steps + 1000 + + + style + wx.SL_HORIZONTAL + + + converver + float_converter + + + grid_pos + + + + notebook + + _coordinate - (430, 330) + (552, 4) _rotation @@ -997,53 +1067,58 @@ - blks2_pfb_arb_resampler_ccf + wxgui_scopesink2 id - blks2_pfb_arb_resampler_ccf_0 + wxgui_scopesink2_0_0 _enabled True - rate - float(spb)/float(spb_gen) + type + float - taps - firdes.low_pass(128, 128, 0.45, 0.1) + title + Error - size - 128 + samp_rate + samp_rate - _coordinate - (617, 374) + v_scale + 3 - _rotation + t_scale 0 - - - gr_float_to_complex - id - gr_float_to_complex_0 + ac_couple + False - _enabled - True + xy_mode + False - vlen + num_inputs 1 + + grid_pos + + + + notebook + notebook_0,0 + _coordinate - (590, 184) + (1110, 651) _rotation @@ -1094,7 +1169,7 @@ _coordinate - (832, 157) + (834, 157) _rotation @@ -1102,58 +1177,61 @@ - wxgui_scopesink2 + blks2_pfb_arb_resampler_ccf id - wxgui_scopesink2_0 + blks2_pfb_arb_resampler_ccf_0 _enabled True - type - complex + rate + float(spb)/float(spb_gen) - title - Scope Plot + taps + firdes.low_pass(128, 128, 0.45, 0.1) - samp_rate - samp_rate + size + 128 - v_scale - 0 + _coordinate + (617, 374) - t_scale + _rotation 0 + + + gr_multiply_const_vxx - ac_couple - False + id + gr_multiply_const_vxx_0 - xy_mode - False + _enabled + True - num_inputs - 1 + type + complex - grid_pos - + const + sig_amp - notebook - + vlen + 1 _coordinate - (1116, 500) + (1096, 197) _rotation @@ -1164,7 +1242,7 @@ variable id - nfilts + pam_amp _enabled @@ -1172,11 +1250,11 @@ value - 64 + 2 _coordinate - (435, 686) + (223, 9) _rotation @@ -1184,46 +1262,22 @@ - gr_pfb_clock_sync_ccf + variable id - gr_pfb_clock_sync_ccf_0 + spb _enabled True - sps - spb - - - alpha - alpha - - - beta - beta - - - taps - rrctaps - - - filter_size - nfilts - - - init_phase - 16 - - - max_dev - 20 + value + 4.1 _coordinate - (512, 527) + (32, 842) _rotation @@ -1234,7 +1288,7 @@ variable id - pam_amp + sig_amp _enabled @@ -1242,11 +1296,11 @@ value - 2 + 1 _coordinate - (223, 9) + (315, 9) _rotation @@ -1357,6 +1411,12 @@ root_raised_cosine_filter_0 + gr_multiply_const_vxx_0 + 0 + 0 + + + gr_multiply_const_vxx_0 blks2_pfb_arb_resampler_ccf_0 0 0 -- 2.47.2