Hi, 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.
Cheers Martin -- 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/qa_stream_to_vector_overlap.py =================================================================== --- gnuradio-core/src/python/gnuradio/gr/qa_stream_to_vector_overlap.py (revision 0) +++ gnuradio-core/src/python/gnuradio/gr/qa_stream_to_vector_overlap.py (revision 0) @@ -0,0 +1,49 @@ +#!/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_stream_to_vector_overlap(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = [float(x) for x in range(1,13)] + expected_result = (0,0,1,2, 1,2,3,4, 3,4,5,6, 5,6,7,8, 7,8,9,10, 9,10,11,12) + + src = gr.vector_source_f(src_data) + overlap = gr.stream_to_vector_overlap(gr.sizeof_float, 4, 2) + dst = gr.vector_sink_f(4) + + self.tb.connect(src, overlap, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.main () + Property changes on: gnuradio-core/src/python/gnuradio/gr/qa_stream_to_vector_overlap.py ___________________________________________________________________ Added: svn:executable + * Index: gnuradio-core/src/python/gnuradio/gr/Makefile.am =================================================================== --- gnuradio-core/src/python/gnuradio/gr/Makefile.am (revision 10232) +++ 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 10232) +++ 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 10232) +++ 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,59 @@ +/* -*- 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, int 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 overlap items as the i-1-th block ended. + * \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, int overlap); + + protected: + gr_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, int overlap); + + std::vector<char> d_buf; + int d_bytes_overlap; + + public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#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,35 @@ +/* -*- 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. + */ + +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, int overlap); + +class gr_stream_to_vector_overlap : public gr_sync_decimator +{ + protected: + gr_stream_to_vector_overlap (size_t itemsize, size_t nitems_per_block, int overlap); + + public: +}; + 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,73 @@ +/* -*- 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> + +gr_stream_to_vector_overlap_sptr +gr_make_stream_to_vector_overlap (size_t item_size, size_t nitems_per_block, int 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, int 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), + d_buf(overlap * item_size, 0), + d_bytes_overlap(overlap * item_size) +{ +} + +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]; + char *d_bufptr = (char *) &d_buf[0]; + + // TODO: The last d_bytes_overlap bytes are copied twice, once to d_buf + // and once to the beginning of the next vector. think about if there's + // any speed to be gained here. + for (int i = 0; i < noutput_items; i++) { + memcpy(out, d_bufptr, d_bytes_overlap); + out += d_bytes_overlap; + memcpy(out, in, block_size-d_bytes_overlap); + out += block_size - d_bytes_overlap; + + in += block_size - d_bytes_overlap; + memcpy(d_bufptr, in, d_bytes_overlap); + in += d_bytes_overlap; + } + + return noutput_items; +}
pgp3g44coBntr.pgp
Description: PGP signature
_______________________________________________ Patch-gnuradio mailing list Patch-gnuradio@gnu.org http://lists.gnu.org/mailman/listinfo/patch-gnuradio