summaryrefslogtreecommitdiff
path: root/gr-blocks/python/blocks/matrix_interleaver.py
diff options
context:
space:
mode:
authorJaredD <jareddpub@gmail.com>2021-07-19 04:41:18 -0600
committerGitHub <noreply@github.com>2021-07-19 06:41:18 -0400
commit15a8cce4dadaa895081d1d9816f37e65117cffb5 (patch)
tree4be2473cc5ed302e2b2d859f436fd0f101e79ab4 /gr-blocks/python/blocks/matrix_interleaver.py
parentfbab6c383d6f86ab0de42a90a9182d22637a5b96 (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/matrix_interleaver.py')
-rw-r--r--gr-blocks/python/blocks/matrix_interleaver.py63
1 files changed, 63 insertions, 0 deletions
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))