def test_sc_005(self): const = [1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = (1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j, 0 - 1j, -1 + 0j, 0 + 1j, 1 + 0j) src = blocks.vector_source_s(src_data) op = digital.chunks_to_symbols_sc(const) dst = blocks.vector_sink_c() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() actual_result = dst.data() self.assertEqual(expected_result, actual_result)
def test_sc_005(self): const = [ 1+0j, 0+1j, -1+0j, 0-1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = (1+0j, 0+1j, -1+0j, 0-1j, 0-1j, -1+0j, 0+1j, 1+0j) src = gr.vector_source_s(src_data) op = digital.chunks_to_symbols_sc(const) dst = gr.vector_sink_c() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() actual_result = dst.data() self.assertEqual(expected_result, actual_result)
def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024 * 16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size / bitspersymbol # TX src = blocks.lfsr_32k_source_s() # packet size in shorts src_head = blocks.head(gr.sizeof_short, packet_size / 16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = digital.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf(constellation.base(), digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = blocks.check_lfsr_32k_s() self.connect(src, src_head, s2fsmi, enc, mod) self.connect(mod, (add, 0)) self.connect(noise, (add, 1)) self.connect(add, metrics, va, fsmi2s, self.dst)