summaryrefslogtreecommitdiff
path: root/gr-digital/python/digital/qa_constellation.py
diff options
context:
space:
mode:
authormormj <mormjb@gmail.com>2020-10-30 10:59:50 -0400
committerMarcus Müller <marcus@hostalia.de>2020-10-30 17:52:53 +0100
commit7a0948ba85758fba1cc3858ef99bfa600dcc7416 (patch)
tree610d7f9d773a193562def6df2d4b50f1bb3b3f86 /gr-digital/python/digital/qa_constellation.py
parent12192ee7d58de95ddca35a3e93bfc172bdb5c820 (diff)
qa: run autopep8 formatting on qa python files
find ./ -iname qa*.py | xargs autopep8 --in-place -a -a mostly formats whitespace and gets rid of trailing semicolons
Diffstat (limited to 'gr-digital/python/digital/qa_constellation.py')
-rw-r--r--gr-digital/python/digital/qa_constellation.py144
1 files changed, 97 insertions, 47 deletions
diff --git a/gr-digital/python/digital/qa_constellation.py b/gr-digital/python/digital/qa_constellation.py
index 050b507a2b..0e3460a142 100644
--- a/gr-digital/python/digital/qa_constellation.py
+++ b/gr-digital/python/digital/qa_constellation.py
@@ -9,7 +9,8 @@
#
-import random, math
+import random
+import math
from cmath import exp, pi, log, sqrt
from gnuradio import gr, gr_unittest, digital, blocks
@@ -27,18 +28,20 @@ tested_mod_codes = (mod_codes.NO_CODE, mod_codes.GRAY_CODE)
# Fourth item is the name of the argument to constructor that specifies
# whether differential encoding is used.
+
def twod_constell():
"""
"""
- points = ((1+0j), (0+1j),
- (-1+0j), (0-1j))
+ points = ((1 + 0j), (0 + 1j),
+ (-1 + 0j), (0 - 1j))
rot_sym = 2
dim = 2
return digital.constellation_calcdist(points, [], rot_sym, dim)
+
def threed_constell():
- oned_points = ((1+0j), (0+1j), (-1+0j), (0-1j))
+ oned_points = ((1 + 0j), (0 + 1j), (-1 + 0j), (0 - 1j))
points = []
r4 = list(range(0, 4))
for ia in r4:
@@ -52,6 +55,7 @@ def threed_constell():
# A list of tuples for constellation testing. The contents of the
# tuples are (constructor, poss_args, differential, diff_argname).
+
# These constellations should lock on well.
easy_constellation_info = (
(psk.psk_constellation,
@@ -66,7 +70,7 @@ easy_constellation_info = (
(qam.qam_constellation,
{'constellation_points': (4,),
'mod_code': tested_mod_codes,
- 'large_ampls_to_corners': [False],},
+ 'large_ampls_to_corners': [False], },
True, None),
(qam.qam_constellation,
{'constellation_points': (4, 16, 64),
@@ -79,7 +83,7 @@ easy_constellation_info = (
(digital.constellation_8psk, {}, False, None),
(twod_constell, {}, True, None),
(threed_constell, {}, True, None),
- )
+)
# These constellations don't work nicely.
# We have a lower required error rate.
@@ -89,9 +93,9 @@ medium_constellation_info = (
'mod_code': tested_mod_codes, },
True, None),
(qam.qam_constellation,
- {'constellation_points': (16 ,),
+ {'constellation_points': (16,),
'mod_code': tested_mod_codes,
- 'large_ampls_to_corners': [False, True],},
+ 'large_ampls_to_corners': [False, True], },
True, None),
(qamlike.qam32_holeinside_constellation,
{'large_ampls_to_corners': [True]},
@@ -103,10 +107,11 @@ difficult_constellation_info = (
(qam.qam_constellation,
{'constellation_points': (64,),
'mod_code': tested_mod_codes,
- 'large_ampls_to_corners': [False, True],},
+ 'large_ampls_to_corners': [False, True], },
True, None),
)
+
def slicer(x):
ret = []
for xi in x:
@@ -116,6 +121,7 @@ def slicer(x):
ret.append(1.0)
return ret
+
def tested_constellations(easy=True, medium=True, difficult=True):
"""
Generator to produce (constellation, differential) tuples for testing purposes.
@@ -132,9 +138,11 @@ def tested_constellations(easy=True, medium=True, difficult=True):
diff_poss = (True, False)
else:
diff_poss = (False,)
- poss_args = [[argname, argvalues, 0] for argname, argvalues in list(poss_args.items())]
+ poss_args = [[argname, argvalues, 0]
+ for argname, argvalues in list(poss_args.items())]
for current_diff in diff_poss:
- # Add an index into args to keep track of current position in argvalues
+ # Add an index into args to keep track of current position in
+ # argvalues
while True:
current_args = dict([(argname, argvalues[argindex])
for argname, argvalues, argindex in poss_args])
@@ -149,7 +157,8 @@ def tested_constellations(easy=True, medium=True, difficult=True):
break
else:
this_poss_arg[2] = 0
- if sum([argindex for argname, argvalues, argindex in poss_args]) == 0:
+ if sum([argindex for argname, argvalues,
+ argindex in poss_args]) == 0:
break
@@ -160,7 +169,10 @@ class test_constellation(gr_unittest.TestCase):
def setUp(self):
random.seed(0)
# Generate a list of random bits.
- self.src_data = [random.randint(0,1) for i in range(0, self.src_length)]
+ self.src_data = [
+ random.randint(
+ 0, 1) for i in range(
+ 0, self.src_length)]
def tearDown(self):
pass
@@ -169,7 +181,8 @@ class test_constellation(gr_unittest.TestCase):
for constellation, differential in tested_constellations():
if differential:
rs = constellation.rotational_symmetry()
- rotations = [exp(i*2*pi*(0+1j)/rs) for i in range(0, rs)]
+ rotations = [exp(i * 2 * pi * (0 + 1j) / rs)
+ for i in range(0, rs)]
else:
rotations = [None]
for rotation in rotations:
@@ -202,12 +215,17 @@ class test_constellation(gr_unittest.TestCase):
c.set_soft_dec_lut(table, prec)
x = sqrt(2.0) / 2.0
- step = (x.real+x.real) / (2**prec - 1)
- samples = [ -x-x*1j, -x+x*1j,
- x+x*1j, x-x*1j,
- (-x+128*step)+(-x+128*step)*1j,
- (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j,
- (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,]
+ step = (x.real + x.real) / (2**prec - 1)
+ samples = [-x - x * 1j,
+ -x + x * 1j,
+ x + x * 1j,
+ x - x * 1j,
+ (-x + 128 * step) + (-x + 128 * step) * 1j,
+ (-x + 64 * step) + (-x + 64 * step) * 1j,
+ (-x + 64 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 64 * step) * 1j,
+ ]
y_python_raw_calc = []
y_python_gen_calc = []
@@ -215,14 +233,19 @@ class test_constellation(gr_unittest.TestCase):
y_cpp_raw_calc = []
y_cpp_table = []
for sample in samples:
- y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code))
+ y_python_raw_calc += slicer(
+ digital.calc_soft_dec(
+ sample, constel, code))
y_python_gen_calc += slicer(digital.sd_psk_4_0(sample, Es))
- y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es))
+ y_python_table += slicer(
+ digital.calc_soft_dec_from_table(
+ sample, table, prec, Es))
y_cpp_raw_calc += c.calc_soft_dec(sample)
y_cpp_table += c.soft_decision_maker(sample)
- self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_gen_calc, 0)
+ self.assertFloatTuplesAlmostEqual(
+ y_python_raw_calc, y_python_gen_calc, 0)
self.assertFloatTuplesAlmostEqual(y_python_gen_calc, y_python_table, 0)
self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0)
@@ -244,20 +267,29 @@ class test_constellation(gr_unittest.TestCase):
c.gen_soft_dec_lut(prec)
x = sqrt(2.0) / 2.0
- step = (x.real+x.real) / (2**prec - 1)
- samples = [ -x-x*1j, -x+x*1j,
- x+x*1j, x-x*1j,
- (-x+128*step)+(-x+128*step)*1j,
- (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j,
- (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,]
+ step = (x.real + x.real) / (2**prec - 1)
+ samples = [-x - x * 1j,
+ -x + x * 1j,
+ x + x * 1j,
+ x - x * 1j,
+ (-x + 128 * step) + (-x + 128 * step) * 1j,
+ (-x + 64 * step) + (-x + 64 * step) * 1j,
+ (-x + 64 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 64 * step) * 1j,
+ ]
y_python_raw_calc = []
y_python_table = []
y_cpp_raw_calc = []
y_cpp_table = []
for sample in samples:
- y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code))
- y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es))
+ y_python_raw_calc += slicer(
+ digital.calc_soft_dec(
+ sample, constel, code))
+ y_python_table += slicer(
+ digital.calc_soft_dec_from_table(
+ sample, table, prec, Es))
y_cpp_raw_calc += slicer(c.calc_soft_dec(sample))
y_cpp_table += slicer(c.soft_decision_maker(sample))
@@ -265,7 +297,6 @@ class test_constellation(gr_unittest.TestCase):
self.assertEqual(y_python_raw_calc, y_python_table)
self.assertEqual(y_cpp_raw_calc, y_cpp_table)
-
def test_soft_qam16_calc(self):
prec = 8
constel, code = digital.qam_16_0()
@@ -284,20 +315,29 @@ class test_constellation(gr_unittest.TestCase):
c.gen_soft_dec_lut(prec)
x = sqrt(2.0) / 2.0
- step = (x.real+x.real) / (2**prec - 1)
- samples = [ -x-x*1j, -x+x*1j,
- x+x*1j, x-x*1j,
- (-x+128*step)+(-x+128*step)*1j,
- (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j,
- (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,]
+ step = (x.real + x.real) / (2**prec - 1)
+ samples = [-x - x * 1j,
+ -x + x * 1j,
+ x + x * 1j,
+ x - x * 1j,
+ (-x + 128 * step) + (-x + 128 * step) * 1j,
+ (-x + 64 * step) + (-x + 64 * step) * 1j,
+ (-x + 64 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 192 * step) * 1j,
+ (-x + 192 * step) + (-x + 64 * step) * 1j,
+ ]
y_python_raw_calc = []
y_python_table = []
y_cpp_raw_calc = []
y_cpp_table = []
for sample in samples:
- y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code))
- y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es))
+ y_python_raw_calc += slicer(
+ digital.calc_soft_dec(
+ sample, constel, code))
+ y_python_table += slicer(
+ digital.calc_soft_dec_from_table(
+ sample, table, prec, Es))
y_cpp_raw_calc += slicer(c.calc_soft_dec(sample))
y_cpp_table += slicer(c.soft_decision_maker(sample))
@@ -305,15 +345,18 @@ class test_constellation(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_table, 0)
self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0)
+
class mod_demod(gr.hier_block2):
def __init__(self, constellation, differential, rotation):
if constellation.arity() > 256:
# If this becomes limiting some of the blocks should be generalised so
# that they can work with shorts and ints as well as chars.
- raise ValueError("Constellation cannot contain more than 256 points.")
+ raise ValueError(
+ "Constellation cannot contain more than 256 points.")
gr.hier_block2.__init__(self, "mod_demod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(
+ 1, 1, gr.sizeof_char), # Input signature
gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
arity = constellation.arity()
@@ -334,13 +377,17 @@ class mod_demod(gr.hier_block2):
# Apply any pre-differential coding
# Gray-coding is done here if we're also using differential coding.
if self.constellation.apply_pre_diff_code():
- self.blocks.append(digital.map_bb(self.constellation.pre_diff_code()))
+ self.blocks.append(
+ digital.map_bb(
+ self.constellation.pre_diff_code()))
# Differential encoding.
if self.differential:
self.blocks.append(digital.diff_encoder_bb(arity))
# Convert to constellation symbols.
- self.blocks.append(digital.chunks_to_symbols_bc(self.constellation.points(),
- self.constellation.dimensionality()))
+ self.blocks.append(
+ digital.chunks_to_symbols_bc(
+ self.constellation.points(),
+ self.constellation.dimensionality()))
# CHANNEL
# Channel just consists of a rotation to check differential coding.
if rotation is not None:
@@ -348,7 +395,9 @@ class mod_demod(gr.hier_block2):
# RX
# Convert the constellation symbols back to binary values.
- self.blocks.append(digital.constellation_decoder_cb(self.constellation.base()))
+ self.blocks.append(
+ digital.constellation_decoder_cb(
+ self.constellation.base()))
# Differential decoding.
if self.differential:
self.blocks.append(digital.diff_decoder_bb(arity))
@@ -358,7 +407,7 @@ class mod_demod(gr.hier_block2):
mod_codes.invert_code(self.constellation.pre_diff_code())))
# unpack the k bit vector into a stream of bits
self.blocks.append(blocks.unpack_k_bits_bb(
- self.constellation.bits_per_symbol()))
+ self.constellation.bits_per_symbol()))
# connect to block output
check_index = len(self.blocks)
self.blocks = self.blocks[:check_index]
@@ -366,5 +415,6 @@ class mod_demod(gr.hier_block2):
self.connect(*self.blocks)
+
if __name__ == '__main__':
gr_unittest.run(test_constellation)