From 520626bcc203a15ec22ed7351204662a33a17ef5 Mon Sep 17 00:00:00 2001
From: Tom Rondeau <trondeau@vt.edu>
Date: Wed, 6 Mar 2013 09:54:14 -0500
Subject: blocks: moving message blocks to gr-blocks.

message_burst_source, message_source, message_sink, message_debug, message_strobe.
---
 gr-blocks/include/blocks/CMakeLists.txt | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'gr-blocks/include/blocks/CMakeLists.txt')

diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 585810864a..66cdbf41c5 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -125,6 +125,11 @@ install(FILES
     interleaved_short_to_complex.h
     keep_m_in_n.h
     keep_one_in_n.h
+    message_debug.h
+    message_sink.h
+    message_source.h
+    message_strobe.h
+    message_burst_source.h
     multiply_cc.h
     multiply_ff.h
     multiply_conjugate_cc.h
-- 
cgit v1.2.3


From 9cfd03bd98693e62c6898f18d90d5d08f4d5c102 Mon Sep 17 00:00:00 2001
From: Tom Rondeau <trondeau@vt.edu>
Date: Wed, 6 Mar 2013 11:46:57 -0500
Subject: blocks: moving peak_detector and moving_average to gr-blocks.

---
 gr-blocks/grc/blocks_block_tree.xml            |   2 +
 gr-blocks/grc/blocks_moving_average_xx.xml     |  68 ++++++++++++++
 gr-blocks/grc/blocks_peak_detector_xb.xml      |  68 ++++++++++++++
 gr-blocks/include/blocks/CMakeLists.txt        |   2 +
 gr-blocks/include/blocks/moving_average_XX.h.t |  84 +++++++++++++++++
 gr-blocks/include/blocks/peak_detector_XX.h.t  | 117 ++++++++++++++++++++++++
 gr-blocks/lib/CMakeLists.txt                   |   2 +
 gr-blocks/lib/moving_average_XX_impl.cc.t      | 114 +++++++++++++++++++++++
 gr-blocks/lib/moving_average_XX_impl.h.t       |  65 +++++++++++++
 gr-blocks/lib/peak_detector_XX_impl.cc.t       | 122 +++++++++++++++++++++++++
 gr-blocks/lib/peak_detector_XX_impl.h.t        |  66 +++++++++++++
 gr-blocks/python/qa_moving_average.py          |  91 ++++++++++++++++++
 gr-blocks/python/qa_peak_detector.py           |  98 ++++++++++++++++++++
 gr-blocks/python/qa_peak_detector2.py          |   1 -
 gr-blocks/swig/blocks_swig.i                   |  21 +++++
 15 files changed, 920 insertions(+), 1 deletion(-)
 create mode 100644 gr-blocks/grc/blocks_moving_average_xx.xml
 create mode 100644 gr-blocks/grc/blocks_peak_detector_xb.xml
 create mode 100644 gr-blocks/include/blocks/moving_average_XX.h.t
 create mode 100644 gr-blocks/include/blocks/peak_detector_XX.h.t
 create mode 100644 gr-blocks/lib/moving_average_XX_impl.cc.t
 create mode 100644 gr-blocks/lib/moving_average_XX_impl.h.t
 create mode 100644 gr-blocks/lib/peak_detector_XX_impl.cc.t
 create mode 100644 gr-blocks/lib/peak_detector_XX_impl.h.t
 create mode 100644 gr-blocks/python/qa_moving_average.py
 create mode 100644 gr-blocks/python/qa_peak_detector.py

(limited to 'gr-blocks/include/blocks/CMakeLists.txt')

diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 27d4a616c6..e5db82115b 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -104,6 +104,7 @@
 		<block>blocks_streams_to_vector</block>
 		<block>blocks_vector_to_stream</block>
 		<block>blocks_vector_to_streams</block>
+		<block>blocks_peak_detector_xb</block>
 		<block>blocks_peak_detector2_fb</block>
 		<block>blocks_regenerate_bb</block>
 		<block>blocks_stretch_ff</block>
@@ -129,6 +130,7 @@
 	        <name>Level Controls (New)</name>
 		<block>blocks_mute_xx</block>
 		<block>blocks_sample_and_hold_xx</block>
+                <block>blocks_moving_average_xx</block>
 	</cat>
 	<cat>
 	        <name>Probes (New)</name>
diff --git a/gr-blocks/grc/blocks_moving_average_xx.xml b/gr-blocks/grc/blocks_moving_average_xx.xml
new file mode 100644
index 0000000000..e90903ad85
--- /dev/null
+++ b/gr-blocks/grc/blocks_moving_average_xx.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Moving Average
+###################################################
+ -->
+<block>
+	<name>Moving Average</name>
+	<key>blocks_moving_average_xx</key>
+	<import>from gnuradio import blocks</import>
+	<make>blocks.moving_average_$(type.fcn)($length, $scale, $max_iter)</make>
+	<callback>set_length_and_scale($length, $scale)</callback>
+	<param>
+		<name>Type</name>
+		<key>type</key>
+		<type>enum</type>
+		<option>
+			<name>Complex</name>
+			<key>complex</key>
+			<opt>fcn:cc</opt>
+			<opt>scale:complex</opt>
+		</option>
+		<option>
+			<name>Float</name>
+			<key>float</key>
+			<opt>fcn:ff</opt>
+			<opt>scale:real</opt>
+		</option>
+		<option>
+			<name>Int</name>
+			<key>int</key>
+			<opt>fcn:ii</opt>
+			<opt>scale:int</opt>
+		</option>
+		<option>
+			<name>Short</name>
+			<key>short</key>
+			<opt>fcn:ss</opt>
+			<opt>scale:int</opt>
+		</option>
+	</param>
+	<param>
+		<name>Length</name>
+		<key>length</key>
+		<value>1000</value>
+		<type>int</type>
+	</param>
+	<param>
+		<name>Scale</name>
+		<key>scale</key>
+		<value>1</value>
+		<type>$type.scale</type>
+	</param>
+	<param>
+		<name>Max Iter</name>
+		<key>max_iter</key>
+		<value>4000</value>
+		<type>int</type>
+	</param>
+	<sink>
+		<name>in</name>
+		<type>$type</type>
+	</sink>
+	<source>
+		<name>out</name>
+		<type>$type</type>
+	</source>
+</block>
diff --git a/gr-blocks/grc/blocks_peak_detector_xb.xml b/gr-blocks/grc/blocks_peak_detector_xb.xml
new file mode 100644
index 0000000000..1aabf89474
--- /dev/null
+++ b/gr-blocks/grc/blocks_peak_detector_xb.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Peak Detector
+###################################################
+ -->
+<block>
+	<name>Peak Detector</name>
+	<key>blocks_peak_detector_xb</key>
+	<import>from gnuradio import blocks</import>
+	<make>blocks.peak_detector_$(type.fcn)b($threshold_factor_rise, $threshold_factor_fall, $look_ahead, $alpha)</make>
+	<callback>set_threshold_factor_rise($threshold_factor_rise)</callback>
+	<callback>set_threshold_factor_fall($threshold_factor_fall)</callback>
+	<callback>set_look_ahead($look_ahead)</callback>
+	<callback>set_alpha($alpha)</callback>
+	<param>
+		<name>Input Type</name>
+		<key>type</key>
+		<type>enum</type>
+		<option>
+			<name>Float</name>
+			<key>float</key>
+			<opt>fcn:f</opt>
+		</option>
+		<option>
+			<name>Int</name>
+			<key>int</key>
+			<opt>fcn:i</opt>
+		</option>
+		<option>
+			<name>Short</name>
+			<key>short</key>
+			<opt>fcn:s</opt>
+		</option>
+	</param>
+	<param>
+		<name>TH Factor Rise</name>
+		<key>threshold_factor_rise</key>
+		<value>0.25</value>
+		<type>real</type>
+	</param>
+	<param>
+		<name>TH Factor Fall</name>
+		<key>threshold_factor_fall</key>
+		<value>0.40</value>
+		<type>real</type>
+	</param>
+	<param>
+		<name>Look Ahead</name>
+		<key>look_ahead</key>
+		<value>10</value>
+		<type>int</type>
+	</param>
+	<param>
+		<name>Alpha</name>
+		<key>alpha</key>
+		<value>0.001</value>
+		<type>real</type>
+	</param>
+	<sink>
+		<name>in</name>
+		<type>$type</type>
+	</sink>
+	<source>
+		<name>out</name>
+		<type>byte</type>
+	</source>
+</block>
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 66cdbf41c5..a223731cb0 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -73,12 +73,14 @@ expand_h(argmax_XX          fs is ss)
 expand_h(divide_XX          ss ii ff cc)
 expand_h(integrate_XX       ss ii ff cc)
 expand_h(max_XX             ff ii ss)
+expand_h(moving_average_XX  ss ii ff cc)
 expand_h(multiply_XX        ss ii)
 expand_h(multiply_const_XX  ss ii)
 expand_h(multiply_const_vXX ss ii ff cc)
 expand_h(mute_XX            ss ii ff cc)
 expand_h(not_XX             bb ss ii)
 expand_h(or_XX              bb ss ii)
+expand_h(peak_detector_XX   fb ib sb)
 expand_h(probe_signal_X     b s i f c)
 expand_h(probe_signal_vX    b s i f c)
 expand_h(sample_and_hold_XX bb ss ii ff)
diff --git a/gr-blocks/include/blocks/moving_average_XX.h.t b/gr-blocks/include/blocks/moving_average_XX.h.t
new file mode 100644
index 0000000000..6b7883fdd4
--- /dev/null
+++ b/gr-blocks/include/blocks/moving_average_XX.h.t
@@ -0,0 +1,84 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief output is the moving sum of the last N samples, scaled by the scale factor
+     * \ingroup filter_blk
+     */
+    class BLOCKS_API @NAME@ : virtual public gr_sync_block
+    {
+    public: 
+      // gr::blocks::@NAME@::sptr
+      typedef boost::shared_ptr<@NAME@> sptr;
+
+      /*!
+       * Create a moving average block.
+       *
+       * \param length Number of samples to use in the average.
+       * \param scale scale factor for the result.
+       * \param max_iter limits how long we go without flushing the accumulator
+       *        This is necessary to avoid numerical instability for float and complex.
+       */
+      static sptr make(int length, @O_TYPE@ scale,
+                       int max_iter = 4096);
+
+      /*!
+       * Get the length used in the avaraging calculation.
+       */
+      virtual int length() const = 0;
+
+      /*!
+       * Get the scale factor being used.
+       */
+      virtual @O_TYPE@ scale() const = 0;
+
+      /*!
+       * Set both the length and the scale factor together.
+       */
+      virtual void set_length_and_scale(int length, @O_TYPE@ scale) = 0;
+
+      /*!
+       * Set the length.
+       */
+      virtual void set_length(int length) = 0;
+
+      /*!
+       * Set the scale factor.
+       */
+      virtual void set_scale(@O_TYPE@ scale) = 0;
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/peak_detector_XX.h.t b/gr-blocks/include/blocks/peak_detector_XX.h.t
new file mode 100644
index 0000000000..1c8ba0652f
--- /dev/null
+++ b/gr-blocks/include/blocks/peak_detector_XX.h.t
@@ -0,0 +1,117 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief Detect the peak of a signal
+     * \ingroup level_blk
+     *
+     * If a peak is detected, this block outputs a 1,
+     * or it outputs 0's.
+     */
+    class GR_CORE_API @NAME@ : virtual public gr_sync_block
+    {
+    public:
+      // gr::blocks::@NAME@::sptr
+      typedef boost::shared_ptr<@NAME@> sptr;
+
+      /*!
+       * Make a peak detector block.
+       *
+       * \param threshold_factor_rise 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_rise*average, we start looking for a
+       *        peak.
+       * \param threshold_factor_fall The threshold factor determins
+       *        when a peak has ended. An average of the signal is
+       *        calculated and when the value of the signal goes
+       *        bellow threshold_factor_fall*average, we stop 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.
+       * \param alpha The gain value of a moving average filter
+       */
+      static sptr make(float threshold_factor_rise = 0.25,
+                       float threshold_factor_fall = 0.40,
+                       int look_ahead = 10,
+                       float alpha = 0.001);
+
+      /*! \brief Set the threshold factor value for the rise time
+       *  \param thr new threshold factor
+       */
+      virtual void set_threshold_factor_rise(float thr) = 0;
+
+      /*! \brief Set the threshold factor value for the fall time
+       *  \param thr new threshold factor
+       */
+      virtual void set_threshold_factor_fall(float thr) = 0;
+
+      /*! \brief Set the look-ahead factor
+       *  \param look new look-ahead factor
+       */
+      virtual void set_look_ahead(int look) = 0;
+      
+      /*! \brief Set the running average alpha
+       *  \param alpha new alpha for running average
+       */
+      virtual void set_alpha(int alpha) = 0;
+
+      /*! \brief Get the threshold factor value for the rise time
+       *  \return threshold factor
+       */
+      virtual float threshold_factor_rise() = 0;
+
+      /*! \brief Get the threshold factor value for the fall time
+       *  \return threshold factor
+       */
+      virtual float threshold_factor_fall() = 0;
+
+      /*! \brief Get the look-ahead factor value
+       *  \return look-ahead factor
+       */
+      virtual int look_ahead() = 0;
+
+      /*! \brief Get the alpha value of the running average
+       *  \return alpha
+       */
+      virtual float alpha() = 0;
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 67e56fa319..c575f4215e 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -99,12 +99,14 @@ expand_cc_h_impl(argmax_XX          fs is ss)
 expand_cc_h_impl(divide_XX          ss ii ff cc)
 expand_cc_h_impl(integrate_XX       ss ii ff cc)
 expand_cc_h_impl(max_XX             ff ii ss)
+expand_cc_h_impl(moving_average_XX  ss ii ff cc)
 expand_cc_h_impl(multiply_XX        ss ii)
 expand_cc_h_impl(multiply_const_XX  ss ii)
 expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
 expand_cc_h_impl(mute_XX            ss ii ff cc)
 expand_cc_h_impl(not_XX             bb ss ii)
 expand_cc_h_impl(or_XX              bb ss ii)
+expand_cc_h_impl(peak_detector_XX   fb ib sb)
 expand_cc_h_impl(probe_signal_X     b s i f c)
 expand_cc_h_impl(probe_signal_vX    b s i f c)
 expand_cc_h_impl(sample_and_hold_XX bb ss ii ff)
diff --git a/gr-blocks/lib/moving_average_XX_impl.cc.t b/gr-blocks/lib/moving_average_XX_impl.cc.t
new file mode 100644
index 0000000000..566deff116
--- /dev/null
+++ b/gr-blocks/lib/moving_average_XX_impl.cc.t
@@ -0,0 +1,114 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2010,2013 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "@NAME_IMPL@.h"
+#include <gr_io_signature.h>
+
+namespace gr {
+  namespace blocks {
+
+    @NAME@::sptr
+    @NAME@::make(int length, @O_TYPE@ scale, int max_iter)
+    {
+      return gnuradio::get_initial_sptr
+        (new @NAME_IMPL@(length, scale, max_iter));
+    }
+
+    @NAME_IMPL@::@NAME_IMPL@(int length, @O_TYPE@ scale, int max_iter)
+    : gr_sync_block("@NAME@",
+                    gr_make_io_signature(1, 1, sizeof(@I_TYPE@)),
+                    gr_make_io_signature(1, 1, sizeof(@O_TYPE@))),
+      d_length(length),
+      d_scale(scale),
+      d_max_iter(max_iter),
+      d_new_length(length),
+      d_new_scale(scale),
+      d_updated(false)
+    {
+      set_history(length);
+    }
+
+    @NAME_IMPL@::~@NAME_IMPL@()
+    {
+    }
+
+    void
+    @NAME_IMPL@::set_length_and_scale(int length, @O_TYPE@ scale)
+    {
+      d_new_length = length;
+      d_new_scale = scale;
+      d_updated = true;
+    }
+
+    void
+    @NAME_IMPL@::set_length(int length)
+    {
+      d_new_length = length;
+      d_updated = true;
+    }
+
+    void
+    @NAME_IMPL@::set_scale(@O_TYPE@ scale)
+    {
+      d_new_scale = scale;
+      d_updated = true;
+    }
+
+    int
+    @NAME_IMPL@::work(int noutput_items,
+                      gr_vector_const_void_star &input_items,
+                      gr_vector_void_star &output_items)
+    {
+      if(d_updated) {
+        d_length = d_new_length;
+        d_scale = d_new_scale;
+        set_history(d_length);
+        d_updated = false;
+        return 0; // history requirements might have changed
+      }
+
+      const @I_TYPE@ *in = (const @I_TYPE@ *)input_items[0];
+      @O_TYPE@ *out = (@O_TYPE@ *)output_items[0];
+
+      @I_TYPE@ sum = 0;
+      int num_iter = (noutput_items>d_max_iter) ? d_max_iter : noutput_items;
+      for(int i = 0; i < d_length-1; i++) {
+        sum += in[i];
+      }
+
+      for(int i = 0; i < num_iter; i++) {
+        sum += in[i+d_length-1];
+        out[i] = sum * d_scale;
+        sum -= in[i];
+      }
+
+      return num_iter;
+    }
+
+  } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/moving_average_XX_impl.h.t b/gr-blocks/lib/moving_average_XX_impl.h.t
new file mode 100644
index 0000000000..7234cbe139
--- /dev/null
+++ b/gr-blocks/lib/moving_average_XX_impl.h.t
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include <blocks/@NAME@.h>
+
+namespace gr {
+  namespace blocks {
+
+    class @NAME_IMPL@ : public @NAME@
+    {
+    private:
+      int d_length;
+      @O_TYPE@ d_scale;
+      int d_max_iter;
+
+      int d_new_length;
+      @O_TYPE@ d_new_scale;
+      bool d_updated;
+
+    public:
+      @NAME_IMPL@(int length, @O_TYPE@ scale,
+                  int max_iter = 4096);
+      ~@NAME_IMPL@();
+
+      int length() const { return d_new_length; }
+      @O_TYPE@ scale() const { return d_new_scale; }
+
+      void set_length_and_scale(int length, @O_TYPE@ scale);
+      void set_length(int length);
+      void set_scale(@O_TYPE@ scale);
+
+      int work(int noutput_items,
+               gr_vector_const_void_star &input_items,
+               gr_vector_void_star &output_items);
+
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/peak_detector_XX_impl.cc.t b/gr-blocks/lib/peak_detector_XX_impl.cc.t
new file mode 100644
index 0000000000..27518962f5
--- /dev/null
+++ b/gr-blocks/lib/peak_detector_XX_impl.cc.t
@@ -0,0 +1,122 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2010,2013 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "@NAME_IMPL@.h"
+#include <gr_io_signature.h>
+#include <string.h>
+
+namespace gr {
+  namespace blocks {
+
+    @NAME@::sptr
+    @NAME@::make(float threshold_factor_rise,
+                 float threshold_factor_fall,
+                 int look_ahead, float alpha)
+    {
+      return gnuradio::get_initial_sptr
+        (new @NAME_IMPL@(threshold_factor_rise,
+                         threshold_factor_fall,
+                         look_ahead, alpha));
+    }
+
+    @NAME_IMPL@::@NAME_IMPL@(float threshold_factor_rise,
+                             float threshold_factor_fall,
+                             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(char))),
+      d_threshold_factor_rise(threshold_factor_rise),
+      d_threshold_factor_fall(threshold_factor_fall),
+      d_look_ahead(look_ahead), d_avg_alpha(alpha), d_avg(0), d_found(0)
+    {
+    }
+
+    @NAME_IMPL@::~@NAME_IMPL@()
+    {
+    }
+
+    int
+    @NAME_IMPL@::work(int noutput_items,
+                      gr_vector_const_void_star &input_items,
+                      gr_vector_void_star &output_items)
+    {
+      @I_TYPE@ *iptr = (@I_TYPE@*)input_items[0];
+      char *optr = (char*)output_items[0];
+
+      memset(optr, 0, noutput_items*sizeof(char));
+
+      @I_TYPE@ peak_val = -(@I_TYPE@)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_rise) {
+            state = 1;
+          }
+          else {
+            d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+            i++;
+          }
+        }
+        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_fall) {
+            d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg;
+            i++;
+          }
+          else {
+            optr[peak_ind] = 1;
+            state = 0;
+            peak_val = -(@I_TYPE@)INFINITY;
+            //printf("Leaving  State 1: Peak: %f  Peak Ind: %d   i: %d  noutput_items: %d\n",
+            //peak_val, peak_ind, i, noutput_items);
+          }
+        }
+      }
+
+      if(state == 0) {
+        //printf("Leave in State 0, produced %d\n",noutput_items);
+        return noutput_items;
+      }
+      else {   // 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+1;
+      }
+    }
+
+  } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/peak_detector_XX_impl.h.t b/gr-blocks/lib/peak_detector_XX_impl.h.t
new file mode 100644
index 0000000000..ef52f0f744
--- /dev/null
+++ b/gr-blocks/lib/peak_detector_XX_impl.h.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include <blocks/@NAME@.h>
+
+namespace gr {
+  namespace blocks {
+
+    class @NAME_IMPL@ : public @NAME@
+    {
+    private:
+      float d_threshold_factor_rise;
+      float d_threshold_factor_fall;
+      int d_look_ahead;
+      float d_avg_alpha;
+      float d_avg;
+      unsigned char d_found;
+
+    public:
+      @NAME_IMPL@(float threshold_factor_rise,
+                  float threshold_factor_fall,
+                  int look_ahead, float alpha);
+      ~@NAME_IMPL@();
+
+      void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
+      void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = 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; }
+      float threshold_factor_fall() { return d_threshold_factor_fall; }
+      int look_ahead() { return d_look_ahead; }
+      float alpha() { return d_avg_alpha; }
+
+      int work(int noutput_items,
+               gr_vector_const_void_star &input_items,
+               gr_vector_void_star &output_items);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_moving_average.py b/gr-blocks/python/qa_moving_average.py
new file mode 100644
index 0000000000..169b4746c2
--- /dev/null
+++ b/gr-blocks/python/qa_moving_average.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig as blocks
+import math, random
+
+def make_random_complex_tuple(L, scale=1):
+    result = []
+    for x in range(L):
+        result.append(scale*complex(2*random.random()-1,
+                                    2*random.random()-1))
+    return tuple(result)
+
+def make_random_float_tuple(L, scale=1):
+    result = []
+    for x in range(L):
+        result.append(scale*(2*random.random()-1))
+    return tuple(result)
+
+class test_moving_average(gr_unittest.TestCase):
+
+    def setUp(self):
+        self.tb = gr.top_block()
+
+    def tearDown(self):
+        self.tb = None
+
+    def test_01(self):
+        tb = self.tb
+
+        N = 10000
+        seed = 0
+        data = make_random_float_tuple(N, 1)
+        expected_result = N*[0,]
+
+        src = gr.vector_source_f(data, False)
+        op  = blocks.moving_average_ff(100, 0.001)
+        dst = gr.vector_sink_f()
+
+        tb.connect(src, op)
+        tb.connect(op, dst)
+        tb.run()
+
+        dst_data = dst.data()
+
+        # make sure result is close to zero
+        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1)
+
+    def test_02(self):
+        tb = self.tb
+
+        N = 10000
+        seed = 0
+        data = make_random_complex_tuple(N, 1)
+        expected_result = N*[0,]
+
+        src = gr.vector_source_c(data, False)
+        op  = blocks.moving_average_cc(100, 0.001)
+        dst = gr.vector_sink_c()
+
+        tb.connect(src, op)
+        tb.connect(op, dst)
+        tb.run()
+
+        dst_data = dst.data()
+
+        # make sure result is close to zero
+        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
+
+if __name__ == '__main__':
+    gr_unittest.run(test_moving_average, "test_moving_average.xml")
diff --git a/gr-blocks/python/qa_peak_detector.py b/gr-blocks/python/qa_peak_detector.py
new file mode 100644
index 0000000000..c3ff2548c4
--- /dev/null
+++ b/gr-blocks/python/qa_peak_detector.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig as blocks
+
+class test_peak_detector(gr_unittest.TestCase):
+
+    def setUp(self):
+        self.tb = gr.top_block()
+
+    def tearDown(self):
+        self.tb = None
+
+    def test_01(self):
+        tb = self.tb
+
+        data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+
+        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+        src = gr.vector_source_f(data, False)
+        regen = blocks.peak_detector_fb()
+        dst = gr.vector_sink_b()
+
+        tb.connect(src, regen)
+        tb.connect(regen, dst)
+        tb.run()
+
+        dst_data = dst.data()
+
+        self.assertEqual(expected_result, dst_data)
+
+    def test_02(self):
+        tb = self.tb
+
+        data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+
+        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+        src = gr.vector_source_i(data, False)
+        regen = blocks.peak_detector_ib()
+        dst = gr.vector_sink_b()
+
+        tb.connect(src, regen)
+        tb.connect(regen, dst)
+        tb.run()
+
+        dst_data = dst.data()
+
+        self.assertEqual(expected_result, dst_data)
+
+    def test_03(self):
+        tb = self.tb
+
+        data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+
+        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+        src = gr.vector_source_s(data, False)
+        regen = blocks.peak_detector_sb()
+        dst = gr.vector_sink_b()
+
+        tb.connect(src, regen)
+        tb.connect(regen, dst)
+        tb.run()
+
+        dst_data = dst.data()
+
+        self.assertEqual(expected_result, dst_data)
+
+if __name__ == '__main__':
+    gr_unittest.run(test_peak_detector, "test_peak_detector.xml")
diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py
index 4b864e4d70..b2d8e318dd 100644
--- a/gr-blocks/python/qa_peak_detector2.py
+++ b/gr-blocks/python/qa_peak_detector2.py
@@ -50,7 +50,6 @@ class test_peak_detector2(gr_unittest.TestCase):
         tb.run()
 
         dst_data = dst.data()
-        print dst_data
 
         self.assertEqual(expected_result, dst_data)
 
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 759b44f121..bd34351b95 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -93,6 +93,10 @@
 #include "blocks/message_source.h"
 #include "blocks/message_strobe.h"
 #include "blocks/message_burst_source.h"
+#include "blocks/moving_average_cc.h"
+#include "blocks/moving_average_ff.h"
+#include "blocks/moving_average_ii.h"
+#include "blocks/moving_average_ss.h"
 #include "blocks/multiply_ss.h"
 #include "blocks/multiply_ii.h"
 #include "blocks/multiply_ff.h"
@@ -120,6 +124,9 @@
 #include "blocks/packed_to_unpacked_ss.h"
 #include "blocks/packed_to_unpacked_ii.h"
 #include "blocks/pdu_to_tagged_stream.h"
+#include "blocks/peak_detector_fb.h"
+#include "blocks/peak_detector_ib.h"
+#include "blocks/peak_detector_sb.h"
 #include "blocks/peak_detector2_fb.h"
 #include "blocks/probe_signal_b.h"
 #include "blocks/probe_signal_s.h"
@@ -234,6 +241,10 @@
 %include "blocks/message_source.h"
 %include "blocks/message_strobe.h"
 %include "blocks/message_burst_source.h"
+%include "blocks/moving_average_cc.h"
+%include "blocks/moving_average_ff.h"
+%include "blocks/moving_average_ii.h"
+%include "blocks/moving_average_ss.h"
 %include "blocks/multiply_ss.h"
 %include "blocks/multiply_ii.h"
 %include "blocks/multiply_ff.h"
@@ -274,6 +285,9 @@
 %include "blocks/packed_to_unpacked_ii.h"
 %include "blocks/patterned_interleaver.h"
 %include "blocks/pdu_to_tagged_stream.h"
+%include "blocks/peak_detector_fb.h"
+%include "blocks/peak_detector_ib.h"
+%include "blocks/peak_detector_sb.h"
 %include "blocks/peak_detector2_fb.h"
 %include "blocks/regenerate_bb.h"
 %include "blocks/repeat.h"
@@ -374,6 +388,10 @@ GR_SWIG_BLOCK_MAGIC2(blocks, message_sink);
 GR_SWIG_BLOCK_MAGIC2(blocks, message_source);
 GR_SWIG_BLOCK_MAGIC2(blocks, message_strobe);
 GR_SWIG_BLOCK_MAGIC2(blocks, message_burst_source);
+GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, moving_average_ss);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
@@ -400,6 +418,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, pack_k_bits_bb);
 GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb);
 GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss);
 GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_fb);
+GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_ib);
+GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_sb);
 GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector2_fb);
 GR_SWIG_BLOCK_MAGIC2(blocks, pdu_to_tagged_stream);
 GR_SWIG_BLOCK_MAGIC2(blocks, or_bb);
-- 
cgit v1.2.3