def test_101b(self): random.seed(0) src_data = [] for i in xrange(100): src_data.append((random.randint(-2**15, 2**15 - 1))) src_data = tuple(src_data) expected_results = src_data src = gr.vector_source_s(tuple(src_data), False) op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) dst = gr.vector_sink_s() self.tb.connect(src, op1, op2) self.tb.connect(op2, dst) self.tb.run() self.assertEqual(expected_results, dst.data())
def test_101b(self): random.seed(0) src_data = [] for i in xrange(100): src_data.append((random.randint(-2**15,2**15-1))) src_data = tuple(src_data) expected_results = src_data src = blocks.vector_source_s(tuple(src_data), False) op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) dst = blocks.vector_sink_s() self.tb.connect(src, op1, op2) self.tb.connect(op2, dst) self.tb.run() self.assertEqual(expected_results, dst.data())
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)