On Fri, Feb 20, 2009 at 05:58:48PM +0100, Martin Braun wrote: > the last thing that I am currently missing in the GR trunk is a > block that works like gr_stream_to_vector, but with a variable overlap. > Here's the code. Resemblance to gr_stream_to_vector was maximised, > perhaps these two blocks can be merged. > Together with the last two patches I sent in, the GR core has all the > stuff to easily implement non-parametric spectral estimation such as > Welch's method.
Hi, whoops, big mistake! I sent in an older version of the patch, prior to some testing and debugging. I'm awfully sorry, I hope no-one's touched that last patch! Here's the correct versions which I've already used and tested thoroughly. Won't happen again! MB -- Dipl.-Ing. Martin Braun Phone: +49-(0)721-608 3790 Institut fuer Nachrichtentechnik Fax: +49-(0)721-608 6071 Universitaet Karlsruhe (TH) http://www.int.uni-karlsruhe.de/
Index: gnuradio-core/src/python/gnuradio/gr/Makefile.am
===================================================================
--- gnuradio-core/src/python/gnuradio/gr/Makefile.am (revision 10467)
+++ gnuradio-core/src/python/gnuradio/gr/Makefile.am (working copy)
@@ -95,4 +95,5 @@
qa_unpack_k_bits.py \
qa_repeat.py \
qa_scrambler.py \
- qa_vector_sink_source.py
+ qa_vector_sink_source.py \
+ qa_stream_to_vector_overlap.py
Index: gnuradio-core/src/lib/general/Makefile.am
===================================================================
--- gnuradio-core/src/lib/general/Makefile.am (revision 10467)
+++ gnuradio-core/src/lib/general/Makefile.am (working copy)
@@ -144,6 +144,7 @@
gr_stream_mux.cc \
gr_stream_to_streams.cc \
gr_stream_to_vector.cc \
+ gr_stream_to_vector_overlap.cc \
gr_streams_to_stream.cc \
gr_streams_to_vector.cc \
gr_stretch_ff.cc \
@@ -300,6 +301,7 @@
gr_stream_mux.h \
gr_stream_to_streams.h \
gr_stream_to_vector.h \
+ gr_stream_to_vector_overlap.h \
gr_streams_to_stream.h \
gr_streams_to_vector.h \
gr_stretch_ff.h \
@@ -454,6 +456,7 @@
gr_stream_mux.i \
gr_stream_to_streams.i \
gr_stream_to_vector.i \
+ gr_stream_to_vector_overlap.i \
gr_streams_to_stream.i \
gr_streams_to_vector.i \
gr_stretch_ff.i \
Index: gnuradio-core/src/lib/general/general.i
===================================================================
--- gnuradio-core/src/lib/general/general.i (revision 10467)
+++ gnuradio-core/src/lib/general/general.i (working copy)
@@ -34,6 +34,7 @@
#include <gr_lfsr_32k_source_s.h>
#include <gr_check_lfsr_32k_s.h>
#include <gr_stream_to_vector.h>
+#include <gr_stream_to_vector_overlap.h>
#include <gr_vector_to_stream.h>
#include <gr_keep_one_in_n.h>
#include <gr_fft_vcc.h>
@@ -153,6 +154,7 @@
%include "gr_lfsr_32k_source_s.i"
%include "gr_check_lfsr_32k_s.i"
%include "gr_stream_to_vector.i"
+%include "gr_stream_to_vector_overlap.i"
%include "gr_vector_to_stream.i"
%include "gr_keep_one_in_n.i"
%include "gr_fft_vcc.i"
Index: gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.h
===================================================================
--- gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.h (revision 0)
+++ gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.h (revision 0)
@@ -0,0 +1,61 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006 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.
+ */
+
+#ifndef INCLUDED_GR_STREAM_TO_VECTOR_OVERLAP_H
+#define INCLUDED_GR_STREAM_TO_VECTOR_OVERLAP_H
+
+#include <gr_sync_decimator.h>
+
+class gr_stream_to_vector_overlap;
+typedef boost::shared_ptr<gr_stream_to_vector_overlap> gr_stream_to_vector_overlap_sptr;
+
+gr_stream_to_vector_overlap_sptr
+gr_make_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, unsigned overlap);
+
+
+/*!
+ * \brief Convert a stream of items into a stream of overlapping blocks containing nitems_per_block.
+ *
+ * The i-th block will start with the same \p overlap items as the i-1-th block ended. The first
+ * block is prepended with \p overlap zeros to ensure synchronicity.
+ * \ingroup converter
+ */
+class gr_stream_to_vector_overlap : public gr_sync_decimator
+{
+ friend gr_stream_to_vector_overlap_sptr
+ gr_make_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, unsigned overlap);
+
+ protected:
+ gr_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, unsigned overlap);
+
+ int d_bytes_overlap;
+
+ public:
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ unsigned overlap() { return history() - 1; };
+};
+
+
+#endif /* INCLUDED_GR_STREAM_TO_VECTOR_OVERLAP_H */
Index: gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.i
===================================================================
--- gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.i (revision 0)
+++ gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.i (revision 0)
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006 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.
+ */
+
+%include "exception.i"
+
+%{
+#include <stdexcept>
+%}
+
+GR_SWIG_BLOCK_MAGIC(gr,stream_to_vector_overlap)
+
+gr_stream_to_vector_overlap_sptr
+gr_make_stream_to_vector_overlap (size_t itemsize, size_t nitems_per_block, unsigned overlap)
+ throw (std::invalid_argument);
+
+class gr_stream_to_vector_overlap : public gr_sync_decimator
+{
+ protected:
+ gr_stream_to_vector_overlap (size_t itemsize, size_t nitems_per_block, unsigned overlap);
+
+ public:
+ unsigned overlap();
+};
+
Index: gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.cc
===================================================================
--- gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.cc (revision 0)
+++ gnuradio-core/src/lib/general/gr_stream_to_vector_overlap.cc (revision 0)
@@ -0,0 +1,68 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2005 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_stream_to_vector_overlap.h>
+#include <gr_io_signature.h>
+#include <string.h>
+#include <stdexcept>
+
+gr_stream_to_vector_overlap_sptr
+gr_make_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, unsigned overlap)
+{
+ return gr_stream_to_vector_overlap_sptr (new gr_stream_to_vector_overlap (item_size, nitems_per_block, overlap));
+}
+
+gr_stream_to_vector_overlap::gr_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, unsigned overlap)
+ : gr_sync_decimator ("stream_to_vector_overlap",
+ gr_make_io_signature (1, 1, item_size),
+ gr_make_io_signature (1, 1, item_size * nitems_per_block),
+ nitems_per_block - overlap),
+ d_bytes_overlap(overlap * item_size)
+{
+ if (overlap + 1 >= nitems_per_block) {
+ throw std::invalid_argument("gr_stream_to_vector_overlap: overlap must be smaller than the number of items per block.");
+ }
+ set_history(overlap + 1);
+}
+
+int
+gr_stream_to_vector_overlap::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ size_t block_size = output_signature()->sizeof_stream_item (0);
+
+ char *in = (char *) input_items[0];
+ char *out = (char *) output_items[0];
+
+ for (int i = 0; i < noutput_items; i++) {
+ memcpy(out, in, block_size);
+ out += block_size;
+ in += block_size - d_bytes_overlap;
+ }
+
+ return noutput_items;
+}
pgptRHclCYVtY.pgp
Description: PGP signature
_______________________________________________ Patch-gnuradio mailing list [email protected] http://lists.gnu.org/mailman/listinfo/patch-gnuradio
