commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4561 - gnuradio/branches/developers/n4hy/ofdm/gnuradi


From: trondeau
Subject: [Commit-gnuradio] r4561 - gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen
Date: Wed, 21 Feb 2007 12:28:14 -0700 (MST)

Author: trondeau
Date: 2007-02-21 12:28:13 -0700 (Wed, 21 Feb 2007)
New Revision: 4561

Modified:
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.cc.t
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.h.t
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.i.t
Log:
improvements to peak detector

Modified: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.cc.t
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.cc.t
        2007-02-21 18:36:20 UTC (rev 4560)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.cc.t
        2007-02-21 19:28:13 UTC (rev 4561)
@@ -30,18 +30,18 @@
 #include <gr_io_signature.h>
 
 @SPTR_NAME@
address@hidden@ ()
address@hidden@ (float threshold_factor, int look_ahead, float alpha)
 {
-  return @SPTR_NAME@ (new @NAME@ ());
+  return @SPTR_NAME@ (new @NAME@ (threshold_factor, look_ahead, alpha));
 }
 
address@hidden@::@NAME@ ()
address@hidden@::@NAME@ (float threshold_factor, int look_ahead, float alpha)
   : gr_sync_block ("@BASE_NAME@",
                   gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
                   gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
-    d_avg(0), d_found(0)
+    d_threshold_factor(threshold_factor), d_look_ahead(look_ahead), 
+    d_avg_alpha(alpha), d_avg(0), d_found(0)
 {
-  set_history(1); // so we can look behind us
 }
 
 int
@@ -52,37 +52,51 @@
   @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0];
   @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
 
-  //unsigned char found = 0;
-  float alpha = 0.01;
-  for(int i=0;i<noutput_items;i++) {
-    d_avg = (alpha)*iptr[i] + (1-alpha)*d_avg;
-  }
+  memset(optr, 0, noutput_items*sizeof(@O_TYPE@));
 
