diff options
author | JaredD <jareddpub@gmail.com> | 2021-07-19 04:41:18 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-19 06:41:18 -0400 |
commit | 15a8cce4dadaa895081d1d9816f37e65117cffb5 (patch) | |
tree | 4be2473cc5ed302e2b2d859f436fd0f101e79ab4 /gr-blocks/python/blocks | |
parent | fbab6c383d6f86ab0de42a90a9182d22637a5b96 (diff) |
blocks: add matrix interleaver block
* blocks: add matrix interleaver block
Matrix interleaver including qa test and example
The matrix interleaver is a hierarchical block that pairs a base
deinterleave block that effectively writes samples into "rows" (1 block of
samples per output) and a base interleave block that outputs samples
iteratively from each input like "columns".
Signed-off-by: Jared Dulmage <jared.dulmage@caliola.com>
Add grc file and update blocks.tree.yml.
Fix module for matrix interleaver example
Signed-off-by: Jared Dulmage <jared.dulmage@caliola.com>
* Update py file docs and license block
Co-authored-by: Jared Dulmage <jared.dulmage@caliola.com>
Diffstat (limited to 'gr-blocks/python/blocks')
-rw-r--r-- | gr-blocks/python/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/python/blocks/__init__.py | 1 | ||||
-rw-r--r-- | gr-blocks/python/blocks/matrix_interleaver.py | 63 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_matrix_interleaver.py | 62 |
4 files changed, 127 insertions, 0 deletions
diff --git a/gr-blocks/python/blocks/CMakeLists.txt b/gr-blocks/python/blocks/CMakeLists.txt index 25ae7755d5..587c7c7ca2 100644 --- a/gr-blocks/python/blocks/CMakeLists.txt +++ b/gr-blocks/python/blocks/CMakeLists.txt @@ -11,6 +11,7 @@ include(GrPython) GR_PYTHON_INSTALL( FILES __init__.py + matrix_interleaver.py parse_file_metadata.py stream_to_vector_decimator.py msg_pair_to_var.py diff --git a/gr-blocks/python/blocks/__init__.py b/gr-blocks/python/blocks/__init__.py index 4a3bc1ccaf..c9a4b3f756 100644 --- a/gr-blocks/python/blocks/__init__.py +++ b/gr-blocks/python/blocks/__init__.py @@ -25,6 +25,7 @@ from .stream_to_vector_decimator import * from .msg_meta_to_pair import meta_to_pair from .msg_pair_to_var import msg_pair_to_var from .var_to_msg import var_to_msg_pair +from .matrix_interleaver import * #alias old add_vXX and multiply_vXX add_vcc = add_cc diff --git a/gr-blocks/python/blocks/matrix_interleaver.py b/gr-blocks/python/blocks/matrix_interleaver.py new file mode 100644 index 0000000000..26a8e86a6e --- /dev/null +++ b/gr-blocks/python/blocks/matrix_interleaver.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2021 Caliola Engineering, LLC. +# +# This file is part of GNU Radio +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gnuradio import gr, blocks + +class matrix_interleaver(gr.hier_block2): + """ + Block interleaver writes inputs into conceptual rows of the matrix + and reads outputs by conceptual columns of the matrix. + In deinterleaver mode it writes inputs into conceptual columns + and reads outputs by conceptual rows. + """ + + def __init__(self, itemsize, rows=1, cols=1, deint=False): + gr.hier_block2.__init__( + self, "Matrix Interleaver", + gr.io_signature(1, 1, itemsize), + gr.io_signature(1, 1, itemsize), + ) + + self.itemsize = itemsize + self.set_rowsandcols(rows, cols, deint) + + def set_rowsandcols(self, rows, cols, deint): + self.disconnect_all() + + self.passthrough = None + self.interleaver = None + self.deinterleaver = None + + ################################################## + # Parameters + ################################################## + self.rows = rows + self.cols = cols + self.deint = deint + + ################################################## + # Blocks + ################################################## + # short circuit for unitary rows / columns + if rows == 1 or cols == 1: + self.passthrough = blocks.copy(self.itemsize) + self.connect((self, 0), (self.passthrough, 0), (self, 0)) + return + + self.deinterleaver = blocks.deinterleave(self.itemsize, 1 if deint else cols) + self.interleaver = blocks.interleave(self.itemsize, cols if deint else 1) + + ################################################## + # Connections + ################################################## + self.connect((self, 0), (self.deinterleaver, 0)) + for n in range(rows): + self.connect((self.deinterleaver, n), (self.interleaver, n)) + self.connect((self.interleaver, 0), (self, 0)) diff --git a/gr-blocks/python/blocks/qa_matrix_interleaver.py b/gr-blocks/python/blocks/qa_matrix_interleaver.py new file mode 100755 index 0000000000..d254ef6b55 --- /dev/null +++ b/gr-blocks/python/blocks/qa_matrix_interleaver.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2021 Caliola Engineering, LLC. +# +# This file is part of GNU Radio +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gnuradio import gr, gr_unittest +from gnuradio import blocks +from matrix_interleaver import matrix_interleaver + +class qa_matrix_interleaver(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_interleave(self): + tb = self.tb + + # set up fg + cols, rows = 4, 10 + vec = sum((cols * [x,] for x in range(rows)), []) + expected = cols * list(range(rows)) + + src = blocks.vector_source_f(vec, False) + itlv = matrix_interleaver(gr.sizeof_float, rows=rows, cols=cols) + snk = blocks.vector_sink_f() + + tb.connect(src, itlv, snk) + tb.run() + result = snk.data() + + # check data + self.assertFloatTuplesAlmostEqual(expected, result) + + def test_deinterleave(self): + tb = self.tb + + # set up fg + cols, rows = 4, 10 + vec = sum((rows * [x,] for x in range(cols)), []) + expected = rows * list(range(cols)) + + src = blocks.vector_source_f(vec, False) + itlv = matrix_interleaver(gr.sizeof_float, rows=rows, cols=cols, deint=True) + snk = blocks.vector_sink_f() + + tb.connect(src, itlv, snk) + tb.run() + result = snk.data() + + # check data + self.assertFloatTuplesAlmostEqual(expected, result) + +if __name__ == '__main__': + gr_unittest.run(qa_matrix_interleaver) |