Adds gr.integrate_XX for ss, ii, ff, and cc. Sums successive samples and decimates...
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 12 Apr 2008 17:42:20 +0000 (17:42 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 12 Apr 2008 17:42:20 +0000 (17:42 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8190 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_integrate_XX.cc.t [new file with mode: 0644]
gnuradio-core/src/lib/gengen/gr_integrate_XX.h.t [new file with mode: 0644]
gnuradio-core/src/lib/gengen/gr_integrate_XX.i.t [new file with mode: 0644]
gnuradio-core/src/python/gnuradio/gr/qa_integrate.py [new file with mode: 0755]

index ebc403e3f79a0e26c4745b88214c269b0bfbff72..fb96ed2be72f6c647c6e43808ab3d7773098c007 100644 (file)
@@ -53,6 +53,9 @@ CODE_GENERATOR =                      \
        gr_divide_XX.cc.t               \
        gr_divide_XX.h.t                \
        gr_divide_XX.i.t                \
+       gr_integrate_XX.cc.t            \
+       gr_integrate_XX.h.t             \
+       gr_integrate_XX.i.t             \
        gr_max_XX.cc.t                  \
        gr_max_XX.h.t                   \
        gr_max_XX.i.t                   \
index 512576ac284622b6e0b2318cdf7e1d2073b9500b..79b0ef7bd2c8d17bb52dbd07345b032db0253ff1 100644 (file)
@@ -35,6 +35,10 @@ GENERATED_H = \
        gr_divide_ff.h \
        gr_divide_ii.h \
        gr_divide_ss.h \
+       gr_integrate_cc.h \
+       gr_integrate_ff.h \
+       gr_integrate_ii.h \
+       gr_integrate_ss.h \
        gr_max_ff.h \
        gr_max_ii.h \
        gr_max_ss.h \
@@ -137,6 +141,10 @@ GENERATED_I = \
        gr_divide_ff.i \
        gr_divide_ii.i \
        gr_divide_ss.i \
+       gr_integrate_cc.i \
+       gr_integrate_ff.i \
+       gr_integrate_ii.i \
+       gr_integrate_ss.i \
        gr_max_ff.i \
        gr_max_ii.i \
        gr_max_ss.i \
@@ -239,6 +247,10 @@ GENERATED_CC = \
        gr_divide_ff.cc \
        gr_divide_ii.cc \
        gr_divide_ss.cc \
+       gr_integrate_cc.cc \
+       gr_integrate_ff.cc \
+       gr_integrate_ii.cc \
+       gr_integrate_ss.cc \
        gr_max_ff.cc \
        gr_max_ii.cc \
        gr_max_ss.cc \
index 089d7d3804f384822004de3781e474bab6f8e002..e46d4b74af3a18cdbe7690f5d835a7cc443e148a 100755 (executable)
@@ -51,6 +51,7 @@ reg_roots = [
     'gr_multiply_vXX',
     'gr_add_const_vXX',
     'gr_multiply_const_vXX',
+    'gr_integrate_XX',
     ]
 
 # other blocks
index a4de58dbe34bcd8384a66be833957615af0b62e3..bdc15e50cfef18589709bbd9478ab02958563db9 100644 (file)
 #include <gr_divide_ff.h>
 #include <gr_divide_ii.h>
 #include <gr_divide_ss.h>
+#include <gr_integrate_cc.h>
+#include <gr_integrate_ff.h>
+#include <gr_integrate_ii.h>
+#include <gr_integrate_ss.h>
 #include <gr_max_ff.h>
 #include <gr_max_ii.h>
 #include <gr_max_ss.h>
 %include <gr_divide_ff.i>
 %include <gr_divide_ii.i>
 %include <gr_divide_ss.i>
+%include <gr_integrate_cc.i>
+%include <gr_integrate_ff.i>
+%include <gr_integrate_ii.i>
+%include <gr_integrate_ss.i>
 %include <gr_max_ff.i>
 %include <gr_max_ii.i>
 %include <gr_max_ss.i>
diff --git a/gnuradio-core/src/lib/gengen/gr_integrate_XX.cc.t b/gnuradio-core/src/lib/gengen/gr_integrate_XX.cc.t
new file mode 100644 (file)
index 0000000..0a62554
--- /dev/null
@@ -0,0 +1,67 @@
+/* -*- 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 decim)
+{
+  return @SPTR_NAME@ (new @NAME@ (decim));
+}
+
+@NAME@::@NAME@ (int decim)
+  : gr_sync_decimator ("@BASE_NAME@",
+                      gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
+                      gr_make_io_signature (1, 1, sizeof (@O_TYPE@)),
+                      decim),
+    d_decim(decim),
+    d_count(0)
+{
+}
+
+@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];
+  
+  for (int i = 0; i < noutput_items; i++) {
+    out[i] = (@O_TYPE@)0;
+    for (int j = 0; j < d_decim; j++)
+      out[i] += in[i*d_decim+j];
+  }
+
+  return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/gengen/gr_integrate_XX.h.t b/gnuradio-core/src/lib/gengen/gr_integrate_XX.h.t
new file mode 100644 (file)
index 0000000..c8eca2d
--- /dev/null
@@ -0,0 +1,60 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <gr_sync_decimator.h>
+
+class @NAME@;
+
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ gr_make_@BASE_NAME@ (int decim);
+
+/*!
+ * \brief output = sum(input[0]...input[n])
+ * \ingroup math
+ *
+ * Integrate successive samples in input stream and decimate
+ */
+class @NAME@ : public gr_sync_decimator
+{
+private:
+  friend @SPTR_NAME@ gr_make_@BASE_NAME@(int decim);
+
+  @NAME@ (int decim);
+
+  int d_decim;
+  int d_count;
+
+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_integrate_XX.i.t b/gnuradio-core/src/lib/gengen/gr_integrate_XX.i.t
new file mode 100644 (file)
index 0000000..24a2381
--- /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 decim);
+
+class @NAME@ : public gr_sync_decimator
+{
+private:
+  @NAME@ ();
+};
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_integrate.py b/gnuradio-core/src/python/gnuradio/gr/qa_integrate.py
new file mode 100755 (executable)
index 0000000..fbd601e
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+#
+# 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.
+# 
+
+from gnuradio import gr, gr_unittest
+import math
+
+class test_integrate (gr_unittest.TestCase):
+
+    def setUp (self):
+        self.tb = gr.top_block ()
+
+    def tearDown (self):
+        self.tb = None
+
+    def test_000_ss(self):
+       src_data = (1, 2, 3, 4, 5, 6)
+       dst_data = (6, 15)
+       src = gr.vector_source_s(src_data)
+       itg = gr.integrate_ss(3)
+       dst = gr.vector_sink_s()
+       self.tb.connect(src, itg, dst)
+       self.tb.run()
+       self.assertEqual(dst_data, dst.data())
+       
+    def test_001_ii(self):
+       src_data = (1, 2, 3, 4, 5, 6)
+       dst_data = (6, 15)
+       src = gr.vector_source_i(src_data)
+       itg = gr.integrate_ii(3)
+       dst = gr.vector_sink_i()
+       self.tb.connect(src, itg, dst)
+       self.tb.run()
+       self.assertEqual(dst_data, dst.data())
+       
+    def test_002_ff(self):
+       src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
+       dst_data = [6.0, 15.0]
+       src = gr.vector_source_f(src_data)
+       itg = gr.integrate_ff(3)
+       dst = gr.vector_sink_f()
+       self.tb.connect(src, itg, dst)
+       self.tb.run()
+       self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6)      
+
+    def test_003_cc(self):
+       src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j]
+       dst_data = [6.0+6.0j, 15.0+15.0j]
+       src = gr.vector_source_c(src_data)
+       itg = gr.integrate_cc(3)
+       dst = gr.vector_sink_c()
+       self.tb.connect(src, itg, dst)
+       self.tb.run()
+       self.assertComplexTuplesAlmostEqual(dst_data, dst.data(), 6)    
+
+if __name__ == '__main__':
+    gr_unittest.main ()