Merge branch 'wip/sync' of http://gnuradio.org/git/jcorgan into sync
authorTom <trondeau@vt.edu>
Wed, 7 Oct 2009 00:53:30 +0000 (17:53 -0700)
committerTom <trondeau@vt.edu>
Wed, 7 Oct 2009 00:53:30 +0000 (17:53 -0700)
gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc
gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h

index f7dd9468557162af4e99961613c91dd784402292..79779c91cf6ad206e425077c64194f21a0cb970b 100644 (file)
@@ -51,7 +51,7 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain,
   : gr_block ("pfb_clock_sync_ccf",
              gr_make_io_signature (1, 1, sizeof(gr_complex)),
              gr_make_io_signature2 (1, 2, sizeof(gr_complex), sizeof(float))),
-    d_updated (false), d_sps(sps), d_alpha(gain)
+    d_updated (false), d_sps(sps)
 {
   d_nfilters = filter_size;
 
@@ -59,10 +59,9 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain,
   // The accumulator keeps track of overflow to increment the stride correctly.
   // set it here to the fractional difference based on the initial phaes
   // assert(init_phase <= 2*M_PI);
-  float x = init_phase / (2*M_PI); //normalize initial phase
-  d_acc = 0.5; //x*(d_nfilters-1);
-  d_last_filter = (int)floor(d_acc);
-  d_acc = fmodf(d_acc, 1);
+  set_gain(gain);
+  d_k = d_nfilters / 2;
+  d_rate = 0;
   d_start_count = 0;
   
 
@@ -210,9 +209,12 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items,
   gr_complex *in = (gr_complex *) input_items[0];
   gr_complex *out = (gr_complex *) output_items[0];
 
-  float *err;
-  if(ninput_items.size() == 2)
+  float *err, *outrate, *outk;
+  if(output_items.size() > 2) {
     err = (float *) output_items[1];
+    outrate = (float*)output_items[2];
+    outk = (float*)output_items[3];
+  }
   
   if (d_updated) {
     d_updated = false;
@@ -227,28 +229,32 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items,
 
   // produce output as long as we can and there are enough input samples
   while((i < noutput_items) && (count < nrequired)) {
-    out[i] = d_filters[d_last_filter]->filter(&in[count]);
-    error =  (out[i] * d_diff_filters[d_last_filter]->filter(&in[count])).real();
-
-    if(ninput_items.size() == 2)
-      err[i] = error;
-
-    d_acc += d_alpha*error;
-    if(d_acc >= (int)d_nfilters) {
-      d_acc -= d_nfilters;
+    int filtnum = (int)d_k;
+    out[i] = d_filters[filtnum]->filter(&in[count]);
+    error =  (out[i] * d_diff_filters[filtnum]->filter(&in[count])).real();
+
+    d_k = d_k + d_alpha*error + d_rate;
+    d_rate = d_rate + d_beta*error;
+    while(d_k >= d_nfilters) {
+      d_k -= d_nfilters;
       count++;
     }
-    else if(d_acc < 0) {
-      d_acc += d_nfilters-1;
+    while(d_k < 0) {
+      d_k += d_nfilters;
       count--;
     }
 
-    d_last_filter = (int)floor(d_acc);
-    printf("error: %e  d_acc: %e  filter: %d\n",
-          error, d_acc, d_last_filter);
-
     i++;
     count += d_sps;
+
+    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
index d99bd6fe717fde598d923798321278a88d5926ca..b8e0f83b68bc4a8f8c3c9073c5e334cd57075263 100644 (file)
@@ -58,13 +58,14 @@ class gr_pfb_clock_sync_ccf : public gr_block
   bool                    d_updated;
   unsigned int             d_sps;
   float                    d_alpha;
+  float                    d_beta;
   unsigned int             d_nfilters;
   std::vector<gr_fir_ccf*> d_filters;
   std::vector<gr_fir_ccf*> d_diff_filters;
   std::vector< std::vector<float> > d_taps;
   std::vector< std::vector<float> > d_dtaps;
-  float                    d_acc;
-  unsigned int             d_last_filter;
+  float                    d_k;
+  float                    d_rate;
   unsigned int             d_start_count;
   unsigned int             d_taps_per_filter;
 
@@ -98,7 +99,10 @@ public:
   void print_diff_taps();
 
   void set_gain(float gain)
-  { d_alpha = gain; }
+  { 
+    d_alpha = gain;
+    d_beta = 0.25*d_alpha*d_alpha;
+  }
   
   int general_work (int noutput_items,
                    gr_vector_int &ninput_items,