wip on clock sync block; exposing set gain function
authorTom <trondeau@vt.edu>
Tue, 6 Oct 2009 17:23:47 +0000 (10:23 -0700)
committerTom <trondeau@vt.edu>
Tue, 6 Oct 2009 17:23:47 +0000 (10:23 -0700)
gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc
gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h
gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i

index 91cbf74c6bf59b9fff636db12b7f02f2f4579c12..5577e42c8a8a0d34e35a2e0734cf7f2d291f2fd3 100644 (file)
@@ -60,7 +60,7 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain,
   // 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 = x*(d_nfilters-1);
+  d_acc = 0.5; //x*(d_nfilters-1);
   d_last_filter = (int)floor(d_acc);
   d_acc = fmodf(d_acc, 1);
   d_start_count = 0;
@@ -133,12 +133,22 @@ void
 gr_pfb_clock_sync_ccf::create_diff_taps(const std::vector<float> &newtaps,
                                        std::vector<float> &difftaps)
 {
+  float maxtap = -1e12;
   difftaps.clear();
   difftaps.push_back(0); //newtaps[0]);
   for(unsigned int i = 1; i < newtaps.size()-1; i++) {
-    difftaps.push_back(newtaps[i+1] - newtaps[i-1]);
+    float tap = newtaps[i+1] - newtaps[i-1];
+    if(tap > maxtap) {
+     maxtap = tap;
+    }
+    //maxtap += tap;
+    difftaps.push_back(tap);
   }
   difftaps.push_back(0);//-newtaps[newtaps.size()-1]);
+
+  for(unsigned int i = 0; i < difftaps.size(); i++) {
+    difftaps[i] /= 1;//maxtap;
+  }
 }
 
 void
@@ -219,24 +229,18 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items,
     err[i] = error;
 
     d_acc += d_alpha*error;
-    gr_branchless_clip(d_acc, 1);
-
-    int newfilter;
-    newfilter = (int)((float)d_last_filter + d_acc);
-    if(newfilter != (int)d_last_filter)
-      d_acc = 0.5;
-
-    if(newfilter >= (int)d_nfilters) {
-      d_last_filter = newfilter - d_nfilters;
+    if(d_acc >= (int)d_nfilters) {
+      d_acc -= d_nfilters;
       count++;
     }
-    else if(newfilter < 0) {
-      d_last_filter = d_nfilters + newfilter;
+    else if(d_acc < 0) {
+      d_acc += d_nfilters-1;
       count--;
     }
-    else {
-      d_last_filter = newfilter;
-    }
+
+    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;
index 1a04e55c7598ed24fe3321242d1460df3fb1da53..d99bd6fe717fde598d923798321278a88d5926ca 100644 (file)
@@ -29,9 +29,9 @@
 class gr_pfb_clock_sync_ccf;
 typedef boost::shared_ptr<gr_pfb_clock_sync_ccf> 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<float> &taps,
-                                                          unsigned int filter_size=32,
-                                                          float init_phase=0);
+                                                      const std::vector<float> &taps,
+                                                      unsigned int filter_size=32,
+                                                      float init_phase=0);
 
 class gr_fir_ccf;
 
@@ -96,6 +96,9 @@ public:
    */
   void print_taps();
   void print_diff_taps();
+
+  void set_gain(float gain)
+  { d_alpha = gain; }
   
   int general_work (int noutput_items,
                    gr_vector_int &ninput_items,
index 729d4a1aa905ab1bc0bb1747acb058775ef0014a..9defbc7cd090b0b31459418ddb695e2ec160c8f6 100644 (file)
@@ -46,4 +46,5 @@ class gr_pfb_clock_sync_ccf : public gr_block
   std::vector<float> diff_channel_taps(int channel);
   void print_taps();
   void print_diff_taps();
+  void set_gain(float gain);
 };