-  for (int i = 0; i < noutput_items; i++){
-    if(iptr[i] > d_avg*0.25) {
-      if(d_found==0) {
-       d_found = 1;
-       for(int j = 0; j < 10; j++) {
-         if(iptr[i+j] > iptr[i]) {
-           d_found = 0;
-         }
-       }
-      
-       if(d_found) {
-         optr[i] = (@O_TYPE@)1;
-       }
-       else {
-         optr[i] = (@O_TYPE@)0;
-       }
+  @I_TYPE@ peak_val = -INFINITY;
+  int peak_ind = 0;
+  unsigned char state = 0;
+  int i = 0;
+
+  //printf("noutput_items %d\n",noutput_items);
+  while(i < noutput_items) {
+    if(state == 0) {  // below threshold
+      if(iptr[i] > d_avg*d_threshold_factor) {
+       state = 1;
       }
       else {
-       optr[i] = (@O_TYPE@)0;
+       d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+       i++;
       }
     }
-    else {
-      d_found = 0;
-      optr[i] = (@O_TYPE@)0;
+    else if(state == 1) {  // above threshold, have not found peak
+      //printf("Entered State 1: %f  i: %d  noutput_items: %d\n", iptr[i], i, 
noutput_items);
+      if(iptr[i] > peak_val) {
+       peak_val = iptr[i];
+       peak_ind = i;
+       d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+       i++;
+      }
+      else if (iptr[i] > d_avg*d_threshold_factor) {
+       d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+       i++;
+      }
+      else {
+       optr[peak_ind] = (@O_TYPE@)1;
+       state = 0;
+       peak_val = -INFINITY;
+       //printf("Leaving  State 1: Peak: %f  Peak Ind: %d   i: %d  
noutput_items: %d\n", peak_val, peak_ind, i, noutput_items);
+      }
     }
   }
-  return noutput_items;
+
+  if(state == 0) {
+    //printf("Leave in State 0, produced %d\n",noutput_items);
+    return noutput_items;
+  }
+  else if(state == 1) {   // only return up to passing the threshold
+    //printf("Leave in State 1, only produced %d of 
%d\n",peak_ind,noutput_items);
+    return peak_ind;
+  }
 }

Modified: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.h.t
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.h.t
 2007-02-21 18:36:20 UTC (rev 4560)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.h.t
 2007-02-21 19:28:13 UTC (rev 4561)
@@ -30,7 +30,9 @@
 class @NAME@;
 typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
 
address@hidden@ address@hidden@ ();
address@hidden@ address@hidden@ (float threshold_factor = 0.25, 
+                                int look_ahead = 10,
+                                float alpha = 0.001);
 
 /*!
  * \brief Detect the peak of a signal
@@ -38,19 +40,64 @@
  *
  * If a peak is detected, this block outputs a 1, 
  * or it outputs 0's.
+ *
+ * \param threshold_factor The threshold factor determins when a peak
+ *        has started. An average of the signal is calculated and when the 
+ *        value of the signal goes over threshold_factor*average, we start 
+ *        looking for a peak.
+ * \param look_ahead The look-ahead value is used when the threshold is
+ *        found to look if there another peak within this step range.
+ *        If there is a larger value, we set that as the peak and look ahead
+ *        again. This is continued until the highest point is found with
+ *        This look-ahead range.
  */
 class @NAME@ : public gr_sync_block
 {
-  friend @SPTR_NAME@ address@hidden@ ();
+  friend @SPTR_NAME@ address@hidden@ (float threshold_factor, 
+                                         int look_ahead,
+                                         float alpha);
 
-  @NAME@ ();
+  @NAME@ (float threshold_factor, int look_ahead, float alpha);
 
  private:
+  float d_threshold_factor;
+  int d_look_ahead;
+  float d_avg_alpha;
   float d_avg;
   unsigned char d_found;
 
  public:
 
+  /*! \brief Set the threshold factor value
+   *  \param thr new threshold factor
+   */
+  void set_threshold_factor(float thr) { d_threshold_factor = thr; }
+
+  /*! \brief Set the look-ahead factor
+   *  \param look new look-ahead factor
+   */
+  void set_look_ahead(int look) { d_look_ahead = look; }
+
+  /*! \brief Set the running average alpha
+   *  \param alpha new alpha for running average
+   */
+  void set_alpha(int alpha) { d_avg_alpha = alpha; }
+
+  /*! \brief Get the threshold factor value
+   *  \return threshold factor
+   */
+  float threshold_factor() { return d_threshold_factor; }
+
+  /*! \brief Get the look-ahead factor value
+   *  \return look-ahead factor
+   */
+  int look_ahead() { return d_look_ahead; }
+
+  /*! \brief Get the alpha value of the running average
+   *  \return alpha
+   */
+  float alpha() { return d_avg_alpha; }
+
   int work (int noutput_items,
            gr_vector_const_void_star &input_items,
            gr_vector_void_star &output_items);

Modified: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.i.t
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.i.t
 2007-02-21 18:36:20 UTC (rev 4560)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/lib/gengen/gr_peak_detector_XX.i.t
 2007-02-21 19:28:13 UTC (rev 4561)
@@ -24,10 +24,21 @@
 
 GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@)
 
address@hidden@ address@hidden@ ();
address@hidden@ address@hidden@ (float threshold_factor = 0.25, 
+                                int look_ahead = 10,
+                                float alpha=0.001);
 
 class @NAME@ : public gr_sync_block
 {
  private:
-  @NAME@ ();
+  @NAME@ (float threshold_factor, int look_ahead, float alpha);
+
+ public:
+  void set_threshold_factor(float thr) { d_threshold_factor = thr; }
+  void set_look_ahead(int look) { d_look_ahead = look; }
+  void set_alpha(int alpha) { d_avg_alpha = alpha; }
+
+  float threshold_factor() { return d_threshold_factor; }
+  int look_ahead() { return d_look_ahead; }
+  float alpha() { return d_avg_alpha; }
 };





reply via email to

[Prev in Thread] Current Thread [Next in Thread]