def test_soft_qam16_calc(self): prec = 8 constel, code = digital.qam_16_0() rot_sym = 1 side = 2 width = 2 c = digital.constellation_rect(constel, code, rot_sym, side, side, width, width) # Get max energy/symbol in constellation constel = c.points() Es = max([abs(constel_i) for constel_i in constel]) table = digital.soft_dec_table(constel, code, prec) 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, ] 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_cpp_raw_calc += slicer(c.calc_soft_dec(sample)) y_cpp_table += slicer(c.soft_decision_maker(sample)) self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_table, 0) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0)
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_soft_qam16_calc(self): prec = 8 constel, code = digital.qam_16_0() rot_sym = 1 side = 2 width = 2 c = digital.constellation_rect(constel, code, rot_sym, side, side, width, width) # Get max energy/symbol in constellation constel = c.points() Es = max([abs(constel_i) for constel_i in constel]) table = digital.soft_dec_table(constel, code, prec) 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,] 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_cpp_raw_calc += slicer(c.calc_soft_dec(sample)) y_cpp_table += slicer(c.soft_decision_maker(sample)) self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_table, 0) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0)