From 5c8fcd7a45f2a32589ad87e1a14c8eed30bfd006 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 21 Jul 2008 23:32:23 +0000 Subject: [PATCH] efficient moving average filters, should speed up OFDM significantly git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8965 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/gengen/Makefile.am | 5 +- gnuradio-core/src/lib/gengen/Makefile.gen | 12 +++ .../src/lib/gengen/generate_common.py | 1 + .../src/lib/gengen/gengen_generated.i | 8 ++ .../src/lib/gengen/gr_moving_average_XX.cc.t | 74 +++++++++++++++++++ .../src/lib/gengen/gr_moving_average_XX.h.t | 61 +++++++++++++++ .../src/lib/gengen/gr_moving_average_XX.i.t | 33 +++++++++ 7 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 gnuradio-core/src/lib/gengen/gr_moving_average_XX.cc.t create mode 100644 gnuradio-core/src/lib/gengen/gr_moving_average_XX.h.t create mode 100644 gnuradio-core/src/lib/gengen/gr_moving_average_XX.i.t diff --git a/gnuradio-core/src/lib/gengen/Makefile.am b/gnuradio-core/src/lib/gengen/Makefile.am index fb96ed2b..aaf9dd5f 100644 --- a/gnuradio-core/src/lib/gengen/Makefile.am +++ b/gnuradio-core/src/lib/gengen/Makefile.am @@ -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 diff --git a/gnuradio-core/src/lib/gengen/Makefile.gen b/gnuradio-core/src/lib/gengen/Makefile.gen index 79b0ef7b..7ee92a25 100644 --- a/gnuradio-core/src/lib/gengen/Makefile.gen +++ b/gnuradio-core/src/lib/gengen/Makefile.gen @@ -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 \ diff --git a/gnuradio-core/src/lib/gengen/generate_common.py b/gnuradio-core/src/lib/gengen/generate_common.py index e46d4b74..182b7407 100755 --- a/gnuradio-core/src/lib/gengen/generate_common.py +++ b/gnuradio-core/src/lib/gengen/generate_common.py @@ -52,6 +52,7 @@ reg_roots = [ 'gr_add_const_vXX', 'gr_multiply_const_vXX', 'gr_integrate_XX', + 'gr_moving_average_XX', ] # other blocks diff --git a/gnuradio-core/src/lib/gengen/gengen_generated.i b/gnuradio-core/src/lib/gengen/gengen_generated.i index bdc15e50..f1be17f7 100644 --- a/gnuradio-core/src/lib/gengen/gengen_generated.i +++ b/gnuradio-core/src/lib/gengen/gengen_generated.i @@ -42,6 +42,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -148,6 +152,10 @@ %include %include %include +%include +%include +%include +%include %include %include %include 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 index 00000000..e5e98523 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.cc.t @@ -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 + +@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 index 00000000..3121e3bf --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.h.t @@ -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 + +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 index 00000000..c7da8d94 --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_moving_average_XX.i.t @@ -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@ (); +}; -- 2.30.2