summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2017-03-27 14:20:09 -0700
committerJohnathan Corgan <johnathan@corganlabs.com>2017-03-27 14:20:09 -0700
commit1ee3e3a1cb18f9e2df57983e615e8a5680515bc5 (patch)
tree5c3c0b64fd4f002b96214580e7ec4afe50d0b7f3
parentb3b63be28857d04004a337b7c0bebfad06bc2e7c (diff)
parentc01ac41eed33130521812f88005b6b7123ae24dc (diff)
Merge branch 'next' into python3
-rw-r--r--gr-blocks/grc/blocks_block_tree.xml1
-rw-r--r--gr-blocks/grc/blocks_exponentiate_const_cci.xml45
-rw-r--r--gr-blocks/include/gnuradio/blocks/CMakeLists.txt1
-rw-r--r--gr-blocks/include/gnuradio/blocks/exponentiate_const_cci.h66
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/exponentiate_const_cci_impl.cc102
-rw-r--r--gr-blocks/lib/exponentiate_const_cci_impl.h53
-rw-r--r--gr-blocks/python/blocks/qa_exponentiate_const_cci.py66
-rw-r--r--gr-blocks/swig/blocks_swig7.i3
9 files changed, 338 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index cb9ad639c6..d0bb252a47 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -93,6 +93,7 @@
<block>blocks_add_xx</block>
<block>blocks_add_const_vxx</block>
<block>blocks_divide_xx</block>
+ <block>blocks_exponentiate_const_cci</block>
<block>blocks_multiply_xx</block>
<block>blocks_multiply_const_xx</block>
<block>blocks_multiply_const_vxx</block>
diff --git a/gr-blocks/grc/blocks_exponentiate_const_cci.xml b/gr-blocks/grc/blocks_exponentiate_const_cci.xml
new file mode 100644
index 0000000000..3c9e9b9625
--- /dev/null
+++ b/gr-blocks/grc/blocks_exponentiate_const_cci.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<block>
+ <name>Exponentiate Const Int</name>
+ <key>blocks_exponentiate_const_cci</key>
+ <import>from gnuradio import blocks</import>
+ <make>blocks.exponentiate_const_cci($exponent, $vlen)</make>
+ <callback>set_exponent($exponent)</callback>
+
+ <param>
+ <name>Num Ports</name>
+ <key>num_ports</key>
+ <value>1</value>
+ <type>int</type>
+ </param>
+ <param>
+ <name>Vec Length</name>
+ <key>vlen</key>
+ <value>1</value>
+ <type>int</type>
+ </param>
+ <param>
+ <name>Exponent</name>
+ <key>exponent</key>
+ <value>1</value>
+ <type>int</type>
+ </param>
+
+ <check>$num_ports &gt; 0</check>
+ <check>$vlen &gt; 0</check>
+ <check>$exponent &gt; 0</check>
+
+ <sink>
+ <name>in</name>
+ <type>complex</type>
+ <vlen>$vlen</vlen>
+ <nports>$num_ports</nports>
+ </sink>
+
+ <source>
+ <name>out</name>
+ <type>complex</type>
+ <vlen>$vlen</vlen>
+ <nports>$num_ports</nports>
+ </source>
+</block>
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
index d566b3da67..0d3dc470ea 100644
--- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
+++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
@@ -99,6 +99,7 @@ install(FILES
deinterleave.h
delay.h
endian_swap.h
+ exponentiate_const_cci.h
file_descriptor_sink.h
file_descriptor_source.h
file_sink.h
diff --git a/gr-blocks/include/gnuradio/blocks/exponentiate_const_cci.h b/gr-blocks/include/gnuradio/blocks/exponentiate_const_cci.h
new file mode 100644
index 0000000000..0d96c645cf
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/exponentiate_const_cci.h
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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_EXPONENTIATE_CONST_CCI_H
+#define INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Exponentiates a complex stream with an integer exponent
+ * \ingroup blocks
+ *
+ * \details
+ * This block raises a complex stream to an integer exponent. The exponent
+ * must be at least 1. There is a callback function so the exponent can be
+ * changed at runtime.
+ *
+ * NOTE: The algorithm uses iterative multiplication to achieve exponentiation,
+ * hence it is O(exponent). Therefore, this block could be inefficient for large
+ * exponents.
+ */
+ class BLOCKS_API exponentiate_const_cci : virtual public gr::sync_block
+ {
+ public:
+ typedef boost::shared_ptr<exponentiate_const_cci> sptr;
+
+ /*
+ * \param exponent Exponent the input stream is raised to, which must be an integer.
+ * The algorithm uses iterative multiplication to achieve exponentiation, hence it is
+ * O(exponent). Therefore, this block could be inefficient for large exponents.
+ * \param vlen Vector length of input/output stream
+ */
+ static sptr make(int exponent, size_t vlen = 1);
+
+ virtual void set_exponent(int exponent) = 0;
+ };
+
+ } // namespace blocks
+} // namespace gr
+
+#endif /* INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_H */
+
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 3769577302..f8e2a989ac 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -115,6 +115,7 @@ list(APPEND gr_blocks_sources
divide_ff_impl.cc
delay_impl.cc
endian_swap_impl.cc
+ exponentiate_const_cci_impl.cc
file_descriptor_sink_impl.cc
file_descriptor_source_impl.cc
file_sink_impl.cc
diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.cc b/gr-blocks/lib/exponentiate_const_cci_impl.cc
new file mode 100644
index 0000000000..c46930febb
--- /dev/null
+++ b/gr-blocks/lib/exponentiate_const_cci_impl.cc
@@ -0,0 +1,102 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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 <gnuradio/io_signature.h>
+#include "exponentiate_const_cci_impl.h"
+#include <volk/volk.h>
+
+namespace gr {
+ namespace blocks {
+
+ exponentiate_const_cci::sptr
+ exponentiate_const_cci::make(int exponent, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr
+ (new exponentiate_const_cci_impl(exponent, vlen));
+ }
+
+ /*
+ * The private constructor
+ */
+ exponentiate_const_cci_impl::exponentiate_const_cci_impl(int exponent, size_t vlen)
+ : gr::sync_block("exponentiate_const_cci",
+ gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen),
+ gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen)),
+ d_exponent(exponent),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple = volk_get_alignment()/sizeof(gr_complex);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ exponentiate_const_cci_impl::~exponentiate_const_cci_impl()
+ {
+ }
+
+ bool
+ exponentiate_const_cci_impl::check_topology(int ninputs, int noutputs)
+ {
+ return ninputs == noutputs;
+ }
+
+ void
+ exponentiate_const_cci_impl::set_exponent(int exponent) {
+ gr::thread::scoped_lock guard(d_setlock);
+ d_exponent = exponent;
+ }
+
+ int
+ exponentiate_const_cci_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr::thread::scoped_lock guard(d_setlock);
+
+ for(unsigned int i = 0; i < input_items.size(); i++) {
+ const gr_complex *in = (const gr_complex *) input_items[i];
+ gr_complex *out = (gr_complex *) output_items[i];
+
+ if(d_exponent > 1) {
+ volk_32fc_x2_multiply_32fc(out, in, in, noutput_items*d_vlen);
+ for(int j = 2; j < d_exponent; j++) {
+ volk_32fc_x2_multiply_32fc(out, out, in, noutput_items*d_vlen);
+ }
+ }
+ else {
+ memcpy(out, in, sizeof(gr_complex)*noutput_items*d_vlen);
+ }
+ }
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
+
diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.h b/gr-blocks/lib/exponentiate_const_cci_impl.h
new file mode 100644
index 0000000000..c89fe57646
--- /dev/null
+++ b/gr-blocks/lib/exponentiate_const_cci_impl.h
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2017 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_EXPONENTIATE_CONST_CCI_IMPL_H
+#define INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_IMPL_H
+
+#include <gnuradio/blocks/exponentiate_const_cci.h>
+
+namespace gr {
+ namespace blocks {
+
+ class exponentiate_const_cci_impl : public exponentiate_const_cci
+ {
+ private:
+ int d_exponent;
+ int d_vlen;
+
+ public:
+ exponentiate_const_cci_impl(int exponent, size_t vlen);
+ ~exponentiate_const_cci_impl();
+ bool check_topology(int ninputs, int noutputs);
+ void set_exponent(int exponent);
+
+ // Where all the action really happens
+ 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_EXPONENTIATE_CONST_CCI_IMPL_H */
+
diff --git a/gr-blocks/python/blocks/qa_exponentiate_const_cci.py b/gr-blocks/python/blocks/qa_exponentiate_const_cci.py
new file mode 100644
index 0000000000..0c4b65eb68
--- /dev/null
+++ b/gr-blocks/python/blocks/qa_exponentiate_const_cci.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright 2017 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
+from gnuradio import blocks
+import pmt
+
+class qa_exponentiate_const_cci(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001_t(self):
+ for exponent in range(1,10):
+ in_data = (1+1j, -1, 4-1j, -3-7j)
+ out_data = (in_data[0]**exponent, in_data[1]**exponent, in_data[2]**exponent, in_data[3]**exponent)
+
+ # Test streaming input
+ source = blocks.vector_source_c(in_data, False, 1)
+ exponentiate_const_cci = blocks.exponentiate_const_cci(exponent)
+ sink = blocks.vector_sink_c(1)
+
+ self.tb.connect(source, exponentiate_const_cci, sink)
+ self.tb.run()
+
+ self.assertAlmostEqual(sink.data(), out_data)
+
+ # Test vector input
+ for vlen in [2, 4]:
+ source = blocks.vector_source_c(in_data, False, 1)
+ s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen)
+ exponentiate_const_cci = blocks.exponentiate_const_cci(exponent, vlen)
+ v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, vlen)
+ sink = blocks.vector_sink_c(1)
+
+ self.tb.connect(source, s2v, exponentiate_const_cci, v2s, sink)
+ self.tb.run()
+
+ self.assertAlmostEqual(sink.data(), out_data)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(qa_exponentiate_const_cci, 'qa_exponentiate_const_cci.xml')
diff --git a/gr-blocks/swig/blocks_swig7.i b/gr-blocks/swig/blocks_swig7.i
index d48ea8324d..20ca46dee6 100644
--- a/gr-blocks/swig/blocks_swig7.i
+++ b/gr-blocks/swig/blocks_swig7.i
@@ -36,6 +36,7 @@
#include "gnuradio/blocks/divide_ss.h"
#include "gnuradio/blocks/divide_ii.h"
#include "gnuradio/blocks/divide_cc.h"
+#include "gnuradio/blocks/exponentiate_const_cci.h"
#include "gnuradio/blocks/skiphead.h"
#include "gnuradio/blocks/stream_mux.h"
#include "gnuradio/blocks/stream_to_streams.h"
@@ -58,6 +59,7 @@
%include "gnuradio/blocks/divide_ss.h"
%include "gnuradio/blocks/divide_ii.h"
%include "gnuradio/blocks/divide_cc.h"
+%include "gnuradio/blocks/exponentiate_const_cci.h"
%include "gnuradio/blocks/skiphead.h"
%include "gnuradio/blocks/stream_mux.h"
%include "gnuradio/blocks/stream_to_streams.h"
@@ -79,6 +81,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, exponentiate_const_cci);
GR_SWIG_BLOCK_MAGIC2(blocks, skiphead);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);