commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7156 - gnuradio/branches/developers/trondeau/ofdm2/gn


From: trondeau
Subject: [Commit-gnuradio] r7156 - gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general
Date: Thu, 13 Dec 2007 15:33:41 -0700 (MST)

Author: trondeau
Date: 2007-12-13 15:33:39 -0700 (Thu, 13 Dec 2007)
New Revision: 7156

Added:
   
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.cc
   
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.h
   
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.i
Modified:
   
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/Makefile.am
   
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/general.i
Log:
Adding Kyle Jamieson's peak detector code. We will probably want to either move 
this to gengen alongside gr_peak_detector or replace it.

Modified: 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/Makefile.am
       2007-12-13 21:08:10 UTC (rev 7155)
+++ 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/Makefile.am
       2007-12-13 22:33:39 UTC (rev 7156)
@@ -109,6 +109,7 @@
         gr_ofdm_sampler.cc              \
        gr_pa_2x2_phase_combiner.cc     \
        gr_packet_sink.cc               \
+       gr_peak_detector2_fb.cc         \
        gr_phase_modulator_fc.cc        \
        gr_pll_carriertracking_cc.cc    \
        gr_pll_freqdet_cf.cc            \
@@ -252,6 +253,7 @@
        gr_ofdm_sampler.h               \
        gr_pa_2x2_phase_combiner.h      \
        gr_packet_sink.h                \
+       gr_peak_detector2_fb.h          \
        gr_phase_modulator_fc.h         \
        gr_pll_carriertracking_cc.h     \
        gr_pll_freqdet_cf.h             \
@@ -396,6 +398,7 @@
        gr_ofdm_sampler.i               \
        gr_pa_2x2_phase_combiner.i      \
        gr_packet_sink.i                \
+       gr_peak_detector2_fb.i          \
        gr_phase_modulator_fc.i         \
        gr_pll_carriertracking_cc.i     \
        gr_pll_freqdet_cf.i             \

Modified: 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/general.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/general.i
 2007-12-13 21:08:10 UTC (rev 7155)
+++ 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/general.i
 2007-12-13 22:33:39 UTC (rev 7156)
@@ -128,6 +128,7 @@
 #include <gr_bin_statistics_f.h>
 #include <gr_glfsr_source_b.h>
 #include <gr_glfsr_source_f.h>
+#include <gr_peak_detector2_fb.h>
 %}
 
 %include "gr_nop.i"
@@ -236,3 +237,4 @@
 %include "gr_bin_statistics_f.i"
 %include "gr_glfsr_source_b.i"
 %include "gr_glfsr_source_f.i"
+%include "gr_peak_detector2_fb.i"

Added: 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.cc
===================================================================
--- 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.cc
                           (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.cc
   2007-12-13 22:33:39 UTC (rev 7156)
@@ -0,0 +1,106 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_peak_detector2_fb.h>
+#include <gr_io_signature.h>
+
+gr_peak_detector2_fb_sptr
+gr_make_peak_detector2_fb (float threshold_factor_rise,
+                          int look_ahead, float alpha)
+{
+  return gr_peak_detector2_fb_sptr (new gr_peak_detector2_fb 
(threshold_factor_rise, 
+                                 look_ahead, alpha));
+}
+
+gr_peak_detector2_fb::gr_peak_detector2_fb (float threshold_factor_rise, 
+                                           int look_ahead, float alpha)
+  : gr_sync_block ("peak_detector2_fb",
+                  gr_make_io_signature (1, 1, sizeof(float)),
+                  gr_make_io_signature2 (1, 2, sizeof(char), sizeof(float))),
+    d_threshold_factor_rise(threshold_factor_rise), 
+    d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false)
+{
+}
+
+int
+gr_peak_detector2_fb::work (int noutput_items,
+                           gr_vector_const_void_star &input_items,
+                           gr_vector_void_star &output_items) {
+  float *iptr = (float *) input_items[0];
+  char *optr = (char *) output_items[0];
+  
+  assert(noutput_items >= 2);
+
+  memset(optr, 0, noutput_items*sizeof(char));
+
+  for (int i = 0; i < noutput_items; i++) {
+
+    if (!d_found) {
+      // Have not yet detected presence of peak
+      if (iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) {
+       d_found = true;
+       d_look_ahead_remaining = d_look_ahead;
+        d_peak_val = -(float)INFINITY;
+      } 
+      else {
+       d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg;
+      }
+    } 
+    else {
+      // Detected presence of peak
+      if (iptr[i] > d_peak_val) {
+        d_peak_val = iptr[i];
+        d_peak_ind = i;
+      } 
+      else if (d_look_ahead_remaining <= 0) {
+        optr[d_peak_ind] = 1;
+        d_found = false;
+        d_avg = iptr[i];
+      }
+      
+      // Have not yet located peak, loop and keep searching.
+      d_look_ahead_remaining--;
+    }
+    
+    // Every iteration of the loop, write debugging signal out if
+    // connected:
+    if (output_items.size() == 2) {
+      float *sigout = (float *) output_items[1];
+      sigout[i] = d_avg;
+    }
+  } // loop
+  
+  if (!d_found) 
+    return noutput_items;
+  
+  // else if detected presence, keep searching during the next call to work.
+  int tmp = d_peak_ind;
+  d_peak_ind = 1;
+  
+  return tmp - 1; 
+}
+
+

