From f42ef36d60348965936ede158886c1847670f774 Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Thu, 21 Feb 2013 18:24:02 -0500
Subject: blocks: converting blocks to v3.7 style in gr-blocks.
delay, rms, unpacked_to_packed, packed_to_unpacked
---
gr-blocks/grc/blocks_block_tree.xml | 6 +-
gr-blocks/grc/blocks_delay.xml | 75 +++++
gr-blocks/grc/blocks_packed_to_unpacked_xx.xml | 68 ++++
gr-blocks/grc/blocks_rms_xx.xml | 42 +++
gr-blocks/grc/blocks_unpacked_to_packed_xx.xml | 68 ++++
gr-blocks/include/blocks/CMakeLists.txt | 6 +
gr-blocks/include/blocks/delay.h | 57 ++++
gr-blocks/include/blocks/log2_const.h | 53 ++++
gr-blocks/include/blocks/packed_to_unpacked_XX.h.t | 73 +++++
gr-blocks/include/blocks/rms_cf.h | 54 ++++
gr-blocks/include/blocks/rms_ff.h | 53 ++++
gr-blocks/include/blocks/unpacked_to_packed_XX.h.t | 72 +++++
gr-blocks/lib/CMakeLists.txt | 5 +
gr-blocks/lib/delay_impl.cc | 141 +++++++++
gr-blocks/lib/delay_impl.h | 58 ++++
gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t | 147 +++++++++
gr-blocks/lib/packed_to_unpacked_XX_impl.h.t | 59 ++++
gr-blocks/lib/rms_cf_impl.cc | 77 +++++
gr-blocks/lib/rms_cf_impl.h | 56 ++++
gr-blocks/lib/rms_ff_impl.cc | 77 +++++
gr-blocks/lib/rms_ff_impl.h | 55 ++++
gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t | 143 +++++++++
gr-blocks/lib/unpacked_to_packed_XX_impl.h.t | 59 ++++
gr-blocks/python/qa_delay.py | 65 ++++
gr-blocks/python/qa_file_metadata.py | 4 +-
gr-blocks/python/qa_packed_to_unpacked.py | 344 +++++++++++++++++++++
gr-blocks/python/qa_rms.py | 83 +++++
gr-blocks/swig/blocks_swig.i | 31 +-
28 files changed, 2027 insertions(+), 4 deletions(-)
create mode 100644 gr-blocks/grc/blocks_delay.xml
create mode 100644 gr-blocks/grc/blocks_packed_to_unpacked_xx.xml
create mode 100644 gr-blocks/grc/blocks_rms_xx.xml
create mode 100644 gr-blocks/grc/blocks_unpacked_to_packed_xx.xml
create mode 100644 gr-blocks/include/blocks/delay.h
create mode 100644 gr-blocks/include/blocks/log2_const.h
create mode 100644 gr-blocks/include/blocks/packed_to_unpacked_XX.h.t
create mode 100644 gr-blocks/include/blocks/rms_cf.h
create mode 100644 gr-blocks/include/blocks/rms_ff.h
create mode 100644 gr-blocks/include/blocks/unpacked_to_packed_XX.h.t
create mode 100644 gr-blocks/lib/delay_impl.cc
create mode 100644 gr-blocks/lib/delay_impl.h
create mode 100644 gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t
create mode 100644 gr-blocks/lib/packed_to_unpacked_XX_impl.h.t
create mode 100644 gr-blocks/lib/rms_cf_impl.cc
create mode 100644 gr-blocks/lib/rms_cf_impl.h
create mode 100644 gr-blocks/lib/rms_ff_impl.cc
create mode 100644 gr-blocks/lib/rms_ff_impl.h
create mode 100644 gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t
create mode 100644 gr-blocks/lib/unpacked_to_packed_XX_impl.h.t
create mode 100755 gr-blocks/python/qa_delay.py
create mode 100755 gr-blocks/python/qa_packed_to_unpacked.py
create mode 100644 gr-blocks/python/qa_rms.py
(limited to 'gr-blocks')
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 797b3dbc5..6b17078cd 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -49,6 +49,7 @@
blocks_conjugate_ccblocks_integrate_xxblocks_nlog10_ff
+ blocks_rms_xxBoolean Operations (New)
@@ -82,7 +83,10 @@
Stream Operations (New)
- blocks_deinterleave
+ blocks_delay
+ blocks_packed_to_unpacked_xx
+ blocks_unpacked_to_packed_xx
+ blocks_deinterleaveblocks_interleaveblocks_keep_m_in_nblocks_keep_one_in_n
diff --git a/gr-blocks/grc/blocks_delay.xml b/gr-blocks/grc/blocks_delay.xml
new file mode 100644
index 000000000..a7c48c4dc
--- /dev/null
+++ b/gr-blocks/grc/blocks_delay.xml
@@ -0,0 +1,75 @@
+
+
+
+ Delay
+ blocks_delay
+ from gnuradio import blocks
+ blocks.delay($type.size*$vlen, $delay)
+ set_dly($delay)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ Delay
+ delay
+ 0
+ int
+
+
+ Num Ports
+ num_ports
+ 1
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_ports > 0
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+ $num_ports
+
+
+
diff --git a/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml b/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml
new file mode 100644
index 000000000..b236a38db
--- /dev/null
+++ b/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml
@@ -0,0 +1,68 @@
+
+
+
+ Packed to Unpacked
+ blocks_packed_to_unpacked_xx
+ from gnuradio import blocks
+ blocks.packed_to_unpacked_$(type.fcn)($bits_per_chunk, $endianness)
+
+ Type
+ type
+ enum
+
+
+
+
+
+ Bits per Chunk
+ bits_per_chunk
+ 2
+ int
+
+
+ Endianness
+ endianness
+ int
+
+
+
+
+ Num Ports
+ num_ports
+ 1
+ int
+
+ $num_ports > 0
+
+ in
+ $type
+ $num_ports
+
+
+
diff --git a/gr-blocks/grc/blocks_rms_xx.xml b/gr-blocks/grc/blocks_rms_xx.xml
new file mode 100644
index 000000000..0ae09139a
--- /dev/null
+++ b/gr-blocks/grc/blocks_rms_xx.xml
@@ -0,0 +1,42 @@
+
+
+
+ RMS
+ blocks_rms_xx
+ from gnuradio import blocks
+ blocks.rms_$(type.fcn)f($alpha)
+ set_alpha($alpha)
+
+ Input Type
+ type
+ enum
+
+
+
+
+ Alpha
+ alpha
+ 0.0001
+ real
+
+
+ in
+ $type
+
+
+
diff --git a/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml b/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml
new file mode 100644
index 000000000..d27dc9bfc
--- /dev/null
+++ b/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml
@@ -0,0 +1,68 @@
+
+
+
+ Unpacked to Packed
+ blocks_unpacked_to_packed_xx
+ from gnuradio import blocks
+ blocks.unpacked_to_packed_$(type.fcn)($bits_per_chunk, $endianness)
+
+ Type
+ type
+ enum
+
+
+
+
+
+ Bits per Chunk
+ bits_per_chunk
+ 2
+ int
+
+
+ Endianness
+ endianness
+ int
+
+
+
+
+ Num Ports
+ num_ports
+ 1
+ int
+
+ $num_ports > 0
+
+ in
+ $type
+ $num_ports
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 37790b7cf..a6608696a 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -78,6 +78,8 @@ expand_h(not_XX bb ss ii)
expand_h(or_XX bb ss ii)
expand_h(sub_XX ss ii ff cc)
expand_h(xor_XX bb ss ii)
+expand_h(packed_to_unpacked_XX bb ss ii)
+expand_h(unpacked_to_packed_XX bb ss ii)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
@@ -90,6 +92,7 @@ install(FILES
${generated_includes}
api.h
count_bits.h
+ log2_const.h
add_ff.h
char_to_float.h
char_to_short.h
@@ -102,6 +105,7 @@ install(FILES
complex_to_arg.h
conjugate_cc.h
deinterleave.h
+ delay.h
file_source.h
file_meta_sink.h
file_meta_source.h
@@ -123,6 +127,8 @@ install(FILES
nlog10_ff.h
patterned_interleaver.h
repeat.h
+ rms_cf.h
+ rms_ff.h
short_to_char.h
short_to_float.h
stream_mux.h
diff --git a/gr-blocks/include/blocks/delay.h b/gr-blocks/include/blocks/delay.h
new file mode 100644
index 000000000..2a59fa0fc
--- /dev/null
+++ b/gr-blocks/include/blocks/delay.h
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2012-2013 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_BLOCKS_DELAY_H
+#define INCLUDED_BLOCKS_DELAY_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief delay the input by a certain number of samples
+ * \ingroup misc_blk
+ */
+ class BLOCKS_API delay : virtual public gr_block
+ {
+ public:
+ // gr::blocks::delay::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make a delay block.
+ * \param itemsize size of the data items.
+ * \param delay number of samples to delay stream.
+ */
+ static sptr make(size_t itemsize, int delay);
+
+ virtual int dly() const = 0;
+ virtual void set_dly(int d) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_DELAY_H */
+
diff --git a/gr-blocks/include/blocks/log2_const.h b/gr-blocks/include/blocks/log2_const.h
new file mode 100644
index 000000000..67d63810f
--- /dev/null
+++ b/gr-blocks/include/blocks/log2_const.h
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2013 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.
+ */
+
+
+/*
+ * a bit of template hackery...
+ */
+#ifndef INCLUDED_BLOCKS_LOG2_CONST_H
+#define INCLUDED_BLOCKS_LOG2_CONST_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ template static inline int log2_const() { assert(0); return 0; }
+
+ template<> inline int log2_const<1>() { return 0; }
+ template<> inline int log2_const<2>() { return 1; }
+ template<> inline int log2_const<4>() { return 2; }
+ template<> inline int log2_const<8>() { return 3; }
+ template<> inline int log2_const<16>() { return 4; }
+ template<> inline int log2_const<32>() { return 5; }
+ template<> inline int log2_const<64>() { return 6; }
+ template<> inline int log2_const<128>() { return 7; }
+ template<> inline int log2_const<256>() { return 8; }
+ template<> inline int log2_const<512>() { return 9; }
+ template<> inline int log2_const<1024>(){ return 10; }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_LOG2_CONST_H */
diff --git a/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t b/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t
new file mode 100644
index 000000000..9ab8b8bdf
--- /dev/null
+++ b/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2013 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
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert a stream of packed bytes or shorts to stream of unpacked bytes or shorts.
+ * \ingroup converter_blk
+ *
+ * input: stream of @I_TYPE@; output: stream of @O_TYPE@
+ *
+ * This is the inverse of gr::blocks::unpacked_to_packed_XX.
+ *
+ * The bits in the bytes or shorts input stream are grouped into
+ * chunks of \p bits_per_chunk bits and each resulting chunk is
+ * written right- justified to the output stream of bytes or
+ * shorts. All b or 16 bits of the each input bytes or short are
+ * processed. The right thing is done if bits_per_chunk is not a
+ * power of two.
+ *
+ * The combination of gr_packed_to_unpacked_XX_ followed by
+ * gr_chunks_to_symbols_Xf or gr_chunks_to_symbols_Xc handles the
+ * general case of mapping from a stream of bytes or shorts into
+ * arbitrary float or complex symbols.
+ *
+ * \sa gr::blocks::packed_to_unpacked_bb, gr::blocks::unpacked_to_packed_bb,
+ * \sa gr::blocks::packed_to_unpacked_ss, gr::blocks::unpacked_to_packed_ss,
+ * \sa gr::blocks::chunks_to_symbols_bf, gr::blocks::chunks_to_symbols_bc.
+ * \sa gr::blocks::chunks_to_symbols_sf, gr::blocks::chunks_to_symbols_sc.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_block
+ {
+ public:
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(unsigned int bits_per_chunk,
+ gr_endianness_t endianness);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/rms_cf.h b/gr-blocks/include/blocks/rms_cf.h
new file mode 100644
index 000000000..e73be6923
--- /dev/null
+++ b/gr-blocks/include/blocks/rms_cf.h
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_BLOCKS_RMS_CF_H
+#define INCLUDED_BLOCKS_RMS_CF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief RMS average power
+ * \ingroup math_blk
+ */
+ class BLOCKS_API rms_cf : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::rms_cf::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make an RMS calc. block.
+ * \param alpha gain for running average filter.
+ */
+ static sptr make(double alpha = 0.0001);
+
+ virtual void set_alpha(double alpha) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_RMS_CF_H */
diff --git a/gr-blocks/include/blocks/rms_ff.h b/gr-blocks/include/blocks/rms_ff.h
new file mode 100644
index 000000000..19fb0016d
--- /dev/null
+++ b/gr-blocks/include/blocks/rms_ff.h
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_BLOCKS_RMS_FF_H
+#define INCLUDED_BLOCKS_RMS_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief RMS average power
+ * \ingroup math_blk
+ */
+ class BLOCKS_API rms_ff : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::rms_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make an RMS calc. block.
+ * \param alpha gain for running average filter.
+ */
+ static sptr make(double alpha = 0.0001);
+
+ virtual void set_alpha(double alpha) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_RMS_FF_H */
diff --git a/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t b/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t
new file mode 100644
index 000000000..749f0e00f
--- /dev/null
+++ b/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2013 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
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert a stream of unpacked bytes or shorts into a stream of packed bytes or shorts.
+ * \ingroup converter_blk
+ *
+ * input: stream of @I_TYPE@; output: stream of @O_TYPE@
+ *
+ * This is the inverse of gr::blocks::packed_to_unpacked_XX.
+ *
+ * The low \p bits_per_chunk bits are extracted from each input
+ * byte or short. These bits are then packed densely into the
+ * output bytes or shorts, such that all 8 or 16 bits of the
+ * output bytes or shorts are filled with valid input bits. The
+ * right thing is done if bits_per_chunk is not a power of two.
+ *
+ * The combination of gr_packed_to_unpacked_XX followed by
+ * gr_chunks_to_symbols_Xf or gr_chunks_to_symbols_Xc handles the
+ * general case of mapping from a stream of bytes or shorts into
+ * arbitrary float or complex symbols.
+ *
+ * \sa gr::blocks::packed_to_unpacked_bb, gr::blocks::unpacked_to_packed_bb,
+ * \sa gr::blocks::packed_to_unpacked_ss, gr::blocks::unpacked_to_packed_ss,
+ * \sa gr::blocks::chunks_to_symbols_bf, gr::blocks::chunks_to_symbols_bc.
+ * \sa gr::blocks::chunks_to_symbols_sf, gr::blocks::chunks_to_symbols_sc.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_block
+ {
+ public:
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(unsigned int bits_per_chunk,
+ gr_endianness_t endianness);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 560a55d57..9b076f696 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -104,6 +104,8 @@ expand_cc_h_impl(not_XX bb ss ii)
expand_cc_h_impl(or_XX bb ss ii)
expand_cc_h_impl(sub_XX ss ii ff cc)
expand_cc_h_impl(xor_XX bb ss ii)
+expand_cc_h_impl(packed_to_unpacked_XX bb ss ii)
+expand_cc_h_impl(unpacked_to_packed_XX bb ss ii)
########################################################################
# Setup the include and linker paths
@@ -139,6 +141,7 @@ list(APPEND gr_blocks_sources
complex_to_arg_impl.cc
conjugate_cc_impl.cc
deinterleave_impl.cc
+ delay_impl.cc
file_source_impl.cc
file_meta_sink_impl.cc
file_meta_source_impl.cc
@@ -163,6 +166,8 @@ list(APPEND gr_blocks_sources
nlog10_ff_impl.cc
patterned_interleaver_impl.cc
repeat_impl.cc
+ rms_cf_impl.cc
+ rms_ff_impl.cc
short_to_char_impl.cc
short_to_float_impl.cc
stream_mux_impl.cc
diff --git a/gr-blocks/lib/delay_impl.cc b/gr-blocks/lib/delay_impl.cc
new file mode 100644
index 000000000..67449aca2
--- /dev/null
+++ b/gr-blocks/lib/delay_impl.cc
@@ -0,0 +1,141 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2010,2012-2013 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 "delay_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ delay::sptr
+ delay::make(size_t itemsize, int delay)
+ {
+ return gnuradio::get_initial_sptr
+ (new delay_impl(itemsize, delay));
+ }
+
+ delay_impl::delay_impl(size_t itemsize, int delay)
+ : gr_block("delay",
+ gr_make_io_signature(1, -1, itemsize),
+ gr_make_io_signature(1, -1, itemsize)),
+ d_itemsize(itemsize)
+ {
+ set_dly(delay);
+ d_delta = 0;
+ }
+
+ delay_impl::~delay_impl()
+ {
+ }
+
+ void
+ delay_impl::forecast(int noutput_items,
+ gr_vector_int &ninput_items_required)
+ {
+ // make sure all inputs have noutput_items available
+ unsigned ninputs = ninput_items_required.size();
+ for(unsigned i = 0; i < ninputs; i++)
+ ninput_items_required[i] = noutput_items;
+ }
+
+ void
+ delay_impl::set_dly(int d)
+ {
+ // only set a new delta if there is a change in the delay; this
+ // protects from quickly-repeated calls to this function that
+ // would end with d_delta=0.
+ if(d != dly()) {
+ gruel::scoped_lock l(d_mutex_delay);
+ int old = dly();
+ set_history(d+1);
+ d_delta += dly() - old;
+ }
+ }
+
+ int
+ delay_impl::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gruel::scoped_lock l(d_mutex_delay);
+ assert(input_items.size() == output_items.size());
+
+ const char *iptr;
+ char *optr;
+ int cons, ret;
+
+ // No change in delay; just memcpy ins to outs
+ if(d_delta == 0) {
+ for(size_t i = 0; i < input_items.size(); i++) {
+ iptr = (const char *)input_items[i];
+ optr = (char *)output_items[i];
+ std::memcpy(optr, iptr, noutput_items*d_itemsize);
+ }
+ cons = noutput_items;
+ ret = noutput_items;
+ }
+
+ // Skip over d_delta items on the input
+ else if(d_delta < 0) {
+ int n_to_copy, n_adj;
+ int delta = -d_delta;
+ n_to_copy = std::max(0, noutput_items-delta);
+ n_adj = std::min(delta, noutput_items);
+ for(size_t i = 0; i < input_items.size(); i++) {
+ iptr = (const char *) input_items[i];
+ optr = (char *) output_items[i];
+ std::memcpy(optr, iptr+delta*d_itemsize, n_to_copy*d_itemsize);
+ }
+ cons = noutput_items;
+ ret = n_to_copy;
+ delta -= n_adj;
+ d_delta = -delta;
+ }
+
+ //produce but not consume (inserts zeros)
+ else { // d_delta > 0
+ int n_from_input, n_padding;
+ n_from_input = std::max(0, noutput_items-d_delta);
+ n_padding = std::min(d_delta, noutput_items);
+ for(size_t i = 0; i < input_items.size(); i++) {
+ iptr = (const char *) input_items[i];
+ optr = (char *) output_items[i];
+ std::memset(optr, 0, n_padding*d_itemsize);
+ std::memcpy(optr, iptr, n_from_input*d_itemsize);
+ }
+ cons = n_from_input;
+ ret = noutput_items;
+ d_delta -= n_padding;
+ }
+
+ consume_each(cons);
+ return ret;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/delay_impl.h b/gr-blocks/lib/delay_impl.h
new file mode 100644
index 000000000..56d971b11
--- /dev/null
+++ b/gr-blocks/lib/delay_impl.h
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2012-2013 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_DELAY_IMPL_H
+#define INCLUDED_GR_DELAY_IMPL_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class delay_impl : public delay
+ {
+ private:
+ void forecast(int noutput_items,
+ gr_vector_int &ninput_items_required);
+
+ size_t d_itemsize;
+ int d_delta;
+ gruel::mutex d_mutex_delay;
+
+ public:
+ delay_impl(size_t itemsize, int delay);
+ ~delay_impl();
+
+ int dly() const { return history()-1; }
+ void set_dly(int d);
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_DELAY_IMPL_H */
diff --git a/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t b/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t
new file mode 100644
index 000000000..4f34d8347
--- /dev/null
+++ b/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t
@@ -0,0 +1,147 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2013 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_IMPL@.h"
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ static const unsigned int BITS_PER_TYPE = sizeof(@I_TYPE@) * 8;
+ static const unsigned int LOG2_L_TYPE = log2_const();
+
+ @NAME@::sptr
+ @NAME@::make(unsigned int bits_per_chunk,
+ gr_endianness_t endianness)
+ {
+ return gnuradio::get_initial_sptr
+ (new @NAME_IMPL@(bits_per_chunk, endianness));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(unsigned int bits_per_chunk,
+ gr_endianness_t endianness)
+ : gr_block("@NAME@",
+ gr_make_io_signature(1, -1, sizeof(@I_TYPE@)),
+ gr_make_io_signature(1, -1, sizeof(@O_TYPE@))),
+ d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0)
+ {
+ assert(bits_per_chunk <= BITS_PER_TYPE);
+ assert(bits_per_chunk > 0);
+
+ set_relative_rate((1.0 * BITS_PER_TYPE) / bits_per_chunk);
+ }
+
+ @NAME_IMPL@::~@NAME_IMPL@()
+ {
+ }
+
+ void
+ @NAME_IMPL@::forecast(int noutput_items,
+ gr_vector_int &ninput_items_required)
+ {
+ int input_required = (int)ceil((d_index + noutput_items * d_bits_per_chunk)
+ / (1.0 * BITS_PER_TYPE));
+ unsigned ninputs = ninput_items_required.size();
+ for(unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ //printf("Forecast wants %d needs %d\n",noutput_items,ninput_items_required[i]);
+ }
+ }
+
+ unsigned int
+ get_bit_le(const @I_TYPE@ *in_vector, unsigned int bit_addr)
+ {
+ @I_TYPE@ x = in_vector[bit_addr >> LOG2_L_TYPE];
+ return (x >> (bit_addr & (BITS_PER_TYPE-1))) & 1;
+ }
+
+ unsigned int
+ get_bit_be(const @I_TYPE@ *in_vector, unsigned int bit_addr)
+ {
+ @I_TYPE@ x = in_vector[bit_addr >> LOG2_L_TYPE];
+ return (x >> ((BITS_PER_TYPE-1) - (bit_addr & (BITS_PER_TYPE-1)))) & 1;
+ }
+
+ int
+ @NAME_IMPL@::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ unsigned int index_tmp = d_index;
+
+ assert(input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+ for (int m=0; m < nstreams; m++){
+ const @I_TYPE@ *in = (@I_TYPE@ *)input_items[m];
+ @O_TYPE@ *out = (@O_TYPE@ *)output_items[m];
+ index_tmp = d_index;
+
+ // per stream processing
+
+ switch(d_endianness) {
+ case GR_MSB_FIRST:
+ for(int i = 0; i < noutput_items; i++) {
+ //printf("here msb %d\n",i);
+ @O_TYPE@ x = 0;
+ for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++)
+ x = (x<<1) | get_bit_be(in, index_tmp);
+ out[i] = x;
+ }
+ break;
+
+ case GR_LSB_FIRST:
+ for(int i = 0; i < noutput_items; i++) {
+ //printf("here lsb %d\n",i);
+ @O_TYPE@ x = 0;
+ for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++)
+ x = (x<<1) | get_bit_le(in, index_tmp);
+ out[i] = x;
+ }
+ break;
+
+ default:
+ assert(0);
+ }
+
+ //printf("almost got to end\n");
+ assert(ninput_items[m] >= (int)((d_index+(BITS_PER_TYPE-1)) >> LOG2_L_TYPE));
+ }
+
+ d_index = index_tmp;
+ consume_each(d_index >> LOG2_L_TYPE);
+ d_index = d_index & (BITS_PER_TYPE-1);
+ //printf("got to end\n");
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t b/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t
new file mode 100644
index 000000000..f83496fa7
--- /dev/null
+++ b/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2013 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_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class @NAME_IMPL@ : public @NAME@
+ {
+ private:
+ unsigned int d_bits_per_chunk;
+ gr_endianness_t d_endianness;
+ unsigned int d_index;
+
+ public:
+ @NAME_IMPL@(unsigned int bits_per_chunk,
+ gr_endianness_t endianness);
+ ~@NAME_IMPL@();
+
+ void forecast(int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ bool check_topology(int ninputs, int noutputs)
+ { return ninputs == noutputs; }
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/rms_cf_impl.cc b/gr-blocks/lib/rms_cf_impl.cc
new file mode 100644
index 000000000..d956b45f1
--- /dev/null
+++ b/gr-blocks/lib/rms_cf_impl.cc
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,2013 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 "rms_cf_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ rms_cf::sptr
+ rms_cf::make(double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new rms_cf_impl(alpha));
+ }
+
+ rms_cf_impl::rms_cf_impl (double alpha)
+ : gr_sync_block("rms_cf",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_iir(alpha)
+ {
+ }
+
+ rms_cf_impl::~rms_cf_impl()
+ {
+ }
+
+ void
+ rms_cf_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ int
+ rms_cf_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const gr_complex *in = (const gr_complex *)input_items[0];
+ float *out = (float *)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag();
+ double f = d_iir.filter(mag_sqrd);
+ out[i] = sqrt(f);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/rms_cf_impl.h b/gr-blocks/lib/rms_cf_impl.h
new file mode 100644
index 000000000..438b8549d
--- /dev/null
+++ b/gr-blocks/lib/rms_cf_impl.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_BLOCKS_RMS_CF_IMPL_H
+#define INCLUDED_BLOCKS_RMS_CF_IMPL_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief RMS average power
+ * \ingroup math_blk
+ */
+ class rms_cf_impl : public rms_cf
+ {
+ private:
+ gr_single_pole_iir d_iir;
+
+ public:
+ rms_cf_impl(double alpha = 0.0001);
+ ~rms_cf_impl();
+
+ void set_alpha(double alpha);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_RMS_CF_IMPL_H */
diff --git a/gr-blocks/lib/rms_ff_impl.cc b/gr-blocks/lib/rms_ff_impl.cc
new file mode 100644
index 000000000..2b8cdc34e
--- /dev/null
+++ b/gr-blocks/lib/rms_ff_impl.cc
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,2013 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 "rms_ff_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ rms_ff::sptr
+ rms_ff::make(double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new rms_ff_impl(alpha));
+ }
+
+ rms_ff_impl::rms_ff_impl(double alpha)
+ : gr_sync_block("rms_ff",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_iir(alpha)
+ {
+ }
+
+ rms_ff_impl::~rms_ff_impl()
+ {
+ }
+
+ void
+ rms_ff_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ int
+ rms_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *)input_items[0];
+ float *out = (float *)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ double mag_sqrd = in[i]*in[i];
+ double f = d_iir.filter(mag_sqrd);
+ out[i] = sqrt(f);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/rms_ff_impl.h b/gr-blocks/lib/rms_ff_impl.h
new file mode 100644
index 000000000..82ecbda52
--- /dev/null
+++ b/gr-blocks/lib/rms_ff_impl.h
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2013 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_BLOCKS_RMS_FF_IMPL_H
+#define INCLUDED_BLOCKS_RMS_FF_IMPL_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief RMS average power
+ * \ingroup math_blk
+ */
+ class rms_ff_impl : public rms_ff
+ {
+ private:
+ gr_single_pole_iir d_iir;
+
+ public:
+ rms_ff_impl(double alpha = 0.0001);
+ ~rms_ff_impl();
+
+ void set_alpha(double alpha);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_RMS_FF_IMPL_H */
diff --git a/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t b/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t
new file mode 100644
index 000000000..3a7428fd8
--- /dev/null
+++ b/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t
@@ -0,0 +1,143 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,2013 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_IMPL@.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ static const unsigned int BITS_PER_TYPE = sizeof(@O_TYPE@) * 8;
+
+ @NAME@::sptr
+ @NAME@::make(unsigned int bits_per_chunk,
+ gr_endianness_t endianness)
+ {
+ return gnuradio::get_initial_sptr
+ (new @NAME_IMPL@(bits_per_chunk, endianness));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(unsigned int bits_per_chunk,
+ gr_endianness_t endianness)
+ : gr_block("@NAME@",
+ gr_make_io_signature(1, -1, sizeof(@I_TYPE@)),
+ gr_make_io_signature(1, -1, sizeof(@O_TYPE@))),
+ d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0)
+ {
+ assert(bits_per_chunk <= BITS_PER_TYPE);
+ assert(bits_per_chunk > 0);
+
+ set_relative_rate(bits_per_chunk/(1.0 * BITS_PER_TYPE));
+ }
+
+ @NAME_IMPL@::~@NAME_IMPL@()
+ {
+ }
+
+ void
+ @NAME_IMPL@::forecast(int noutput_items,
+ gr_vector_int &ninput_items_required)
+ {
+ int input_required = (int)ceil((d_index+noutput_items * 1.0 * BITS_PER_TYPE)
+ / d_bits_per_chunk);
+ unsigned ninputs = ninput_items_required.size();
+ for(unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+ }
+
+ unsigned int
+ get_bit_be1(const @I_TYPE@ *in_vector, unsigned int bit_addr,
+ unsigned int bits_per_chunk)
+ {
+ unsigned int byte_addr = (int)bit_addr/bits_per_chunk;
+ @I_TYPE@ x = in_vector[byte_addr];
+ unsigned int residue = bit_addr - byte_addr * bits_per_chunk;
+ //printf("Bit addr %d byte addr %d residue %d val %d\n",bit_addr,byte_addr,residue,(x>>(bits_per_chunk-1-residue))&1);
+ return (x >> (bits_per_chunk-1-residue)) & 1;
+ }
+
+ int
+ @NAME_IMPL@::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ unsigned int index_tmp = d_index;
+
+ assert(input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+ for(int m=0; m< nstreams; m++) {
+ const @I_TYPE@ *in = (@I_TYPE@ *)input_items[m];
+ @O_TYPE@ *out = (@O_TYPE@ *)output_items[m];
+ index_tmp=d_index;
+
+ // per stream processing
+
+ //assert((ninput_items[m]-d_index)*d_bits_per_chunk >= noutput_items*BITS_PER_TYPE);
+
+ switch(d_endianness) {
+
+ case GR_MSB_FIRST:
+ for(int i = 0; i < noutput_items; i++) {
+ @O_TYPE@ tmp=0;
+ for(unsigned int j = 0; j < BITS_PER_TYPE; j++) {
+ tmp = (tmp<<1) | get_bit_be1(in, index_tmp, d_bits_per_chunk);
+ index_tmp++;
+ }
+ out[i] = tmp;
+ }
+ break;
+
+ case GR_LSB_FIRST:
+ for(int i = 0; i < noutput_items; i++) {
+ unsigned long tmp=0;
+ for(unsigned int j = 0; j < BITS_PER_TYPE; j++) {
+ tmp = (tmp>>1) | (get_bit_be1(in, index_tmp, d_bits_per_chunk) << (BITS_PER_TYPE-1));
+ index_tmp++;
+ }
+ out[i] = tmp;
+ }
+ break;
+
+ default:
+ assert(0);
+ }
+ }
+
+ d_index = index_tmp;
+ consume_each((int)(d_index/d_bits_per_chunk));
+ d_index = d_index%d_bits_per_chunk;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t b/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t
new file mode 100644
index 000000000..c8f414c55
--- /dev/null
+++ b/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006.2013 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_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class @NAME_IMPL@ : public @NAME@
+ {
+ private:
+ unsigned int d_bits_per_chunk;
+ gr_endianness_t d_endianness;
+ unsigned int d_index;
+
+ public:
+ @NAME_IMPL@(unsigned int bits_per_chunk,
+ gr_endianness_t endianness);
+ ~@NAME_IMPL@();
+
+ void forecast(int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ bool check_topology(int ninputs, int noutputs)
+ { return ninputs == noutputs; }
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_delay.py b/gr-blocks/python/qa_delay.py
new file mode 100755
index 000000000..031cadb2d
--- /dev/null
+++ b/gr-blocks/python/qa_delay.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,2010,2013 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 blocks_swig as blocks
+
+class test_delay(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_000(self):
+ delta_t = 0
+ tb = self.tb
+ src_data = [float(x) for x in range(0, 100)]
+ expected_result = tuple(delta_t*[0.0] + src_data)
+
+ src = gr.vector_source_f(src_data)
+ op = blocks.delay(gr.sizeof_float, delta_t)
+ dst = gr.vector_sink_f()
+
+ tb.connect(src, op, dst)
+ tb.run()
+ dst_data = dst.data()
+ self.assertEqual(expected_result, dst_data)
+
+ def test_010(self):
+ delta_t = 10
+ tb = self.tb
+ src_data = [float(x) for x in range(0, 100)]
+ expected_result = tuple(delta_t*[0.0] + src_data)
+
+ src = gr.vector_source_f(src_data)
+ op = blocks.delay(gr.sizeof_float, delta_t)
+ dst = gr.vector_sink_f()
+
+ tb.connect(src, op, dst)
+ tb.run()
+ dst_data = dst.data()
+ self.assertEqual(expected_result, dst_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_delay, "test_delay.xml")
diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py
index 29ed0d1c8..c7826b1d3 100644
--- a/gr-blocks/python/qa_file_metadata.py
+++ b/gr-blocks/python/qa_file_metadata.py
@@ -28,8 +28,8 @@ import os, math
def sig_source_c(samp_rate, freq, amp, N):
t = map(lambda x: float(x)/samp_rate, xrange(N))
- y = map(lambda x: math.cos(2.*math.pi*freq*x) + \
- 1j*math.sin(2.*math.pi*freq*x), t)
+ y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \
+ 1j*amp*math.sin(2.*math.pi*freq*x), t)
return y
class test_file_metadata(gr_unittest.TestCase):
diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py
new file mode 100755
index 000000000..98a02e78f
--- /dev/null
+++ b/gr-blocks/python/qa_packed_to_unpacked.py
@@ -0,0 +1,344 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2007,2010,2013 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 blocks_swig as blocks
+import random
+
+class test_packing(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block ()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001(self):
+ src_data = (0x80,)
+ expected_results = (1,0,0,0,0,0,0,0)
+ src = gr.vector_source_b(src_data, False)
+ op = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_002(self):
+ src_data = (0x80,)
+ expected_results = (0,0,0,0,0,0,0,1)
+ src = gr.vector_source_b(src_data, False)
+ op = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_003(self):
+ src_data = (0x11,)
+ expected_results = (4, 2)
+ src = gr.vector_source_b(src_data, False)
+ op = gr.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_004(self):
+ src_data = (0x11,)
+ expected_results = (0, 4)
+ src = gr.vector_source_b(src_data, False)
+ op = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_005(self):
+ src_data = (1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0)
+ expected_results = (0x82, 0x5a)
+ src = gr.vector_source_b(src_data, False)
+ op = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_006(self):
+ src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0)
+ expected_results = (0x82, 0x5a)
+ src = gr.vector_source_b(src_data, False)
+ op = gr.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_007(self):
+ src_data = (4, 2, 0,0,0)
+ expected_results = (0x11,)
+ src = gr.vector_source_b(src_data, False)
+ op = gr.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_008(self):
+ src_data = (0, 4, 2,0,0)
+ expected_results = (0x11,)
+ src = gr.vector_source_b(src_data,False)
+ op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_009(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(202):
+ src_data.append((random.randint(0,255)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+
+ src = gr.vector_source_b(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results[0:201], dst.data())
+
+ def test_010(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(56):
+ src_data.append((random.randint(0,255)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_b(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results[0:201], dst.data())
+
+ def test_011(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(56):
+ src_data.append((random.randint(0,255)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_b(tuple(src_data),False)
+ op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
+ op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results[0:201], dst.data())
+
+
+ # tests on shorts
+ def test_100a(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**15,2**15-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_s(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_s()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_100b(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**15,2**15-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_s(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST)
+ op2 = gr.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_s()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_101a(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**15,2**15-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_s(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_s()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_101b(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**15,2**15-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_s(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST)
+ op2 = gr.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_s()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+
+ # tests on ints
+ def test_200a(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**31,2**31-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_i(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_200b(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**31,2**31-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_i(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST)
+ op2 = gr.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_201a(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**31,2**31-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_i(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST)
+ op2 = gr.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+ def test_201b(self):
+ random.seed(0)
+ src_data = []
+ for i in xrange(100):
+ src_data.append((random.randint(-2**31,2**31-1)))
+ src_data = tuple(src_data)
+ expected_results = src_data
+ src = gr.vector_source_i(tuple(src_data), False)
+ op1 = gr.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST)
+ op2 = gr.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ self.tb.connect(op2, dst)
+ self.tb.run()
+
+ self.assertEqual(expected_results, dst.data())
+
+if __name__ == '__main__':
+ gr_unittest.run(test_packing, "test_packing.xml")
+
diff --git a/gr-blocks/python/qa_rms.py b/gr-blocks/python/qa_rms.py
new file mode 100644
index 000000000..f3386668a
--- /dev/null
+++ b/gr-blocks/python/qa_rms.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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 blocks_swig as blocks
+import math
+
+def sig_source_f(samp_rate, freq, amp, N):
+ t = map(lambda x: float(x)/samp_rate, xrange(N))
+ y = map(lambda x: amp*math.cos(2.*math.pi*freq*x), t)
+ return y
+
+def sig_source_c(samp_rate, freq, amp, N):
+ t = map(lambda x: float(x)/samp_rate, xrange(N))
+ y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \
+ 1j*amp*math.sin(2.*math.pi*freq*x), t)
+ return y
+
+class test_rms(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_ff(self):
+ amp = 2
+ src_data = sig_source_f(1, 0.01, amp, 200)
+ N = 750000
+
+ expected_data = amp/math.sqrt(2.0)
+
+ src = gr.vector_source_f(src_data, True)
+ head = gr.head(gr.sizeof_float, N)
+ op = blocks.rms_ff(0.0001)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect(src, head, op, dst)
+ self.tb.run()
+
+ dst_data = dst.data()
+ self.assertAlmostEqual(dst_data[-1], expected_data, 4)
+
+ def test_cf(self):
+ amp = 4
+ src_data = sig_source_c(1, 0.01, amp, 200)
+ N = 750000
+
+ expected_data = amp
+
+ src = gr.vector_source_c(src_data, True)
+ head = gr.head(gr.sizeof_gr_complex, N)
+ op = blocks.rms_cf(0.0001)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect(src, head, op, dst)
+ self.tb.run()
+
+ dst_data = dst.data()
+ self.assertAlmostEqual(dst_data[-1], expected_data, 4)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_rms, "test_rms.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 53eea818f..b229e5563 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012 Free Software Foundation, Inc.
+ * Copyright 2012-2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -27,6 +27,8 @@
//load generated python docstrings
%include "blocks_swig_doc.i"
+%include
+
%{
#include "blocks/add_ff.h"
#include "blocks/add_ss.h"
@@ -57,6 +59,7 @@
#include "blocks/complex_to_arg.h"
#include "blocks/conjugate_cc.h"
#include "blocks/deinterleave.h"
+#include "blocks/delay.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -96,10 +99,15 @@
#include "blocks/not_ss.h"
#include "blocks/not_ii.h"
#include "blocks/patterned_interleaver.h"
+#include "blocks/packed_to_unpacked_bb.h"
+#include "blocks/packed_to_unpacked_ss.h"
+#include "blocks/packed_to_unpacked_ii.h"
#include "blocks/or_bb.h"
#include "blocks/or_ss.h"
#include "blocks/or_ii.h"
#include "blocks/repeat.h"
+#include "blocks/rms_cf.h"
+#include "blocks/rms_ff.h"
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/stream_mux.h"
@@ -112,6 +120,9 @@
#include "blocks/sub_ii.h"
#include "blocks/sub_cc.h"
#include "blocks/uchar_to_float.h"
+#include "blocks/unpacked_to_packed_bb.h"
+#include "blocks/unpacked_to_packed_ss.h"
+#include "blocks/unpacked_to_packed_ii.h"
#include "blocks/vector_to_stream.h"
#include "blocks/vector_to_streams.h"
#include "blocks/xor_bb.h"
@@ -148,6 +159,7 @@
%include "blocks/complex_to_arg.h"
%include "blocks/conjugate_cc.h"
%include "blocks/deinterleave.h"
+%include "blocks/delay.h"
%include "blocks/file_source.h"
%include "blocks/file_meta_sink.h"
%include "blocks/file_meta_source.h"
@@ -187,10 +199,15 @@
%include "blocks/not_ss.h"
%include "blocks/not_ii.h"
%include "blocks/patterned_interleaver.h"
+%include "blocks/packed_to_unpacked_bb.h"
+%include "blocks/packed_to_unpacked_ss.h"
+%include "blocks/packed_to_unpacked_ii.h"
%include "blocks/or_bb.h"
%include "blocks/or_ss.h"
%include "blocks/or_ii.h"
%include "blocks/repeat.h"
+%include "blocks/rms_cf.h"
+%include "blocks/rms_ff.h"
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/stream_mux.h"
@@ -203,6 +220,9 @@
%include "blocks/sub_ii.h"
%include "blocks/sub_cc.h"
%include "blocks/uchar_to_float.h"
+%include "blocks/unpacked_to_packed_bb.h"
+%include "blocks/unpacked_to_packed_ss.h"
+%include "blocks/unpacked_to_packed_ii.h"
%include "blocks/vector_to_stream.h"
%include "blocks/vector_to_streams.h"
%include "blocks/xor_bb.h"
@@ -238,6 +258,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_arg);
GR_SWIG_BLOCK_MAGIC2(blocks, conjugate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, deinterleave);
+GR_SWIG_BLOCK_MAGIC2(blocks, delay);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
@@ -277,10 +298,15 @@ GR_SWIG_BLOCK_MAGIC2(blocks, not_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, not_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, not_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver);
+GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, or_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, or_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, or_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, repeat);
+GR_SWIG_BLOCK_MAGIC2(blocks, rms_cf);
+GR_SWIG_BLOCK_MAGIC2(blocks, rms_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux);
@@ -293,6 +319,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_stream);
GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_streams);
GR_SWIG_BLOCK_MAGIC2(blocks, xor_bb);
--
cgit
From 2fcf27f95b10d84dbe0e2b36a316c6ed87dc8739 Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Thu, 21 Feb 2013 19:48:41 -0500
Subject: blocks: fixing use of packed/unpacked from gr-blocks in QA code.
---
gr-blocks/python/qa_packed_to_unpacked.py | 56 +++++++++++++++----------------
1 file changed, 28 insertions(+), 28 deletions(-)
(limited to 'gr-blocks')
diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py
index 98a02e78f..d84f5dbd3 100755
--- a/gr-blocks/python/qa_packed_to_unpacked.py
+++ b/gr-blocks/python/qa_packed_to_unpacked.py
@@ -62,7 +62,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (0x11,)
expected_results = (4, 2)
src = gr.vector_source_b(src_data, False)
- op = gr.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST)
+ op = blocks.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -75,7 +75,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (0x11,)
expected_results = (0, 4)
src = gr.vector_source_b(src_data, False)
- op = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
+ op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -88,7 +88,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0)
expected_results = (0x82, 0x5a)
src = gr.vector_source_b(src_data, False)
- op = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
+ op = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -101,7 +101,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0)
expected_results = (0x82, 0x5a)
src = gr.vector_source_b(src_data, False)
- op = gr.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
+ op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -114,7 +114,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (4, 2, 0,0,0)
expected_results = (0x11,)
src = gr.vector_source_b(src_data, False)
- op = gr.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST)
+ op = blocks.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -127,7 +127,7 @@ class test_packing(gr_unittest.TestCase):
src_data = (0, 4, 2,0,0)
expected_results = (0x11,)
src = gr.vector_source_b(src_data,False)
- op = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
+ op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op)
@@ -145,8 +145,8 @@ class test_packing(gr_unittest.TestCase):
expected_results = src_data
src = gr.vector_source_b(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op1, op2)
@@ -163,8 +163,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_b(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op1, op2)
@@ -181,8 +181,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_b(tuple(src_data),False)
- op1 = gr.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
- op2 = gr.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
+ op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
+ op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
dst = gr.vector_sink_b()
self.tb.connect(src, op1, op2)
@@ -201,8 +201,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_s(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST)
dst = gr.vector_sink_s()
self.tb.connect(src, op1, op2)
@@ -219,8 +219,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_s(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST)
- op2 = gr.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST)
dst = gr.vector_sink_s()
self.tb.connect(src, op1, op2)
@@ -237,8 +237,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_s(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST)
dst = gr.vector_sink_s()
self.tb.connect(src, op1, op2)
@@ -255,8 +255,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_s(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST)
- op2 = gr.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST)
dst = gr.vector_sink_s()
self.tb.connect(src, op1, op2)
@@ -275,8 +275,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_i(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST)
dst = gr.vector_sink_i()
self.tb.connect(src, op1, op2)
@@ -293,8 +293,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_i(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST)
- op2 = gr.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST)
dst = gr.vector_sink_i()
self.tb.connect(src, op1, op2)
@@ -311,8 +311,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_i(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST)
- op2 = gr.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST)
dst = gr.vector_sink_i()
self.tb.connect(src, op1, op2)
@@ -329,8 +329,8 @@ class test_packing(gr_unittest.TestCase):
src_data = tuple(src_data)
expected_results = src_data
src = gr.vector_source_i(tuple(src_data), False)
- op1 = gr.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST)
- op2 = gr.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST)
+ op1 = blocks.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST)
+ op2 = blocks.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST)
dst = gr.vector_sink_i()
self.tb.connect(src, op1, op2)
--
cgit
From ffcaa3436cc8e608cb51bad78ca669b90bd110f2 Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Sun, 24 Feb 2013 14:15:05 -0500
Subject: blocks: converted peak_detector2 and regenerate to v3.7.
---
gr-blocks/grc/blocks_peak_detector2_fb.xml | 41 ++++++++++
gr-blocks/grc/blocks_regenerate_bb.xml | 34 ++++++++
gr-blocks/include/blocks/CMakeLists.txt | 2 +
gr-blocks/include/blocks/peak_detector2_fb.h | 91 +++++++++++++++++++++
gr-blocks/include/blocks/regenerate_bb.h | 80 ++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 2 +
gr-blocks/lib/peak_detector2_fb_impl.cc | 118 +++++++++++++++++++++++++++
gr-blocks/lib/peak_detector2_fb_impl.h | 64 +++++++++++++++
gr-blocks/lib/regenerate_bb_impl.cc | 103 +++++++++++++++++++++++
gr-blocks/lib/regenerate_bb_impl.h | 57 +++++++++++++
gr-blocks/python/qa_peak_detector2.py | 58 +++++++++++++
gr-blocks/python/qa_regenerate.py | 90 ++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 6 ++
13 files changed, 746 insertions(+)
create mode 100644 gr-blocks/grc/blocks_peak_detector2_fb.xml
create mode 100644 gr-blocks/grc/blocks_regenerate_bb.xml
create mode 100644 gr-blocks/include/blocks/peak_detector2_fb.h
create mode 100644 gr-blocks/include/blocks/regenerate_bb.h
create mode 100644 gr-blocks/lib/peak_detector2_fb_impl.cc
create mode 100644 gr-blocks/lib/peak_detector2_fb_impl.h
create mode 100644 gr-blocks/lib/regenerate_bb_impl.cc
create mode 100644 gr-blocks/lib/regenerate_bb_impl.h
create mode 100644 gr-blocks/python/qa_peak_detector2.py
create mode 100755 gr-blocks/python/qa_regenerate.py
(limited to 'gr-blocks')
diff --git a/gr-blocks/grc/blocks_peak_detector2_fb.xml b/gr-blocks/grc/blocks_peak_detector2_fb.xml
new file mode 100644
index 000000000..584e7a1fb
--- /dev/null
+++ b/gr-blocks/grc/blocks_peak_detector2_fb.xml
@@ -0,0 +1,41 @@
+
+
+
+ Peak Detector2
+ blocks_peak_detector2_fb
+ from gnuradio import blocks
+ blocks.peak_detector2_fb($threshold_factor_rise, $look_ahead, $alpha)
+ set_threshold_factor_rise($threshold_factor_rise)
+ set_look_ahead($look_ahead)
+ set_alpha($alpha)
+
+ TH Factor Rise
+ threshold_factor_rise
+ 7
+ real
+
+
+ Look Ahead
+ look_ahead
+ 1000
+ int
+
+
+ Alpha
+ alpha
+ 0.001
+ real
+
+
+ in
+ float
+
+
+
diff --git a/gr-blocks/grc/blocks_regenerate_bb.xml b/gr-blocks/grc/blocks_regenerate_bb.xml
new file mode 100644
index 000000000..6e6f46188
--- /dev/null
+++ b/gr-blocks/grc/blocks_regenerate_bb.xml
@@ -0,0 +1,34 @@
+
+
+
+ Regenerate
+ blocks_regenerate_bb
+ from gnuradio import blocks
+ blocks.regenerate_bb($period, $max_regen)
+
+ Period
+ period
+ int
+
+
+ Max Regen Count
+ max_regen
+ 500
+ int
+
+
+ in
+ byte
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index a6608696a..cd2fea672 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -126,6 +126,8 @@ install(FILES
multiply_const_ff.h
nlog10_ff.h
patterned_interleaver.h
+ peak_detector2_fb.h
+ regenerate_bb.h
repeat.h
rms_cf.h
rms_ff.h
diff --git a/gr-blocks/include/blocks/peak_detector2_fb.h b/gr-blocks/include/blocks/peak_detector2_fb.h
new file mode 100644
index 000000000..71afc3287
--- /dev/null
+++ b/gr-blocks/include/blocks/peak_detector2_fb.h
@@ -0,0 +1,91 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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_PEAK_DETECTOR2_FB_H
+#define INCLUDED_GR_PEAK_DETECTOR2_FB_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Detect the peak of a signal
+ * \ingroup level_blk
+ *
+ * If a peak is detected, this block outputs a 1, or it outputs
+ * 0's. A separate debug output may be connected, to view the
+ * internal EWMA described below.
+ *
+ * \param threshold_factor_rise The threshold factor determins
+ * when a peak is present. An EWMA average of the signal is
+ * calculated and when the value of the signal goes over
+ * threshold_factor_rise*average, we call the peak.
+ * \param look_ahead The look-ahead value is used when the
+ * threshold is found to locate the peak within this range.
+ * \param alpha The gain value of a single-pole moving average filter.
+ */
+ class BLOCKS_API peak_detector2_fb : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::peak_detector2_fb::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(float threshold_factor_rise=7,
+ int look_ahead=1000, float alpha=0.001);
+
+ /*! \brief Set the threshold factor value for the rise time
+ * \param thr new threshold factor
+ */
+ virtual void set_threshold_factor_rise(float thr) = 0;
+
+ /*! \brief Set the look-ahead factor
+ * \param look new look-ahead factor
+ */
+ virtual void set_look_ahead(int look) = 0;
+
+ /*! \brief Set the running average alpha
+ * \param alpha new alpha for running average
+ */
+ virtual void set_alpha(int alpha) = 0;
+
+ /*! \brief Get the threshold factor value for the rise time
+ * \return threshold factor
+ */
+ virtual float threshold_factor_rise() = 0;
+
+ /*! \brief Get the look-ahead factor value
+ * \return look-ahead factor
+ */
+ virtual int look_ahead() = 0;
+
+ /*! \brief Get the alpha value of the running average
+ * \return alpha
+ */
+ virtual float alpha() = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_H */
diff --git a/gr-blocks/include/blocks/regenerate_bb.h b/gr-blocks/include/blocks/regenerate_bb.h
new file mode 100644
index 000000000..3063e70a7
--- /dev/null
+++ b/gr-blocks/include/blocks/regenerate_bb.h
@@ -0,0 +1,80 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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_REGENERATE_BB_H
+#define INCLUDED_GR_REGENERATE_BB_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Detect the peak of a signal and repeat every period samples
+ * \ingroup level_blk
+ *
+ * If a peak is detected, this block outputs a 1 repeated every
+ * period samples until reset by detection of another 1 on the
+ * input or stopped after max_regen regenerations have occurred.
+ *
+ * Note that if max_regen=(-1)/ULONG_MAX then the regeneration
+ * will run forever.
+ */
+ class BLOCKS_API regenerate_bb : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::regenerate_bb::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make a regenerate block
+ * \param period The number of samples between regenerations
+ * \param max_regen The maximum number of regenerations to
+ * perform; if set to ULONG_MAX, it will regenerate
+ * continuously.
+ */
+ static sptr make(int period, unsigned int max_regen=500);
+
+ /*! \brief Reset the maximum regeneration count; this will reset
+ the current regen.
+ */
+ virtual void set_max_regen(unsigned int regen) = 0;
+
+ /*! \brief Reset the period of regenerations; this will reset
+ the current regen.
+ */
+ virtual void set_period(int period) = 0;
+
+ /*! \brief return the maximum regeneration count.
+ */
+ virtual unsigned int max_regen() const = 0;
+
+ /*! \brief return the regeneration period.
+ */
+ virtual int period() const = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_REGENERATE_BB_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 9b076f696..aa87d9c64 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -165,6 +165,8 @@ list(APPEND gr_blocks_sources
multiply_const_ff_impl.cc
nlog10_ff_impl.cc
patterned_interleaver_impl.cc
+ peak_detector2_fb_impl.cc
+ regenerate_bb_impl.cc
repeat_impl.cc
rms_cf_impl.cc
rms_ff_impl.cc
diff --git a/gr-blocks/lib/peak_detector2_fb_impl.cc b/gr-blocks/lib/peak_detector2_fb_impl.cc
new file mode 100644
index 000000000..0d375c3ba
--- /dev/null
+++ b/gr-blocks/lib/peak_detector2_fb_impl.cc
@@ -0,0 +1,118 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2010,2013 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 "peak_detector2_fb_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ peak_detector2_fb::sptr
+ peak_detector2_fb::make(float threshold_factor_rise,
+ int look_ahead, float alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new peak_detector2_fb_impl(threshold_factor_rise,
+ look_ahead, alpha));
+ }
+
+ peak_detector2_fb_impl::peak_detector2_fb_impl(float threshold_factor_rise,
+ int look_ahead, float alpha)
+ : gr_sync_block("peak_detector2_fb",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature2(1, 2, sizeof(char), sizeof(float))),
+ d_threshold_factor_rise(threshold_factor_rise),
+ d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false)
+ {
+ }
+
+ peak_detector2_fb_impl::~peak_detector2_fb_impl()
+ {
+ }
+
+ int
+ peak_detector2_fb_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ float *iptr = (float *)input_items[0];
+ char *optr = (char *)output_items[0];
+
+ assert(noutput_items >= 2);
+
+ memset(optr, 0, noutput_items*sizeof(char));
+
+ for(int i = 0; i < noutput_items; i++) {
+ if(!d_found) {
+ // Have not yet detected presence of peak
+ if(iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) {
+ d_found = true;
+ d_look_ahead_remaining = d_look_ahead;
+ d_peak_val = -(float)INFINITY;
+ }
+ else {
+ d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg;
+ }
+ }
+ else {
+ // Detected presence of peak
+ if(iptr[i] > d_peak_val) {
+ d_peak_val = iptr[i];
+ d_peak_ind = i;
+ }
+ else if(d_look_ahead_remaining <= 0) {
+ optr[d_peak_ind] = 1;
+ d_found = false;
+ d_avg = iptr[i];
+ }
+
+ // Have not yet located peak, loop and keep searching.
+ d_look_ahead_remaining--;
+ }
+
+ // Every iteration of the loop, write debugging signal out if
+ // connected:
+ if(output_items.size() == 2) {
+ float *sigout = (float *)output_items[1];
+ sigout[i] = d_avg;
+ }
+ } // loop
+
+ if(!d_found)
+ return noutput_items;
+
+ // else if detected presence, keep searching during the next call to work.
+ int tmp = d_peak_ind;
+ d_peak_ind = 1;
+
+ return tmp - 1;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
diff --git a/gr-blocks/lib/peak_detector2_fb_impl.h b/gr-blocks/lib/peak_detector2_fb_impl.h
new file mode 100644
index 000000000..f03dd36a8
--- /dev/null
+++ b/gr-blocks/lib/peak_detector2_fb_impl.h
@@ -0,0 +1,64 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2013 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_PEAK_DETECTOR2_FB_IMPL_H
+#define INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class peak_detector2_fb_impl : public peak_detector2_fb
+ {
+ private:
+ float d_threshold_factor_rise;
+ int d_look_ahead;
+ int d_look_ahead_remaining;
+ int d_peak_ind;
+ float d_peak_val;
+ float d_alpha;
+ float d_avg;
+ bool d_found;
+
+ public:
+ peak_detector2_fb_impl(float threshold_factor_rise,
+ int look_ahead, float alpha);
+ ~peak_detector2_fb_impl();
+
+ void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; }
+ void set_look_ahead(int look) { d_look_ahead = look; }
+ void set_alpha(int alpha) { d_alpha = alpha; }
+
+ float threshold_factor_rise() { return d_threshold_factor_rise; }
+ int look_ahead() { return d_look_ahead; }
+ float alpha() { return d_alpha; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H */
diff --git a/gr-blocks/lib/regenerate_bb_impl.cc b/gr-blocks/lib/regenerate_bb_impl.cc
new file mode 100644
index 000000000..4472efb6d
--- /dev/null
+++ b/gr-blocks/lib/regenerate_bb_impl.cc
@@ -0,0 +1,103 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2010,2013 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 "regenerate_bb_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ regenerate_bb::sptr
+ regenerate_bb::make(int period, unsigned int max_regen)
+ {
+ return gnuradio::get_initial_sptr
+ (new regenerate_bb_impl(period, max_regen));
+ }
+
+ regenerate_bb_impl::regenerate_bb_impl(int period, unsigned int max_regen)
+ : gr_sync_block("regenerate_bb",
+ gr_make_io_signature(1, 1, sizeof(char)),
+ gr_make_io_signature(1, 1, sizeof(char))),
+ d_period(period),
+ d_countdown(0),
+ d_max_regen(max_regen),
+ d_regen_count(max_regen)
+ {
+ }
+
+ regenerate_bb_impl::~regenerate_bb_impl()
+ {
+ }
+
+ void
+ regenerate_bb_impl::set_max_regen(unsigned int regen)
+ {
+ d_max_regen = regen;
+ d_countdown = 0;
+ d_regen_count = d_max_regen;
+ }
+
+ void
+ regenerate_bb_impl::set_period(int period)
+ {
+ d_period = period;
+ d_countdown = 0;
+ d_regen_count = d_max_regen;
+ }
+
+ int
+ regenerate_bb_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const char *iptr = (const char *)input_items[0];
+ char *optr = (char *)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ optr[i] = 0;
+
+ if(d_regen_count < d_max_regen) {
+ d_countdown--;
+
+ if(d_countdown == 0) {
+ optr[i] = 1;
+ d_countdown = d_period;
+ d_regen_count++;
+ }
+ }
+
+ if(iptr[i] == 1) {
+ d_countdown = d_period;
+ optr[i] = 1;
+ d_regen_count = 0;
+ }
+
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/regenerate_bb_impl.h b/gr-blocks/lib/regenerate_bb_impl.h
new file mode 100644
index 000000000..bcfa18391
--- /dev/null
+++ b/gr-blocks/lib/regenerate_bb_impl.h
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2012-2013 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_REGENERATE_BB_H
+#define INCLUDED_GR_REGENERATE_BB_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class regenerate_bb_impl : public regenerate_bb
+ {
+ private:
+ int d_period;
+ int d_countdown;
+ unsigned int d_max_regen;
+ unsigned int d_regen_count;
+
+ public:
+ regenerate_bb_impl(int period, unsigned int max_regen=500);
+ ~regenerate_bb_impl();
+
+ void set_max_regen(unsigned int regen);
+ void set_period(int period);
+
+ unsigned int max_regen() const { return d_max_regen; };
+ int period() const { return d_period; };
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_REGENERATE_BB_IMPL_H */
diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py
new file mode 100644
index 000000000..4b864e4d7
--- /dev/null
+++ b/gr-blocks/python/qa_peak_detector2.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+# Copyright 2007,2010,2013 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 blocks_swig as blocks
+
+class test_peak_detector2(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_regen1(self):
+ tb = self.tb
+
+ data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+
+ expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+
+ src = gr.vector_source_f(data, False)
+ regen = blocks.peak_detector2_fb()
+ dst = gr.vector_sink_b()
+
+ tb.connect(src, regen)
+ tb.connect(regen, dst)
+ tb.run()
+
+ dst_data = dst.data()
+ print dst_data
+
+ self.assertEqual(expected_result, dst_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_peak_detector2, "test_peak_detector2.xml")
diff --git a/gr-blocks/python/qa_regenerate.py b/gr-blocks/python/qa_regenerate.py
new file mode 100755
index 000000000..a57eeba2b
--- /dev/null
+++ b/gr-blocks/python/qa_regenerate.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+#
+# Copyright 2007,2010,2013 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 blocks_swig as blocks
+
+class test_regenerate(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_regen1(self):
+ tb = self.tb
+
+ data = [0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+
+ expected_result = (0, 0, 0,
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+
+ src = gr.vector_source_b(data, False)
+ regen = blocks.regenerate_bb(5, 2)
+ dst = gr.vector_sink_b()
+
+ tb.connect(src, regen)
+ tb.connect(regen, dst)
+ tb.run()
+
+ dst_data = dst.data()
+
+ self.assertEqual(expected_result, dst_data)
+
+ def test_regen2(self):
+ tb = self.tb
+
+ data = 200*[0,]
+ data[9] = 1
+ data[99] = 1
+
+ expected_result = 200*[0,]
+ expected_result[9] = 1
+ expected_result[19] = 1
+ expected_result[29] = 1
+ expected_result[39] = 1
+
+ expected_result[99] = 1
+ expected_result[109] = 1
+ expected_result[119] = 1
+ expected_result[129] = 1
+
+ src = gr.vector_source_b(data, False)
+ regen = blocks.regenerate_bb(10, 3)
+ dst = gr.vector_sink_b()
+
+ tb.connect(src, regen)
+ tb.connect(regen, dst)
+ tb.run ()
+
+ dst_data = dst.data()
+
+ self.assertEqual(tuple(expected_result), dst_data)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_regenerate, "test_regenerate.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index b229e5563..114142cbf 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -102,9 +102,11 @@
#include "blocks/packed_to_unpacked_bb.h"
#include "blocks/packed_to_unpacked_ss.h"
#include "blocks/packed_to_unpacked_ii.h"
+#include "blocks/peak_detector2_fb.h"
#include "blocks/or_bb.h"
#include "blocks/or_ss.h"
#include "blocks/or_ii.h"
+#include "blocks/regenerate_bb.h"
#include "blocks/repeat.h"
#include "blocks/rms_cf.h"
#include "blocks/rms_ff.h"
@@ -202,9 +204,11 @@
%include "blocks/packed_to_unpacked_bb.h"
%include "blocks/packed_to_unpacked_ss.h"
%include "blocks/packed_to_unpacked_ii.h"
+%include "blocks/peak_detector2_fb.h"
%include "blocks/or_bb.h"
%include "blocks/or_ss.h"
%include "blocks/or_ii.h"
+%include "blocks/regenerate_bb.h"
%include "blocks/repeat.h"
%include "blocks/rms_cf.h"
%include "blocks/rms_ff.h"
@@ -301,9 +305,11 @@ GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver);
GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector2_fb);
GR_SWIG_BLOCK_MAGIC2(blocks, or_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, or_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, or_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, regenerate_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, repeat);
GR_SWIG_BLOCK_MAGIC2(blocks, rms_cf);
GR_SWIG_BLOCK_MAGIC2(blocks, rms_ff);
--
cgit
From a54dc5bab6cc38513e9732be9f5c2670145b160f Mon Sep 17 00:00:00 2001
From: Tom Rondeau
Date: Sun, 24 Feb 2013 18:55:04 -0500
Subject: blocks: adding threshold, strech, and throttle to gr-blocks.
---
gr-blocks/grc/blocks_block_tree.xml | 8 +++
gr-blocks/grc/blocks_regenerate_bb.xml | 2 -
gr-blocks/grc/blocks_stretch_ff.xml | 34 ++++++++++++
gr-blocks/grc/blocks_threshold_ff.xml | 40 ++++++++++++++
gr-blocks/grc/blocks_throttle.xml | 67 +++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 3 +
gr-blocks/include/blocks/stretch_ff.h | 59 ++++++++++++++++++++
gr-blocks/include/blocks/threshold_ff.h | 66 ++++++++++++++++++++++
gr-blocks/include/blocks/throttle.h | 62 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 3 +
gr-blocks/lib/stretch_ff_impl.cc | 84 ++++++++++++++++++++++++++++
gr-blocks/lib/stretch_ff_impl.h | 53 ++++++++++++++++++
gr-blocks/lib/threshold_ff_impl.cc | 78 ++++++++++++++++++++++++++
gr-blocks/lib/threshold_ff_impl.h | 57 +++++++++++++++++++
gr-blocks/lib/throttle_impl.cc | 97 +++++++++++++++++++++++++++++++++
gr-blocks/lib/throttle_impl.h | 54 ++++++++++++++++++
gr-blocks/python/qa_stretch.py | 67 +++++++++++++++++++++++
gr-blocks/python/qa_threshold.py | 54 ++++++++++++++++++
gr-blocks/python/qa_throttle.py | 39 +++++++++++++
gr-blocks/swig/blocks_swig.i | 9 +++
20 files changed, 934 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/grc/blocks_stretch_ff.xml
create mode 100644 gr-blocks/grc/blocks_threshold_ff.xml
create mode 100644 gr-blocks/grc/blocks_throttle.xml
create mode 100644 gr-blocks/include/blocks/stretch_ff.h
create mode 100644 gr-blocks/include/blocks/threshold_ff.h
create mode 100644 gr-blocks/include/blocks/throttle.h
create mode 100644 gr-blocks/lib/stretch_ff_impl.cc
create mode 100644 gr-blocks/lib/stretch_ff_impl.h
create mode 100644 gr-blocks/lib/threshold_ff_impl.cc
create mode 100644 gr-blocks/lib/threshold_ff_impl.h
create mode 100644 gr-blocks/lib/throttle_impl.cc
create mode 100644 gr-blocks/lib/throttle_impl.h
create mode 100755 gr-blocks/python/qa_stretch.py
create mode 100644 gr-blocks/python/qa_threshold.py
create mode 100755 gr-blocks/python/qa_throttle.py
(limited to 'gr-blocks')
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 6b17078cd..6ab84c94e 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -98,5 +98,13 @@
blocks_streams_to_vectorblocks_vector_to_streamblocks_vector_to_streams
+ blocks_peak_detector2_fb
+ blocks_regenerate_bb
+ blocks_stretch_ff
+ blocks_threadhold_ff
+
+
+ Misc (New)
+ blocks_throttle
diff --git a/gr-blocks/grc/blocks_regenerate_bb.xml b/gr-blocks/grc/blocks_regenerate_bb.xml
index 6e6f46188..bbee53387 100644
--- a/gr-blocks/grc/blocks_regenerate_bb.xml
+++ b/gr-blocks/grc/blocks_regenerate_bb.xml
@@ -24,11 +24,9 @@
inbyte
- $vlen
diff --git a/gr-blocks/grc/blocks_stretch_ff.xml b/gr-blocks/grc/blocks_stretch_ff.xml
new file mode 100644
index 000000000..00a67602b
--- /dev/null
+++ b/gr-blocks/grc/blocks_stretch_ff.xml
@@ -0,0 +1,34 @@
+
+
+
+ Stretch
+ blocks_stretch_ff
+ from gnuradio import blocks
+ blocks.stretch_ff($lo, $vlen)
+
+ Low
+ lo
+ real
+
+
+ Vec. Length
+ vlen
+ 1
+ int
+
+
+ in
+ float
+ $vlen
+
+
+
diff --git a/gr-blocks/grc/blocks_threshold_ff.xml b/gr-blocks/grc/blocks_threshold_ff.xml
new file mode 100644
index 000000000..0da4157fc
--- /dev/null
+++ b/gr-blocks/grc/blocks_threshold_ff.xml
@@ -0,0 +1,40 @@
+
+
+
+ Threshold
+ blocks_threshold_ff
+ from gnuradio import blocks
+ blocks.threshold_ff($low, $high, $init)
+ set_hi($high)
+ set_lo($low)
+
+ Low
+ low
+ -100
+ real
+
+
+ High
+ high
+ 100
+ real
+
+
+ Initial State
+ init
+ 0
+ real
+
+
+ in
+ float
+
+
+
diff --git a/gr-blocks/grc/blocks_throttle.xml b/gr-blocks/grc/blocks_throttle.xml
new file mode 100644
index 000000000..8293cbde9
--- /dev/null
+++ b/gr-blocks/grc/blocks_throttle.xml
@@ -0,0 +1,67 @@
+
+
+
+ Throttle
+ blocks_throttle
+ 1
+ from gnuradio import blocks
+ blocks.throttle($type.size*$vlen, $samples_per_second)
+ set_sample_rate($samples_per_second)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ Sample Rate
+ samples_per_second
+ samp_rate
+ real
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index cd2fea672..8d5fe9b13 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -138,6 +138,9 @@ install(FILES
stream_to_vector.h
streams_to_stream.h
streams_to_vector.h
+ stretch_ff.h
+ threshold_ff.h
+ throttle.h
uchar_to_float.h
vector_to_stream.h
vector_to_streams.h
diff --git a/gr-blocks/include/blocks/stretch_ff.h b/gr-blocks/include/blocks/stretch_ff.h
new file mode 100644
index 000000000..5f98452a4
--- /dev/null
+++ b/gr-blocks/include/blocks/stretch_ff.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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_STRETCH_FF_H
+#define INCLUDED_GR_STRETCH_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief adjust y-range of an input vector by mapping to range
+ * (max-of-input, stipulated-min). Primarily for spectral
+ * signature matching by normalizing spectrum dynamic ranges.
+ * \ingroup misc_blk
+ */
+ class BLOCKS_API stretch_ff : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::stretch_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make a stretch block.
+ * \param lo Set low value for range.
+ * \param vlen vector length of input stream.
+ */
+ static sptr make(float lo, size_t vlen=1);
+
+ virtual float lo() const = 0;
+ virtual void set_lo(float lo) = 0;
+ virtual size_t vlen() const = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_STRETCH_FF_H */
diff --git a/gr-blocks/include/blocks/threshold_ff.h b/gr-blocks/include/blocks/threshold_ff.h
new file mode 100644
index 000000000..900e5c5bd
--- /dev/null
+++ b/gr-blocks/include/blocks/threshold_ff.h
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2013 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_THRESHOLD_FF_H
+#define INCLUDED_GR_THRESHOLD_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Output a 1 or zero based on a threshold value.
+ * \ingroup misc_blk
+ *
+ * Test the incoming signal against a threshold. If the signal
+ * excedes the \p hi value, it will output a 1 until the signal
+ * falls below the \p lo value.
+ */
+ class BLOCKS_API threshold_ff : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::threshold_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /* \brief Create a threadshold block.
+ * \param lo Threshold input signal needs to drop below to
+ * change state to 0.
+ * \param hi Threshold input signal needs to rise above to
+ * change state to 1.
+ * \param initial_state Initial state of the block (0 or 1).
+ */
+ static sptr make(float lo, float hi, float initial_state=0);
+
+ virtual float lo () const = 0;
+ virtual void set_lo (float lo) = 0;
+ virtual float hi () const = 0;
+ virtual void set_hi (float hi) = 0;
+ virtual float last_state () const = 0;
+ virtual void set_last_state (float last_state) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_THRESHOLD_FF_H */
diff --git a/gr-blocks/include/blocks/throttle.h b/gr-blocks/include/blocks/throttle.h
new file mode 100644
index 000000000..20d8037e1
--- /dev/null
+++ b/gr-blocks/include/blocks/throttle.h
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005-2011,2013 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_THROTTLE_H
+#define INCLUDED_GR_THROTTLE_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief throttle flow of samples such that the average rate does
+ * not exceed samples_per_sec.
+ * \ingroup misc_blk
+ *
+ * input: one stream of itemsize; output: one stream of itemsize
+ *
+ * N.B. this should only be used in GUI apps where there is no
+ * other rate limiting block. It is not intended nor effective at
+ * precisely controlling the rate of samples. That should be
+ * controlled by a source or sink tied to sample clock. E.g., a
+ * USRP or audio card.
+ */
+ class BLOCKS_API throttle : virtual public gr_sync_block
+ {
+ public:
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, double samples_per_sec);
+
+ //! Sets the sample rate in samples per second.
+ virtual void set_sample_rate(double rate) = 0;
+
+ //! Get the sample rate in samples per second.
+ virtual double sample_rate() const = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_THROTTLE_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index aa87d9c64..e1b9b4f00 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -177,6 +177,9 @@ list(APPEND gr_blocks_sources
stream_to_vector_impl.cc
streams_to_stream_impl.cc
streams_to_vector_impl.cc
+ stretch_ff_impl.cc
+ threshold_ff_impl.cc
+ throttle_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
vector_to_stream_impl.cc
diff --git a/gr-blocks/lib/stretch_ff_impl.cc b/gr-blocks/lib/stretch_ff_impl.cc
new file mode 100644
index 000000000..90bbc7ee5
--- /dev/null
+++ b/gr-blocks/lib/stretch_ff_impl.cc
@@ -0,0 +1,84 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2010,2013 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 "stretch_ff_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ stretch_ff::sptr
+ stretch_ff::make(float lo, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr
+ (new stretch_ff_impl(lo, vlen));
+ }
+
+ stretch_ff_impl::stretch_ff_impl(float lo, size_t vlen)
+ : gr_sync_block("stretch_ff",
+ gr_make_io_signature(1, 1, vlen * sizeof(float)),
+ gr_make_io_signature(1, 1, vlen * sizeof(float))),
+ d_lo(lo), d_vlen(vlen)
+ {
+ }
+
+ stretch_ff_impl::~stretch_ff_impl()
+ {
+ }
+
+ int
+ stretch_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *)input_items[0];
+ float *out = (float *)output_items[0];
+
+ for(int count = 0; count < noutput_items; count++) {
+ float vmax = in[0] - d_lo;
+
+ for(unsigned int i = 1; i < d_vlen; i++) {
+ float vtmp = in[i] - d_lo;
+ if(vtmp > vmax)
+ vmax = vtmp;
+ }
+
+ if(vmax != 0.0)
+ for(unsigned int i = 0; i < d_vlen; i++)
+ out[i] = d_lo * (1.0 - (in[i] - d_lo) / vmax);
+ else
+ for(unsigned int i = 0; i < d_vlen; i++)
+ out[i] = in[i];
+
+ in += d_vlen;
+ out += d_vlen;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stretch_ff_impl.h b/gr-blocks/lib/stretch_ff_impl.h
new file mode 100644
index 000000000..af69d835a
--- /dev/null
+++ b/gr-blocks/lib/stretch_ff_impl.h
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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_STRETCH_FF_IMPL_H
+#define INCLUDED_GR_STRETCH_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class stretch_ff_impl : public stretch_ff
+ {
+ private:
+ float d_lo; // the constant
+ size_t d_vlen;
+
+ public:
+ stretch_ff_impl(float lo, size_t vlen);
+ ~stretch_ff_impl();
+
+ float lo() const { return d_lo; }
+ void set_lo(float lo) { d_lo = lo; }
+ size_t vlen() const { return d_vlen; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_STRETCH_FF_IMPL_H */
diff --git a/gr-blocks/lib/threshold_ff_impl.cc b/gr-blocks/lib/threshold_ff_impl.cc
new file mode 100644
index 000000000..477f2b1c8
--- /dev/null
+++ b/gr-blocks/lib/threshold_ff_impl.cc
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010,2013 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 "threshold_ff_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ threshold_ff::sptr
+ threshold_ff::make(float lo, float hi, float initial_state)
+ {
+ return gnuradio::get_initial_sptr
+ (new threshold_ff_impl(lo, hi, initial_state));
+ }
+
+ threshold_ff_impl::threshold_ff_impl(float lo, float hi,
+ float initial_state)
+ : gr_sync_block("threshold_ff",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_lo(lo), d_hi(hi), d_last_state(initial_state)
+ {
+ }
+
+ threshold_ff_impl::~threshold_ff_impl()
+ {
+ }
+
+ int
+ threshold_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *)input_items[0];
+ float *out = (float *)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ if(in[i] > d_hi) {
+ out[i] = 1.0;
+ d_last_state = 1.0;
+ }
+ else if(in[i] < d_lo) {
+ out[i] = 0.0;
+ d_last_state = 0.0;
+ }
+ else
+ out[i] = d_last_state;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/threshold_ff_impl.h b/gr-blocks/lib/threshold_ff_impl.h
new file mode 100644
index 000000000..41afaa52a
--- /dev/null
+++ b/gr-blocks/lib/threshold_ff_impl.h
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2013 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_THRESHOLD_FF_IMPL_H
+#define INCLUDED_GR_THRESHOLD_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class threshold_ff_impl : public threshold_ff
+ {
+ private:
+ float d_lo, d_hi; // the constant
+ float d_last_state;
+
+ public:
+ threshold_ff_impl(float lo, float hi,
+ float initial_state=0);
+ ~threshold_ff_impl();
+
+ float lo() const { return d_lo; }
+ void set_lo(float lo) { d_lo = lo; }
+ float hi() const { return d_hi; }
+ void set_hi(float hi) { d_hi = hi; }
+ float last_state() const { return d_last_state; }
+ void set_last_state(float last_state) { d_last_state = last_state; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_THRESHOLD_FF_IMPL_H */
diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc
new file mode 100644
index 000000000..49743e3f2
--- /dev/null
+++ b/gr-blocks/lib/throttle_impl.cc
@@ -0,0 +1,97 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005-2011 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 "throttle_impl.h"
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ throttle::sptr
+ throttle::make(size_t itemsize, double samples_per_sec)
+ {
+ return gnuradio::get_initial_sptr
+ (new throttle_impl(itemsize, samples_per_sec));
+ }
+
+ throttle_impl::throttle_impl(size_t itemsize,
+ double samples_per_second)
+ : gr_sync_block("throttle",
+ gr_make_io_signature(1, 1, itemsize),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize)
+ {
+ set_sample_rate(samples_per_second);
+ }
+
+ throttle_impl::~throttle_impl()
+ {
+ }
+
+ void
+ throttle_impl::set_sample_rate(double rate)
+ {
+ //changing the sample rate performs a reset of state params
+ d_start = boost::get_system_time();
+ d_total_samples = 0;
+ d_samps_per_tick = rate/boost::posix_time::time_duration::ticks_per_second();
+ d_samps_per_us = rate/1e6;
+ }
+
+ double
+ throttle_impl::sample_rate() const
+ {
+ return d_samps_per_us * 1e6;
+ }
+
+ int
+ throttle_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ //calculate the expected number of samples to have passed through
+ boost::system_time now = boost::get_system_time();
+ boost::int64_t ticks = (now - d_start).ticks();
+ uint64_t expected_samps = uint64_t(d_samps_per_tick*ticks);
+
+ //if the expected samples was less, we need to throttle back
+ if(d_total_samples > expected_samps) {
+ boost::this_thread::sleep(boost::posix_time::microseconds
+ (long((d_total_samples - expected_samps)/d_samps_per_us)));
+ }
+
+ //copy all samples output[i] <= input[i]
+ const char *in = (const char *)input_items[0];
+ char *out = (char *)output_items[0];
+ std::memcpy(out, in, noutput_items * d_itemsize);
+ d_total_samples += noutput_items;
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/throttle_impl.h b/gr-blocks/lib/throttle_impl.h
new file mode 100644
index 000000000..86dbef2ac
--- /dev/null
+++ b/gr-blocks/lib/throttle_impl.h
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005-2011,2013 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_THROTTLE_IMPL_H
+#define INCLUDED_GR_THROTTLE_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class throttle_impl : public throttle
+ {
+ private:
+ boost::system_time d_start;
+ size_t d_itemsize;
+ uint64_t d_total_samples;
+ double d_samps_per_tick, d_samps_per_us;
+
+ public:
+ throttle_impl(size_t itemsize, double samples_per_sec);
+ ~throttle_impl();
+
+ void set_sample_rate(double rate);
+ double sample_rate() const;
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_THROTTLE_IMPL_H */
diff --git a/gr-blocks/python/qa_stretch.py b/gr-blocks/python/qa_stretch.py
new file mode 100755
index 000000000..013d878a8
--- /dev/null
+++ b/gr-blocks/python/qa_stretch.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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 blocks_swig as blocks
+
+class test_stretch(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_stretch_01(self):
+ tb = self.tb
+
+ data = 10*[1,]
+ data0 = map(lambda x: x/20.0, data)
+ data1 = map(lambda x: x/10.0, data)
+
+ expected_result0 = 10*[0.05,]
+ expected_result1 = 10*[0.1,]
+
+ src0 = gr.vector_source_f(data0, False)
+ src1 = gr.vector_source_f(data1, False)
+ inter = gr.streams_to_vector(gr.sizeof_float, 2)
+ op = blocks.stretch_ff(0.1, 2)
+ deinter = gr.vector_to_streams(gr.sizeof_float, 2)
+ dst0 = gr.vector_sink_f()
+ dst1 = gr.vector_sink_f()
+
+ tb.connect(src0, (inter,0))
+ tb.connect(src1, (inter,1))
+ tb.connect(inter, op)
+ tb.connect(op, deinter)
+ tb.connect((deinter,0), dst0)
+ tb.connect((deinter,1), dst1)
+ tb.run()
+
+ dst0_data = dst0.data()
+ dst1_data = dst1.data()
+
+ self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4)
+ self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_stretch, "test_stretch.xml")
diff --git a/gr-blocks/python/qa_threshold.py b/gr-blocks/python/qa_threshold.py
new file mode 100644
index 000000000..f91af739a
--- /dev/null
+++ b/gr-blocks/python/qa_threshold.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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 blocks_swig as blocks
+
+class test_threshold(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_01(self):
+ tb = self.tb
+
+ data = [0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2]
+
+ expected_result = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1)
+
+ src = gr.vector_source_f(data, False)
+ op = blocks.threshold_ff(1, 1)
+ dst = gr.vector_sink_f()
+
+ tb.connect(src, op)
+ tb.connect(op, dst)
+ tb.run()
+
+ dst_data = dst.data()
+
+ self.assertEqual(expected_result, dst_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_threshold, "test_threshold.xml")
diff --git a/gr-blocks/python/qa_throttle.py b/gr-blocks/python/qa_throttle.py
new file mode 100755
index 000000000..5d462f2c9
--- /dev/null
+++ b/gr-blocks/python/qa_throttle.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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 blocks_swig as blocks
+
+class test_throttle(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_01(self):
+ # Test that we can make the block
+ op = blocks.throttle(gr.sizeof_gr_complex, 1)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_throttle, "test_throttle.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 114142cbf..6407421b1 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -117,10 +117,13 @@
#include "blocks/stream_to_vector.h"
#include "blocks/streams_to_stream.h"
#include "blocks/streams_to_vector.h"
+#include "blocks/stretch_ff.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
#include "blocks/sub_cc.h"
+#include "blocks/threshold_ff.h"
+#include "blocks/throttle.h"
#include "blocks/uchar_to_float.h"
#include "blocks/unpacked_to_packed_bb.h"
#include "blocks/unpacked_to_packed_ss.h"
@@ -219,10 +222,13 @@
%include "blocks/stream_to_vector.h"
%include "blocks/streams_to_stream.h"
%include "blocks/streams_to_vector.h"
+%include "blocks/stretch_ff.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
%include "blocks/sub_cc.h"
+%include "blocks/threshold_ff.h"
+%include "blocks/throttle.h"
%include "blocks/uchar_to_float.h"
%include "blocks/unpacked_to_packed_bb.h"
%include "blocks/unpacked_to_packed_ss.h"
@@ -320,10 +326,13 @@ GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector);
GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_stream);
GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_vector);
+GR_SWIG_BLOCK_MAGIC2(blocks, stretch_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, throttle);
GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss);
--
cgit