summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/gr_complex_to_xxx.cc33
-rw-r--r--gnuradio-core/src/lib/general/gr_complex_to_xxx.h21
-rw-r--r--gnuradio-core/src/lib/general/gr_complex_to_xxx.i11
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_complex_to_xxx.py12
4 files changed, 75 insertions, 2 deletions
diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
index 727f44f07..222357cd0 100644
--- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
+++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc
@@ -169,6 +169,39 @@ gr_complex_to_mag::work (int noutput_items,
// ----------------------------------------------------------------
+gr_complex_to_mag_squared_sptr
+gr_make_complex_to_mag_squared (unsigned int vlen)
+{
+ return gr_complex_to_mag_squared_sptr (new gr_complex_to_mag_squared (vlen));
+}
+
+gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen)
+ : gr_sync_block ("complex_to_mag_squared",
+ gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
+ gr_make_io_signature (1, 1, sizeof (float) * vlen)),
+ d_vlen(vlen)
+{
+}
+
+int
+gr_complex_to_mag_squared::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];
+ int noi = noutput_items * d_vlen;
+
+ for (int i = 0; i < noi; i++){
+ const float __x = in[i].real();
+ const float __y = in[i].imag();
+ out[i] = __x * __x + __y * __y;
+ }
+ return noutput_items;
+}
+
+// ----------------------------------------------------------------
+
gr_complex_to_arg_sptr
gr_make_complex_to_arg (unsigned int vlen)
{
diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.h b/gnuradio-core/src/lib/general/gr_complex_to_xxx.h
index 02a9fc8fd..d9acdb8ab 100644
--- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.h
+++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.h
@@ -30,18 +30,21 @@ class gr_complex_to_float;
class gr_complex_to_real;
class gr_complex_to_imag;
class gr_complex_to_mag;
+class gr_complex_to_mag_squared;
class gr_complex_to_arg;
typedef boost::shared_ptr<gr_complex_to_float> gr_complex_to_float_sptr;
typedef boost::shared_ptr<gr_complex_to_real> gr_complex_to_real_sptr;
typedef boost::shared_ptr<gr_complex_to_imag> gr_complex_to_imag_sptr;
typedef boost::shared_ptr<gr_complex_to_mag> gr_complex_to_mag_sptr;
+typedef boost::shared_ptr<gr_complex_to_mag_squared> gr_complex_to_mag_squared_sptr;
typedef boost::shared_ptr<gr_complex_to_arg> gr_complex_to_arg_sptr;
gr_complex_to_float_sptr gr_make_complex_to_float (unsigned int vlen=1);
gr_complex_to_real_sptr gr_make_complex_to_real (unsigned int vlen=1);
gr_complex_to_imag_sptr gr_make_complex_to_imag (unsigned int vlen=1);
gr_complex_to_mag_sptr gr_make_complex_to_mag (unsigned int vlen=1);
+gr_complex_to_mag_squared_sptr gr_make_complex_to_mag_squared (unsigned int vlen=1);
gr_complex_to_arg_sptr gr_make_complex_to_arg (unsigned int vlen=1);
/*!
@@ -117,6 +120,24 @@ class gr_complex_to_mag : public gr_sync_block
};
/*!
+ * \brief complex in, magnitude squared out (float)
+ * \ingroup converter
+ * \param vlen vector len (default 1)
+ */
+class gr_complex_to_mag_squared : public gr_sync_block
+{
+ friend gr_complex_to_mag_squared_sptr gr_make_complex_to_mag_squared (unsigned int vlen);
+ gr_complex_to_mag_squared (unsigned int vlen);
+
+ unsigned int d_vlen;
+
+ public:
+ virtual int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+/*!
* \brief complex in, angle out (float)
* \ingroup converter
* \param vlen vector len (default 1)
diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.i b/gnuradio-core/src/lib/general/gr_complex_to_xxx.i
index 06f1020a0..e6d00cc8b 100644
--- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.i
+++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.i
@@ -39,8 +39,8 @@ gr_complex_to_imag_sptr gr_make_complex_to_imag (unsigned int vlen=1);
class gr_complex_to_imag : public gr_sync_block
{
gr_complex_to_imag (unsigned int vlen);
-}
- ;
+};
+
GR_SWIG_BLOCK_MAGIC(gr,complex_to_mag);
gr_complex_to_mag_sptr gr_make_complex_to_mag (unsigned int vlen=1);
class gr_complex_to_mag : public gr_sync_block
@@ -48,6 +48,13 @@ class gr_complex_to_mag : public gr_sync_block
gr_complex_to_mag (unsigned int vlen);
};
+GR_SWIG_BLOCK_MAGIC(gr,complex_to_mag_squared);
+gr_complex_to_mag_squared_sptr gr_make_complex_to_mag_squared (unsigned int vlen=1);
+class gr_complex_to_mag_squared : public gr_sync_block
+{
+ gr_complex_to_mag_squared (unsigned int vlen);
+};
+
GR_SWIG_BLOCK_MAGIC(gr,complex_to_arg);
gr_complex_to_arg_sptr gr_make_complex_to_arg (unsigned int vlen=1);
class gr_complex_to_arg : public gr_sync_block
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_complex_to_xxx.py b/gnuradio-core/src/python/gnuradio/gr/qa_complex_to_xxx.py
index 4bc193350..f92cf82b6 100755
--- a/gnuradio-core/src/python/gnuradio/gr/qa_complex_to_xxx.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_complex_to_xxx.py
@@ -96,6 +96,18 @@ class test_complex_ops (gr_unittest.TestCase):
actual_result = dst.data ()
self.assertFloatTuplesAlmostEqual (expected_result, actual_result,5)
+ def test_complex_to_mag_squared (self):
+ src_data = (0, 1, -1, 3+4j, -3-4j, -3+4j)
+ expected_result = (0, 1, 1, 25, 25, 25)
+ src = gr.vector_source_c (src_data)
+ op = gr.complex_to_mag_squared ()
+ dst = gr.vector_sink_f ()
+ self.fg.connect (src, op)
+ self.fg.connect (op, dst)
+ self.fg.run ()
+ actual_result = dst.data ()
+ self.assertFloatTuplesAlmostEqual (expected_result, actual_result,5)
+
def test_complex_to_arg (self):
pi = math.pi
expected_result = (0, pi/6, pi/4, pi/2, 3*pi/4, 7*pi/8,