def test_soft_qpsk_gen(self): prec = 8 constel, code = digital.psk_4_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_generator(digital.sd_psk_4_0, prec, Es) 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, ] y_python_raw_calc = [] y_python_gen_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_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_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_gen_calc, y_python_table, 0) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0)
def test_soft_qpsk_gen(self): prec = 8 constel, code = digital.psk_4_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_generator(digital.sd_psk_4_0, prec, Es) 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,] y_python_raw_calc = [] y_python_gen_calc = [] y_python_table = [] y_cpp_raw_calc = [] y_cpp_table = [] for sample in samples: y_python_raw_calc += digital.calc_soft_dec(sample, constel, code) y_python_gen_calc += digital.sd_psk_4_0(sample, Es) y_python_table += 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, 4) self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_table, 2) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 4)
def helper_with_lut(self, prec, src_data, const_gen, const_sd_gen): cnst_pts, code = const_gen() Es = max([abs(c) for c in cnst_pts]) lut = digital.soft_dec_table_generator(const_sd_gen, prec, Es) expected_result = list() for s in src_data: res = digital.calc_soft_dec_from_table(s, lut, prec, sqrt(2.0)) expected_result += res cnst = digital.constellation_calcdist(cnst_pts, code, 2, 1) cnst.set_soft_dec_lut(lut, int(prec)) src = blocks.vector_source_c(src_data) op = digital.constellation_soft_decoder_cf(cnst.base()) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() actual_result = dst.data() # fetch the contents of the sink #print "actual result", actual_result #print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 5)
def helper_with_lut(self, prec, src_data, const_gen, const_sd_gen): cnst_pts, code = const_gen() Es = max([abs(c) for c in cnst_pts]) lut = digital.soft_dec_table_generator(const_sd_gen, prec, Es) expected_result = list() for s in src_data: res = digital.calc_soft_dec_from_table(s, lut, prec, sqrt(2.0)) expected_result += res cnst = digital.constellation_calcdist(cnst_pts, code, 2, 1) cnst.set_soft_dec_lut(lut, int(prec)) src = blocks.vector_source_c(src_data) op = digital.constellation_soft_decoder_cf(cnst.base()) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() actual_result = dst.data() # fetch the contents of the sink # print "actual result", actual_result # print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 5)
def test_constellation_soft_decoder_cf_qam16(self): prec = 8 src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j, 0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j, 1+1j) lut = digital.soft_dec_table_generator(digital.sd_qam_16_0x0_0_1_2_3, prec) expected_result = list() for s in src_data: expected_result += digital.calc_soft_dec_from_table(s, lut, prec) cnst_pts = digital.qam_16_0x0_0_1_2_3() cnst = digital.constellation_calcdist(cnst_pts[0], cnst_pts[1], 2, 1) cnst.set_soft_dec_lut(lut, int(prec)) src = blocks.vector_source_c(src_data) op = digital.constellation_soft_decoder_cf(cnst.base()) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() # run the graph and wait for it to finish actual_result = dst.data() # fetch the contents of the sink #print "actual result", actual_result #print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 5)