efficient moving average filters, should speed up OFDM significantly
authormatt <matt@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 21 Jul 2008 23:32:23 +0000 (23:32 +0000)
committermatt <matt@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 21 Jul 2008 23:32:23 +0000 (23:32 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8965 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/gengen/Makefile.am
gnuradio-core/src/lib/gengen/Makefile.gen
gnuradio-core/src/lib/gengen/generate_common.py
gnuradio-core/src/lib/gengen/gengen_generated.i
gnuradio-core/src/lib/gengen/gr_moving_average_XX.cc.t [new file with mode: 0644]
gnuradio-core/src/lib/gengen/gr_moving_average_XX.h.t [new file with mode: 0644]
gnuradio-core/src/lib/gengen/gr_moving_average_XX.i.t [new file with mode: 0644]

index fb96ed2be72f6c647c6e43808ab3d7773098c007..aaf9dd5fcda7cffddc8fbb4da57ab3a67582ae5f 100644 (file)
@@ -112,7 +112,10 @@ CODE_GENERATOR =                   \
        gr_or_XX.i.t                    \
        gr_not_XX.cc.t                  \
        gr_not_XX.h.t                   \
-       gr_not_XX.i.t
+       gr_not_XX.i.t                   \
+       gr_moving_average_XX.cc.t       \
+       gr_moving_average_XX.h.t        \
+       gr_moving_average_XX.i.t
 
 include Makefile.gen
 
index 79b0ef7bd2c8d17bb52dbd07345b032db0253ff1..7ee92a25a19acb15fed24423fb7b992f2a804768 100644 (file)
@@ -42,6 +42,10 @@ GENERATED_H = \
        gr_max_ff.h \
        gr_max_ii.h \
        gr_max_ss.h \
+       gr_moving_average_cc.h \
+       gr_moving_average_ff.h \
+       gr_moving_average_ii.h \
+       gr_moving_average_ss.h \
        gr_multiply_cc.h \
        gr_multiply_const_cc.h \
        gr_multiply_const_ff.h \
@@ -148,6 +152,10 @@ GENERATED_I = \
        gr_max_ff.i \
        gr_max_ii.i \
        gr_max_ss.i \
+       gr_moving_average_cc.i \
+       gr_moving_average_ff.i \
+       gr_moving_average_ii.i \
+       gr_moving_average_ss.i \
        gr_multiply_cc.i \
        gr_multiply_const_cc.i \
        gr_multiply_const_ff.i \
@@ -254,6 +262,10 @@ GENERATED_CC = \
        gr_max_ff.cc \
        gr_max_ii.cc \
        gr_max_ss.cc \
+       gr_moving_average_cc.cc \
+       gr_moving_average_ff.cc \
+       gr_moving_average_ii.cc \
+       gr_moving_average_ss.cc \
        gr_multiply_cc.cc \
        gr_multiply_const_cc.cc \
        gr_multiply_const_ff.cc \
index e46d4b74af3a18cdbe7690f5d835a7cc443e148a..182b74070edfcc80d4717b64a59537c972c56d92 100755 (executable)
@@ -52,6 +52,7 @@ reg_roots = [
     'gr_add_const_vXX',
     'gr_multiply_const_vXX',
     'gr_integrate_XX',
+    'gr_moving_average_XX',
     ]
 
 # other blocks
index bdc15e50cfef18589709bbd9478ab02958563db9..f1be17f7ab3993040ed72c34a527e8ce5b0686e1 100644 (file)
 #include <gr_max_ff.h>
 #include <gr_max_ii.h>
 #include <gr_max_ss.h>
+#include <gr_moving_average_cc.h>
+#include <gr_moving_average_ff.h>
+#include <gr_moving_average_ii.h>
+#include <gr_moving_average_ss.h>
 #include <gr_multiply_cc.h>
 #include <gr_multiply_const_cc.h>
 #include <gr_multiply_const_ff.h>
 %include <gr_max_ff.i>
 %include <gr_max_ii.i>
 %include <gr_max_ss.i>
+%include <gr_moving_average_cc.i>
+%include <gr_moving_average_ff.i>
+%include <gr_moving_average_ii.i>
+%include <gr_moving_average_ss.i>
 %include <gr_multiply_cc.i>
 %include <gr_multiply_const_cc.i>
 %include <gr_multiply_const_ff.i>
diff --git a/gnuradio-core/src/lib/gengen/gr_moving_average_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.cc.t
new file mode 100644 (file)
index 0000000..e5e9852
--- /dev/null
@@ -0,0 +1,74 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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@.h>
+#include <gr_io_signature.h>
+
+@SPTR_NAME@ 
+gr_make_@BASE_NAME@ (int length, @O_TYPE@ scale, int max_iter)
+{
+  return @SPTR_NAME@ (new @NAME@ (length, scale, max_iter));
+}
+
+@NAME@::@NAME@ (int length, @O_TYPE@ scale, int max_iter)
+  : gr_sync_block ("@BASE_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)
+{
+  set_history(length);
+}
+
+@NAME@::~@NAME@ ()
+{
+}
+
+int 
+@NAME@::work (int noutput_items,
+             gr_vector_const_void_star &input_items,
+             gr_vector_void_star &output_items)
+{
+  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;
+}
diff --git a/gnuradio-core/src/lib/gengen/gr_moving_average_XX.h.t b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.h.t
new file mode 100644 (file)
index 0000000..3121e3b
--- /dev/null
@@ -0,0 +1,61 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 <gr_sync_block.h>
+
+class @NAME@;
+
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ gr_make_@BASE_NAME@ (int length, @O_TYPE@ scale, int max_iter = 4096);
+
+/*!
+ * \brief output is the moving sum of the last N samples, scaled by the scale factor
+ * \ingroup filter.  max_iter limits how long we go without flushing the accumulator
+ * This is necessary to avoid numerical instability for float and complex.
+ *
+ */
+class @NAME@ : public gr_sync_block
+{
+private:
+  friend @SPTR_NAME@ gr_make_@BASE_NAME@(int length, @O_TYPE@ scale, int max_iter);
+
+  @NAME@ (int length, @O_TYPE@ scale, int max_iter = 4096);
+
+  int d_length;
+  @O_TYPE@ d_scale;
+  int d_max_iter;
+
+public:
+  ~@NAME@ ();  
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif /* @GUARD_NAME@ */
diff --git a/gnuradio-core/src/lib/gengen/gr_moving_average_XX.i.t b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.i.t
new file mode 100644 (file)
index 0000000..c7da8d9
--- /dev/null
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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@
+
+GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@);
+
+@SPTR_NAME@ gr_make_@BASE_NAME@ (int length, @O_TYPE@ scale, int max_iter=4096);
+
+class @NAME@ : public gr_sync_block
+{
+private:
+  @NAME@ ();
+};