def test_002_t(self): """Encoder to Decoder - noisy BPSK w/ soft constellation de-mapper""" # Parameters N = 18444 K = 6144 pct_en = False n_ite = 6 M = 2 snr_db = SNR_DB max_len = 10 * K flip_llrs = False sym_rate = 2 * 156250 # NOTE: The soft decoder block outputs positive LLR if bit "1" is more # likely, and negative LLR otherwise (bit = 0). That is, the soft # de-mapper's convention is the oposite of the one adopted in the Turbo # Decoder. To compensate that, we choose to flip the LLRs (multiply them # by "-1") inside the decoder wrapper. # Constants noise_v = 1 / math.sqrt((10**(float(snr_db) / 10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0, 1) for i in range(0, max_len)]) # Flowgraph src = blocks.vector_source_b(in_vec) enc = blocksattx.turbo_encoder(K, pct_en) const = digital.constellation_bpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) cdemap = blocksat.soft_decoder_cf(M, noise_v) dec = blocksat.turbo_decoder(K, pct_en, n_ite, flip_llrs) snk = blocks.vector_sink_b() snk_sym = blocks.vector_sink_c() snk_llr = blocks.vector_sink_f() self.tb.connect(src, enc, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, cdemap, dec, snk) self.tb.connect(cmap, snk_sym) self.tb.connect(cdemap, snk_llr) self.tb.run() # Collect results out_vec = snk.data() llrs = snk_llr.data() syms = snk_sym.data() diff = array(in_vec) - array(out_vec) err = [0 if i == 0 else 1 for i in diff] self.dump(const.points(), in_vec, syms, llrs, out_vec) print('Number of errors: %d' % (sum(err))) # Check results self.assertEqual(sum(err), 0)
def test_003_t(self): """Encoder to Decoder - noisy QPSK w/ soft constellation de-mapper""" # Parameters N = 18444 K = 6144 pct_en = False n_ite = 6 M = 4 snr_db = SNR_DB max_len = 10 * K flip_llrs = False sym_rate = 2 * 156250 # NOTE: just like in the previous example, flipping of the LLRs is # necessary here. # Constants noise_v = 1 / math.sqrt((10**(float(snr_db) / 10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0, 1) for i in range(0, max_len)]) # Flowgraph src = blocks.vector_source_b(in_vec) enc = blocksattx.turbo_encoder(K, pct_en) pack = blocks.repack_bits_bb(1, 2, "", False, gr.GR_MSB_FIRST) const = digital.constellation_qpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) cdemap = blocksat.soft_decoder_cf(M, noise_v) dec = blocksat.turbo_decoder(K, pct_en, n_ite, flip_llrs) snk = blocks.vector_sink_b() snk_sym = blocks.vector_sink_c() snk_llr = blocks.vector_sink_f() self.tb.connect(src, enc, pack, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, cdemap, dec, snk) self.tb.connect(cmap, snk_sym) self.tb.connect(cdemap, snk_llr) self.tb.run() # Collect results out_vec = snk.data() llrs = snk_llr.data() syms = snk_sym.data() diff = array(in_vec) - array(out_vec) err = [0 if i == 0 else 1 for i in diff] self.dump(const.points(), in_vec, syms, llrs, out_vec) print('Number of errors: %d' % (sum(err))) # Check results self.assertEqual(sum(err), 0)
def test_001_t(self): """QPSK points in each quadrant""" # Parameters M = 4 N0 = 1.0 symbol = ((-0.5 - 0.5j), (0.5 - 0.5j), (-0.5 + 0.5j), (0.5 + 0.5j)) # Flowgraph src = blocks.vector_source_c(symbol) soft_decoder = blocksat.soft_decoder_cf(M, N0) snk = blocks.vector_sink_f() self.tb.connect(src, soft_decoder, snk) self.tb.run() # Check data llrs = snk.data() expected_llrs = (1.4142, 1.4142, 1.4142, -1.4142, -1.4142, 1.4142, -1.4142, -1.4142) print(llrs) self.assertFloatTuplesAlmostEqual(llrs, expected_llrs, places=4)
def test_002_t(self): """Decoding of noisy QPSK symbols""" # Parameters M = 4 N0 = 1.0 max_len = 50 snr_db = 20 # Constants rndm = random.Random() noise_v = 1 / math.sqrt((10**(float(snr_db) / 10))) in_vec = tuple([rndm.randint(0, 1) for i in range(0, max_len)]) # Flowgraph src = blocks.vector_source_b(in_vec) pack = blocks.repack_bits_bb(1, 2, "", False, gr.GR_MSB_FIRST) const = digital.constellation_qpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) soft_decoder = blocksat.soft_decoder_cf(M, N0) slicer = digital.binary_slicer_fb() inverter = digital.map_bb([1, 0]) snk = blocks.vector_sink_b() snk_llr = blocks.vector_sink_f() self.tb.connect(src, pack, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, soft_decoder, slicer, inverter, snk) self.tb.connect(soft_decoder, snk_llr) self.tb.run() # check data dec_vec = snk.data() llrs = snk_llr.data() print(llrs) print(in_vec) print(dec_vec) self.assertFloatTuplesAlmostEqual(in_vec, dec_vec, places=4)