summaryrefslogtreecommitdiff
path: root/gr-blocks
diff options
context:
space:
mode:
authorJohnathan Corgan <jcorgan@corganenterprises.com>2012-06-24 11:42:20 -0700
committerJohnathan Corgan <jcorgan@corganenterprises.com>2012-06-24 11:42:20 -0700
commit8c23d9f9ebfe04b60d59efc636c6d5b02baacc99 (patch)
tree772c33274d13715b0e7b807292765a42414c38c4 /gr-blocks
parentb48716fe0b666cf2be605c0c7d79111c6caf96c5 (diff)
blocks: added gr::blocks::float_to_complex
Diffstat (limited to 'gr-blocks')
-rw-r--r--gr-blocks/grc/blocks_block_tree.xml1
-rw-r--r--gr-blocks/grc/blocks_float_to_complex.xml36
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt1
-rw-r--r--gr-blocks/include/blocks/float_to_complex.h50
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/float_to_complex_impl.cc78
-rw-r--r--gr-blocks/lib/float_to_complex_impl.h47
-rwxr-xr-xgr-blocks/python/qa_type_conversions.py25
-rw-r--r--gr-blocks/swig/blocks_swig.i3
9 files changed, 242 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index eb0cdd79c1..29cc2634d5 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -49,5 +49,6 @@
<block>blocks_complex_to_mag_squared</block>
<block>blocks_complex_to_arg</block>
<block>float_to_char</block>
+ <block>float_to_complex</block>
</cat>
</cat>
diff --git a/gr-blocks/grc/blocks_float_to_complex.xml b/gr-blocks/grc/blocks_float_to_complex.xml
new file mode 100644
index 0000000000..6120d58871
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_to_complex.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Float to Complex:
+## one or two input streams
+###################################################
+ -->
+<block>
+ <name>Float To Complex</name>
+ <key>blocks_float_to_complex</key>
+ <import>from gnuradio import blocks</import>
+ <make>blocks.float_to_complex($vlen)</make>
+ <param>
+ <name>Vec Length</name>
+ <key>vlen</key>
+ <value>1</value>
+ <type>int</type>
+ </param>
+ <check>$vlen &gt; 0</check>
+ <sink>
+ <name>re</name>
+ <type>float</type>
+ <vlen>$vlen</vlen>
+ </sink>
+ <sink>
+ <name>im</name>
+ <type>float</type>
+ <vlen>$vlen</vlen>
+ <optional>1</optional>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>complex</type>
+ <vlen>$vlen</vlen>
+ </source>
+</block>
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 374ecadf59..96f42a6993 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -94,6 +94,7 @@ install(FILES
complex_to_mag_squared.h
complex_to_arg.h
float_to_char.h
+ float_to_complex.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_complex.h b/gr-blocks/include/blocks/float_to_complex.h
new file mode 100644
index 0000000000..48c5b6ead4
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_complex.h
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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_FLOAT_TO_COMPLEX_H
+#define INCLUDED_BLOCKS_FLOAT_TO_COMPLEX_H
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief one or two floats in, complex out
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API float_to_complex : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_complex_ff::sptr
+ typedef boost::shared_ptr<float_to_complex> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_COMPLEX_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 0d23852511..f1d04622d9 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -128,6 +128,7 @@ list(APPEND gr_blocks_sources
complex_to_mag_squared_impl.cc
complex_to_arg_impl.cc
float_to_char_impl.cc
+ float_to_complex_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_to_complex_impl.cc b/gr-blocks/lib/float_to_complex_impl.cc
new file mode 100644
index 0000000000..709aa420c3
--- /dev/null
+++ b/gr-blocks/lib/float_to_complex_impl.cc
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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 "float_to_complex_impl.h"
+#include <gr_io_signature.h>
+#include <volk/volk.h>
+
+namespace gr {
+ namespace blocks {
+
+ float_to_complex::sptr float_to_complex::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new float_to_complex_impl(vlen));
+ }
+
+ float_to_complex_impl::float_to_complex_impl(size_t vlen)
+ : gr_sync_block("float_to_complex",
+ gr_make_io_signature (1, 2, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ float_to_complex_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ float *r = (float *)input_items[0];
+ float *i = (float *)input_items[1];
+ gr_complex *out = (gr_complex *) output_items[0];
+
+ switch (input_items.size ()){
+ case 1:
+ for (size_t j = 0; j < noutput_items*d_vlen; j++)
+ out[j] = gr_complex (r[j], 0);
+ break;
+
+ case 2:
+ for (size_t j = 0; j < noutput_items*d_vlen; j++)
+ out[j] = gr_complex (r[j], i[j]);
+ break;
+
+ default:
+ assert (0);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_complex_impl.h b/gr-blocks/lib/float_to_complex_impl.h
new file mode 100644
index 0000000000..859c5bf965
--- /dev/null
+++ b/gr-blocks/lib/float_to_complex_impl.h
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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_FLOAT_TO_COMPLEX_IMPL_H
+#define INCLUDED_FLOAT_TO_COMPLEX_IMPL_H
+
+#include <blocks/float_to_complex.h>
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_complex_impl : public float_to_complex
+ {
+ size_t d_vlen;
+
+ public:
+ float_to_complex_impl(size_t 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_FLOAT_TO_COMPLEX_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 2caa283d24..4daf5f6023 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -167,5 +167,30 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_float_to_complex_1(self):
+ src_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ expected_data = (1+0j, 3+0j, 5+0j, 7+0j, 9+0j)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_complex()
+ dst = gr.vector_sink_c()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+ def test_float_to_complex_2(self):
+ src1_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ src2_data = (2.0, 4.0, 6.0, 8.0, 10.0)
+ expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ src1 = gr.vector_source_f(src1_data)
+ src2 = gr.vector_source_f(src2_data)
+ op = blocks_swig.float_to_complex()
+ dst = gr.vector_sink_c()
+ self.tb.connect(src1, (op, 0))
+ self.tb.connect(src2, (op, 1))
+ self.tb.connect(op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+
if __name__ == '__main__':
gr_unittest.run(test_type_conversions, "test_type_conversions.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index db30a67068..e15b5eb021 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -54,6 +54,7 @@
#include "blocks/divide_ii.h"
#include "blocks/divide_cc.h"
#include "blocks/float_to_char.h"
+#include "blocks/float_to_complex.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -98,6 +99,7 @@
%include "blocks/divide_ii.h"
%include "blocks/divide_cc.h"
%include "blocks/float_to_char.h"
+%include "blocks/float_to_complex.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -141,6 +143,7 @@ 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, float_to_char);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);