diff options
author | Josh Morman <mormjb@gmail.com> | 2020-06-02 09:37:58 -0400 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-11-16 13:10:53 -0500 |
commit | e5144a18d9f5280f62db4dd3c2426860b92b2631 (patch) | |
tree | ce74d38bdfbd2c2ed5a106c2cac7914bc98660a7 /gr-digital/python/digital | |
parent | f1d64ccf38f669420387c1cc8787513538e40947 (diff) |
digital: add constellation_encoder block
Diffstat (limited to 'gr-digital/python/digital')
6 files changed, 153 insertions, 1 deletions
diff --git a/gr-digital/python/digital/bindings/CMakeLists.txt b/gr-digital/python/digital/bindings/CMakeLists.txt index 97e3bd1b66..ade0e251a2 100644 --- a/gr-digital/python/digital/bindings/CMakeLists.txt +++ b/gr-digital/python/digital/bindings/CMakeLists.txt @@ -18,6 +18,7 @@ list(APPEND digital_python_files cma_equalizer_cc_python.cc constellation_python.cc constellation_decoder_cb_python.cc + constellation_encoder_bc_python.cc constellation_receiver_cb_python.cc constellation_soft_decoder_cf_python.cc corr_est_cc_python.cc diff --git a/gr-digital/python/digital/bindings/constellation_decoder_cb_python.cc b/gr-digital/python/digital/bindings/constellation_decoder_cb_python.cc index 7386ba3a18..81933f3a68 100644 --- a/gr-digital/python/digital/bindings/constellation_decoder_cb_python.cc +++ b/gr-digital/python/digital/bindings/constellation_decoder_cb_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(constellation_decoder_cb.h) */ -/* BINDTOOL_HEADER_FILE_HASH(057b33fe4e52dd1a92c38d00e64b04f2) */ +/* BINDTOOL_HEADER_FILE_HASH(688ec1fa379a5cdd51c2b31886991b28) */ /***********************************************************************************/ #include <pybind11/complex.h> diff --git a/gr-digital/python/digital/bindings/constellation_encoder_bc_python.cc b/gr-digital/python/digital/bindings/constellation_encoder_bc_python.cc new file mode 100644 index 0000000000..2efd37645e --- /dev/null +++ b/gr-digital/python/digital/bindings/constellation_encoder_bc_python.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* This file is automatically generated using bindtool and can be manually edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. */ +/* BINDTOOL_GEN_AUTOMATIC(0) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(constellation_encoder_bc.h) */ +/* BINDTOOL_HEADER_FILE_HASH(b7a40d63f0e359222f614398dd1483a3) */ +/***********************************************************************************/ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/digital/constellation_encoder_bc.h> +// pydoc.h is automatically generated in the build directory +#include <constellation_encoder_bc_pydoc.h> + +void bind_constellation_encoder_bc(py::module& m) +{ + + using constellation_encoder_bc = ::gr::digital::constellation_encoder_bc; + + py::class_<constellation_encoder_bc, + gr::sync_interpolator, + std::shared_ptr<constellation_encoder_bc>>( + m, "constellation_encoder_bc", D(constellation_encoder_bc)) + + .def(py::init(&constellation_encoder_bc::make), + py::arg("constellation"), + D(constellation_encoder_bc, make)); +} diff --git a/gr-digital/python/digital/bindings/docstrings/constellation_encoder_bc_pydoc_template.h b/gr-digital/python/digital/bindings/docstrings/constellation_encoder_bc_pydoc_template.h new file mode 100644 index 0000000000..0317538035 --- /dev/null +++ b/gr-digital/python/digital/bindings/docstrings/constellation_encoder_bc_pydoc_template.h @@ -0,0 +1,25 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, digital, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_digital_constellation_encoder_bc = R"doc()doc"; + + +static const char* __doc_gr_digital_constellation_encoder_bc_constellation_encoder_bc = + R"doc()doc"; + + +static const char* __doc_gr_digital_constellation_encoder_bc_make = R"doc()doc"; diff --git a/gr-digital/python/digital/bindings/python_bindings.cc b/gr-digital/python/digital/bindings/python_bindings.cc index e7a0428d4e..f77761329e 100644 --- a/gr-digital/python/digital/bindings/python_bindings.cc +++ b/gr-digital/python/digital/bindings/python_bindings.cc @@ -28,6 +28,7 @@ void bind_clock_recovery_mm_ff(py::module&); void bind_cma_equalizer_cc(py::module&); void bind_constellation(py::module&); void bind_constellation_decoder_cb(py::module&); +void bind_constellation_encoder_bc(py::module&); void bind_constellation_receiver_cb(py::module&); void bind_constellation_soft_decoder_cf(py::module&); void bind_corr_est_cc(py::module&); @@ -134,6 +135,7 @@ PYBIND11_MODULE(digital_python, m) bind_cma_equalizer_cc(m); bind_constellation(m); bind_constellation_decoder_cb(m); + bind_constellation_encoder_bc(m); bind_constellation_receiver_cb(m); bind_constellation_soft_decoder_cf(m); bind_corr_est_cc(m); diff --git a/gr-digital/python/digital/qa_constellation_encoder_bc.py b/gr-digital/python/digital/qa_constellation_encoder_bc.py new file mode 100644 index 0000000000..2c6d587dac --- /dev/null +++ b/gr-digital/python/digital/qa_constellation_encoder_bc.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010-2013,2020 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# + + +from gnuradio import gr, gr_unittest, digital, blocks +import numpy as np + +class test_constellation_encoder(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_constellation_encoder_bc_bpsk(self): + cnst = digital.constellation_bpsk() + + src_data = (1, 1, 0, 0, + 1, 0, 1) + const_map = [-1.0, 1.0] + expected_result = [const_map[x] for x in src_data] + + src = blocks.vector_source_b(src_data) + op = digital.constellation_encoder_bc(cnst.base()) + dst = blocks.vector_sink_c() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() # run the graph and wait for it to finish + + actual_result = dst.data() # fetch the contents of the sink + # print "actual result", actual_result + # print "expected result", expected_result + self.assertFloatTuplesAlmostEqual(expected_result, actual_result) + + def test_constellation_encoder_bc_qpsk(self): + cnst = digital.constellation_qpsk() + src_data = (3, 1, 0, 2, + 3, 2, 1) + expected_result = [cnst.points()[x] for x in src_data] + src = blocks.vector_source_b(src_data) + op = digital.constellation_encoder_bc(cnst.base()) + dst = blocks.vector_sink_c() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() # run the graph and wait for it to finish + + actual_result = dst.data() # fetch the contents of the sink + # print "actual result", actual_result + # print "expected result", expected_result + self.assertFloatTuplesAlmostEqual(expected_result, actual_result) + + + def test_constellation_encoder_bc_qpsk_random(self): + cnst = digital.constellation_qpsk() + src_data = np.random.randint(0, 4, size=20000) + expected_result = [cnst.points()[x] for x in src_data] + src = blocks.vector_source_b(src_data) + op = digital.constellation_encoder_bc(cnst.base()) + dst = blocks.vector_sink_c() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() # run the graph and wait for it to finish + + actual_result = dst.data() # fetch the contents of the sink + # print "actual result", actual_result + # print "expected result", expected_result + self.assertFloatTuplesAlmostEqual(expected_result, actual_result) + +if __name__ == '__main__': + gr_unittest.run(test_constellation_encoder) |