From 0a4225dc9dd9e4d3c5ad58d40570d40d59f5670f Mon Sep 17 00:00:00 2001 From: David Pi <david.pinho@gmail.com> Date: Sat, 17 Jul 2021 13:25:03 +0100 Subject: gr-digital: Fix constellation normalization by average power Correct power normalization calculation. Add a qa test for amplitude and power normalization. Signed-off-by: David Pi <david.pinho@gmail.com> --- gr-digital/python/digital/qa_constellation.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'gr-digital/python/digital/qa_constellation.py') diff --git a/gr-digital/python/digital/qa_constellation.py b/gr-digital/python/digital/qa_constellation.py index d13dae376e..7c9984405f 100644 --- a/gr-digital/python/digital/qa_constellation.py +++ b/gr-digital/python/digital/qa_constellation.py @@ -16,7 +16,8 @@ import numpy from gnuradio import gr, gr_unittest, digital, blocks from gnuradio.digital.utils import mod_codes -from gnuradio.digital import psk, qam, qamlike +from gnuradio.digital import constellation, psk, qam, qamlike +import numpy as np tested_mod_codes = (mod_codes.NO_CODE, mod_codes.GRAY_CODE) @@ -178,6 +179,26 @@ class test_constellation(gr_unittest.TestCase): def tearDown(self): pass + def test_normalization(self): + rot_sym = 1 + side = 2 + width = 2 + # Test a couple of basic constellations + for constel_points, code in (digital.psk_4_0(), digital.qam_16_0()): + constel = digital.constellation_rect(constel_points, code, rot_sym, + side, side, width, width, + constellation.POWER_NORMALIZATION) + + points = np.array(constel.points()) + avg_power = np.sum(abs(points)**2) / len(points) + self.assertAlmostEqual(avg_power, 1.0, 6) + constel = digital.constellation_rect(constel_points, code, rot_sym, + side, side, width, width, + constellation.AMPLITUDE_NORMALIZATION) + points = np.array(constel.points()) + avg_amp = np.sum(abs(points)) / len(points) + self.assertAlmostEqual(avg_amp, 1.0, 6) + def test_hard_decision(self): for constellation, differential in tested_constellations(): if differential: -- cgit v1.2.3