Added: 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.h
===================================================================
--- 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.h
                            (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.h
    2007-12-13 22:33:39 UTC (rev 7156)
@@ -0,0 +1,108 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_gr_peak_detector2_FB_H
+#define INCLUDED_gr_peak_detector2_FB_H
+
+#include <gr_sync_block.h>
+
+class gr_peak_detector2_fb;
+typedef boost::shared_ptr<gr_peak_detector2_fb> gr_peak_detector2_fb_sptr;
+
+gr_peak_detector2_fb_sptr gr_make_peak_detector2_fb (float 
threshold_factor_rise = 7,
+                                                    int look_ahead = 1000,
+                                                    float alpha = 0.001);
+
+/*!
+ * \brief Detect the peak of a signal
+ * \ingroup block
+ *
+ * If a peak is detected, this block outputs a 1, 
+ * or it outputs 0's.  A separate debug output may be connected, to
+ * view the internal EWMA described below.
+ *
+ * \param threshold_factor_rise The threshold factor determins when a peak
+ *        is present. An EWMA average of the signal is calculated and when the 
+ *        value of the signal goes over threshold_factor_rise*average, we
+ *        call the peak.
+ * \param look_ahead The look-ahead value is used when the threshold is
+ *        found to locate the peak within this range.
+ * \param alpha The gain value of a single-pole moving average filter
+ */
+
+class gr_peak_detector2_fb : public gr_sync_block
+{
+  friend gr_peak_detector2_fb_sptr 
+  gr_make_peak_detector2_fb (float threshold_factor_rise, int look_ahead, 
float alpha);
+  
+  gr_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float 
alpha);
+  
+private:
+  float d_threshold_factor_rise;
+  int d_look_ahead;
+  int d_look_ahead_remaining;
+  int d_peak_ind;
+  float d_peak_val;
+  float d_alpha;
+  float d_avg;
+  bool d_found;
+  
+public:
+  
+  /*! \brief Set the threshold factor value for the rise time
+   *  \param thr new threshold factor
+   */
+  void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = 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_alpha = alpha; }
+  
+  /*! \brief Get the threshold factor value for the rise time
+   *  \return threshold factor
+   */
+  float threshold_factor_rise() { return d_threshold_factor_rise; }
+  
+  /*! \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_alpha; }
+  
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif
+
+

Added: 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.i
                            (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ofdm2/gnuradio-core/src/lib/general/gr_peak_detector2_fb.i
    2007-12-13 22:33:39 UTC (rev 7156)
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+GR_SWIG_BLOCK_MAGIC(gr,peak_detector2_fb)
+  
+  gr_peak_detector2_fb_sptr gr_make_peak_detector2_fb (float 
threshold_factor_rise = 7,
+                                                      int look_ahead = 1000,
+                                                      float alpha=0.001);
+
+class gr_peak_detector2_fb : public gr_sync_block
+{
+private:
+  gr_peak_detector2_fb (float threshold_factor_rise, int look_ahead, float 
alpha);
+  
+public:
+  void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
+  void set_look_ahead(int look) { d_look_ahead = look; }
+  void set_alpha(int alpha) { d_avg_alpha = alpha; }
+  
+  float threshold_factor_rise() { return d_threshold_factor_rise; } 
+  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]