[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnuradio-patch
Subject:    [Patch-gnuradio] gr_max_XX block
From:       "Trond Danielsen" <trond.danielsen () gmail ! com>
Date:       2007-04-27 12:02:03
Message-ID: 409676c70704270502q55e35bf9i6819b54bf1e9f02e () mail ! gmail ! com
[Download RAW message or body]

gr_max_XX block that accepts an "unlimited" number of vector inputs
and returns the maximum value across all inputs.

-- 
Trond Danielsen

["gr_max.patch" (text/x-patch)]

Index: gr_max_XX.h.t
===================================================================
--- gr_max_XX.h.t	(revisjon 0)
+++ gr_max_XX.h.t	(revisjon 0)
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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@ ();
+
+
+class @NAME@ : public gr_sync_block
+{
+  friend @SPTR_NAME@ gr_make_@BASE_NAME@ ();
+
+  @NAME@ ();
+
+ public:
+
+  int work (int noutput_items,
+            gr_vector_const_void_star &input_items,
+            gr_vector_void_star &output_items);
+};
+
+
+#endif
Index: gr_max_XX.cc.t
===================================================================
--- gr_max_XX.cc.t	(revisjon 0)
+++ gr_max_XX.cc.t	(revisjon 0)
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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@ ( size_t nitems_per_block ) 
+{
+	return @SPTR_NAME@ ( new @NAME@(nitems_per_block));
+}
+
+@NAME@::@NAME@( size_t nitems_per_block) 
+	: gr_sync_block ( "@BASE_NAME@",
+                   gr_make_io_signature (1, -1, nitems_per_block*sizeof (@I_TYPE@)),
+                   gr_make_io_signature (1, 1, sizeof (@O_TYPE@)))
+{
+}
+
+@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;
+	@O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+	int nitems_per_block = input_signature()->sizeof_stream_item(0)/sizeof(@I_TYPE@);
+	int ninputs = input_items.size ();
+	
+	for (int i=0; i<noutput_items; i++) {
+
+		@O_TYPE@ max = 0;
+		for (int j=0; j<nitems_per_block; j++ )
+			for (int k=0; k<ninputs; k++, in=(const @I_TYPE@ *)input_items[k])
+				max = ( in[i*nitems_per_block + j] > max) ? in[i*nitems_per_block + j] : max;
+
+		optr[i] = max;
+	}
+	return noutput_items;
+}
+
Index: generate_common.py
===================================================================
--- generate_common.py	(revisjon 5153)
+++ generate_common.py	(arbeidskopi)
@@ -59,7 +59,8 @@
     ('gr_unpacked_to_packed_XX',    ('bb','ss','ii')),
     ('gr_packed_to_unpacked_XX',    ('bb','ss','ii')),
     ('gr_sample_and_hold_XX',       ('bb','ss','ii','ff')),
-    ('gr_peak_detector_XX',         ('ff','ii','ss'))
+    ('gr_peak_detector_XX',         ('ff','ii','ss')),
+    ('gr_max_XX',                   ('ff','ii','ss')),
     )
 
 
Index: gr_max_XX.i.t
===================================================================
--- gr_max_XX.i.t	(revisjon 0)
+++ gr_max_XX.i.t	(revisjon 0)
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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@ ();
+
+class @NAME@ : public gr_sync_block
+{
+ private:
+  @NAME@ ();
+};
Index: Makefile.am
===================================================================
--- Makefile.am	(revisjon 5153)
+++ Makefile.am	(arbeidskopi)
@@ -50,6 +50,9 @@
 	gr_divide_XX.cc.t		\
 	gr_divide_XX.h.t		\
 	gr_divide_XX.i.t		\
+	gr_max_XX.cc.t			\
+	gr_max_XX.h.t			\
+	gr_max_XX.i.t			\
 	gr_multiply_XX.cc.t		\
 	gr_multiply_XX.h.t		\
 	gr_multiply_XX.i.t		\


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic