Example #1
0
    def test_001(self):
        tb = self.tb

        src1_data = (0,0.2,-0.3,0,12,0)
        src2_data = (0,0.0,3.0,0,10,0)
        src3_data = (0,0.0,3.0,0,1,0)

        src1 = blocks.vector_source_f(src1_data)
        s2v1 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src1, s2v1)

        src2 = blocks.vector_source_f(src2_data)
        s2v2 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src2, s2v2)

        src3 = blocks.vector_source_f(src3_data)
        s2v3 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src3, s2v3)

        dst1 = blocks.vector_sink_s()
        dst2 = blocks.vector_sink_s()
        argmax = blocks.argmax_fs(len(src1_data))

        tb.connect(s2v1, (argmax, 0))
        tb.connect(s2v2, (argmax, 1))
        tb.connect(s2v3, (argmax, 2))

        tb.connect((argmax,0), dst1)
        tb.connect((argmax,1), dst2)

        tb.run()
        index = dst1.data()
        source = dst2.data()
        self.assertEqual(index, (4,))
        self.assertEqual(source, (0,))
 def test_001_t (self):
     src = ofdm.allocation_src(6,3,"tcp://*:3333")
     src.set_allocation([2]*6,[3]*6)
     #skiphead = blocks.skiphead( gr.sizeof_float, 8 )
     limit_id = blocks.head( gr.sizeof_short, 4 )
     limit_bitcount = blocks.head( gr.sizeof_int, 4 )
     limit_bitloading = blocks.head( gr.sizeof_char*6, 4 )
     limit_power = blocks.head( gr.sizeof_gr_complex*6, 4 )
     dst_id = blocks.vector_sink_s()
     dst_bitcount = blocks.vector_sink_i()
     dst_bitloading = blocks.vector_sink_b(6)
     dst_power = blocks.vector_sink_c(6)
     self.tb.connect((src,0),limit_id,dst_id)
     self.tb.connect((src,1),limit_bitcount,dst_bitcount)
     self.tb.connect((src,2),limit_bitloading,dst_bitloading)
     self.tb.connect((src,3),limit_power,dst_power)
     # set up fg
     self.tb.run ()
     # check data
     result_id = dst_id.data()
     result_bitcount = dst_bitcount.data()
     result_bitloading = dst_bitloading.data()
     result_power = dst_power.data()
     print "id", result_id
     print "bitcount", result_bitcount
     print "bitloading", result_bitloading
     print "power", result_power
Example #3
0
 def do(self, data_src, data_exp, test_block):
     src = blocks.vector_source_b(data_src)
     self.tb.connect(src, test_block)
     dst = blocks.vector_sink_s()
     self.tb.connect(test_block, dst)
     self.tb.run()
     result_data = tuple([int(x) for x in dst.data()])
     self.assertEqual(data_exp, result_data)
 def test_char_to_short(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (256, 512, 768, 1024, 1280)
     src = blocks.vector_source_b(src_data)
     op = blocks.char_to_short()
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
 def test_complex_to_interleaved_short(self):
     src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
     expected_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_interleaved_short()
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #6
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = ArgumentParser()
        args = parser.parse_args()
        src = blocks.lfsr_32k_source_s()
        head = blocks.head(gr.sizeof_short, 2048)
        self.dst = blocks.vector_sink_s()
        self.connect(src, head, self.dst)
Example #7
0
    def test_000_ss(self):
	src_data = (1, 2, 3, 4, 5, 6)
	dst_data = (6, 15)
	src = blocks.vector_source_s(src_data)
	itg = blocks.integrate_ss(3)
	dst = blocks.vector_sink_s()
	self.tb.connect(src, itg, dst)
	self.tb.run()
	self.assertEqual(dst_data, dst.data())
Example #8
0
    def help_const_ss(self, src_data, exp_data, op):
	src = blocks.vector_source_s(src_data)
	srcv = blocks.stream_to_vector(gr.sizeof_short, len(src_data))
	rhs = blocks.vector_to_stream(gr.sizeof_short, len(src_data))
        dst = blocks.vector_sink_s()
        self.tb.connect(src, srcv, op, rhs, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(exp_data, result_data)
 def test_float_to_short_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_short(1, 5)
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
 def test_float_to_short_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_short()
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
 def help_ss (self, src_data, exp_data, op):
     for s in zip (range (len (src_data)), src_data):
         src = blocks.vector_source_s (s[1])
         self.tb.connect (src, (op, s[0]))
     dst = blocks.vector_sink_s ()
     self.tb.connect (op, dst)
     self.tb.run ()
     result_data = dst.data ()
     self.assertEqual (exp_data, result_data)
 def test_and_const_ss (self):
     src_data =        (1,  2,  3,  0x5004,   0x1150)
     expected_result = (0,  2,  2,  0x5000,   0x1100)
     src = blocks.vector_source_s(src_data)
     op = blocks.and_const_ss (0x55AA)
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_result)
Example #13
0
 def test001_module_load (self):
     data = (0,16,36,40,68,104,148,220,320,512)
     src = blocks.vector_source_s(data)
     enc = vocoder.g723_24_encode_sb()
     dec = vocoder.g723_24_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #14
0
 def test001_module_load (self):
     data = (0,8,36,72,100,152,228,316,404,528)
     src = blocks.vector_source_s(data)
     enc = vocoder.g723_40_encode_sb()
     dec = vocoder.g723_40_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #15
0
    def test_004_ss_vec(self):
	src_data = (1, 2, 3, 4, 5, 6)
	dst_data = (9, 12)
	vlen = 2
	src = blocks.vector_source_s(src_data, False, vlen)
	itg = blocks.integrate_ss(3, vlen)
	dst = blocks.vector_sink_s(vlen)
	self.tb.connect(src, itg, dst)
	self.tb.run()
	self.assertEqual(dst_data, dst.data())
    def test_sub_ss1(self):
        src1_data = (1, 2, 3, 4, 5)
        expected_result = (1, 2, 3, 4, 5)

        src = blocks.vector_source_s(src1_data)
        op = blocks.sub_ss()
        dst = blocks.vector_sink_s()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #17
0
 def test001_module_load(self):
     data = (8, 24, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184,
             200, 216, 232, 248, 264, 280, 296, 312, 328, 344)
     src = blocks.vector_source_s(data)
     enc = vocoder.alaw_encode_sb()
     dec = vocoder.alaw_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(list(data), actual_result)
Example #18
0
 def test_001_square_bb(self):
     src_data = (2, 3, 4, 5, 6)
     expected_result = (4, 9, 16, 25, 36)
     src = blocks.vector_source_s(src_data)
     sqr = howtogen.square_ss()
     dst = blocks.vector_sink_s()
     self.tb.connect(src, sqr)
     self.tb.connect(sqr, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
Example #19
0
 def test001_module_load (self):
     data = (8,24,36,52,56,64,76,88,104,124,132,148,172,
             196,220,244,280,320,372,416,468,524,580,648)
     src = blocks.vector_source_s(data)
     enc = vocoder.g721_encode_sb()
     dec = vocoder.g721_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #20
0
    def test_sub_ss1(self):
        src1_data = (1, 2, 3, 4, 5)
        expected_result = (1, 2, 3, 4, 5)

        src = blocks.vector_source_s(src1_data)
        op = blocks.sub_ss()
        dst = blocks.vector_sink_s()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #21
0
 def test001_module_load (self):
     data = (8,24,36,52,56,64,76,88,104,124,132,148,172,
             196,220,244,280,320,372,416,468,524,580,648)
     src = blocks.vector_source_s(data)
     enc = vocoder.g721_encode_sb()
     dec = vocoder.g721_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #22
0
 def test001_module_load(self):
     data = (8, 24, 40, 56, 72, 88, 104, 120, 132, 148, 164, 180, 196, 212,
             228, 244, 260, 276, 292, 308, 324, 340)
     src = blocks.vector_source_s(data)
     enc = vocoder.ulaw_encode_sb()
     dec = vocoder.ulaw_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #23
0
 def test001_module_load (self):
     data = (8,24,40,56,72,88,104,120,132,148,164,180,
             196,212,228,244,260,276,292,308,324,340)
     src = blocks.vector_source_s(data)
     enc = vocoder.ulaw_encode_sb()
     dec = vocoder.ulaw_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #24
0
 def test001_module_load (self):
     data = (8,24,40,56,72,88,104,120,136,152,168,184,
             200,216,232,248,264,280,296,312,328,344)
     src = blocks.vector_source_s(data)
     enc = vocoder.alaw_encode_sb()
     dec = vocoder.alaw_decode_bs()
     snk = blocks.vector_sink_s()
     self.tb.connect(src, enc, dec, snk)
     self.tb.run()
     actual_result = snk.data()
     self.assertEqual(data, actual_result)
Example #25
0
File: app2.py Project: WiLab/gr-iio
 def __init__(self):
     gr.top_block.__init__(self)
     test = (1,2,3)
     test_src = blocks.vector_source_s(test)
     src = iio.fmcomms_source()
     sink = blocks.vector_sink_s()
     self.connect(src,sink)
     self.start()
     sleep(0.05)
     self.stop()
     result = sink.data()
     print(result)
Example #26
0
    def help_ss(self, size, src_data, exp_data, op):
        for s in zip(range (len (src_data)), src_data):
            src = blocks.vector_source_s(s[1])
	    srcv = blocks.stream_to_vector(gr.sizeof_short, size)
	    self.tb.connect(src, srcv)
            self.tb.connect(srcv, (op, s[0]))
	rhs = blocks.vector_to_stream(gr.sizeof_short, size)
        dst = blocks.vector_sink_s()
        self.tb.connect(op, rhs, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(exp_data, result_data)
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality,
             tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = blocks.vector_source_s(packet, False)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    skip = blocks.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    #va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = blocks.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    #tb.connect (add,metrics)
    #tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Example #28
0
 def test_fir_filter_fsf_002(self):
     src_data = 40*[1, 2, 3, 4]
     expected_data = (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 50, 50, 50, 50,
                      50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
                      50, 50, 50, 50, 50, 50, 50, 50, 50, 50)
     src = blocks.vector_source_f(src_data)
     op  = filter.fir_filter_fsf(4, 20*[0.5, 0.5])
     dst = blocks.vector_sink_s()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
Example #29
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        src = blocks.lfsr_32k_source_s()
        head = blocks.head(gr.sizeof_short, 2048)
        self.dst = blocks.vector_sink_s()
        self.connect(src, head, self.dst)
Example #30
0
    def test_001(self):
        tb = self.tb

        src1_data = [0, 0.2, -0.3, 0, 12, 0]
        src2_data = [0, 0.0, 3.0, 0, 10, 0]
        src3_data = [0, 0.0, 3.0, 0, 1, 0]

        src1 = blocks.vector_source_f(src1_data)
        s2v1 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src1, s2v1)

        src2 = blocks.vector_source_f(src2_data)
        s2v2 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src2, s2v2)

        src3 = blocks.vector_source_f(src3_data)
        s2v3 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data))
        tb.connect(src3, s2v3)

        dst1 = blocks.vector_sink_s()
        dst2 = blocks.vector_sink_s()
        argmax = blocks.argmax_fs(len(src1_data))

        tb.connect(s2v1, (argmax, 0))
        tb.connect(s2v2, (argmax, 1))
        tb.connect(s2v3, (argmax, 2))

        tb.connect((argmax, 0), dst1)
        tb.connect((argmax, 1), dst2)

        tb.run()
        index = dst1.data()
        source = dst2.data()
        self.assertEqual(index, [
            4,
        ])
        self.assertEqual(source, [
            0,
        ])
Example #31
0
    def test_001_short(self):
        tb = gr.top_block()

        data = [5, 0, 0, -1, -3, -10]
        exp = [1, 0, 0, -1, -1, -1]
        vlen = 1
        src = blocks.vector_source_s(data, False, vlen)
        sign = misc.signum_xx(misc.SHORT, vlen)
        snk = blocks.vector_sink_s(vlen)
        tb.connect(src, sign, snk)
        tb.run()
        res = snk.data()
        self.assertTupleEqual(res, tuple(exp))
    def test_001(self):
        src_data = [1,2,3,4]
        expected_result = [256, 512, 768, 1024];

        src = blocks.vector_source_s(src_data)
        op = blocks.endian_swap(2)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = list(dst.data())

        self.assertEqual(expected_result, result_data)
Example #33
0
    def test_001(self):
        src_data = [1,2,3,4]
        expected_result = [256, 512, 768, 1024];

        src = blocks.vector_source_s(src_data)
        op = blocks.endian_swap(2)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = list(dst.data())

        self.assertEqual(expected_result, result_data)
Example #34
0
    def stest_s001(self):
        src_data = (0, 2, -3, 0, 12, 0)
        expected_result = (max(src_data),)

        src = blocks.vector_source_s(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_short,len(src_data))
        op = blocks.max_ss(len(src_data))
        dst = blocks.vector_sink_s()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #35
0
    def test001_module_load (self):
        data = 40*(100,200,300,400,500,600,700,800)
        expected_data = (0, 5, 10, 14, 15, 13, 14, 20, 40, 46, 39, 36, 35, 33, 22, 17, 31, 34, 29, 24, 24, 15, -3, -8, -7, 1, -4, -11, -14, -22, -39, -53, -51, -52, -58, -58, -59, -58, -61, -74, -73, -79, -75, -61, -73, -76, -72, -75, -62, -74, -75, -64, -64, -59, -61, -49, -68, -60, -23, -46, -48, -33, -48, 2, 20, -3, 2, -8, 9, 38, 9, 16, 23, 16, 44, 65, 37, 24, 25, 55, 61, 57, 52, 39, 47, 57, 66, 73, 50, 46, 47, 55, 55, 45, 73, 86, 63, 66, 60, 55, 60, 55, 71, 59, 46, 58, 46, 2, 38, 50, 33, 41, 32, 0, -16, -11, 10, 16, -13, 0, -5, -33, -45, -38, -28, -24, -41, 21, -2, -53, -55, -74, -66, -64, -64, -41, -46, -94, -122, -130, -92, -126, -104, -90, -74, -118, -162, -154, -130, -133, -163, -18, -23, -155, -95, -145, -60, -63, 156, 864, 882, 607, 449, 163, 204, 17, 47, 612, 447, 200, -59, -188, -175, -418, -192, 170, 14, -73, -258, -276, -267, -335, -117, 96, 34, -28, -152, -130, -124, -187, 42, 176, 131, 78, -52, -2, -57, -75, 104, 130, 111, 29, -50, -46, -107, -64, 66, 36, 33, -39, -129, -91, -157, -39, 69, 1, -12, -84, -99, -52, -61, 86, 147, 58, 21, -63, -60, -100, -48, 68, 76, 6, -65, -79, -108, -159, -71, 89, 171, 183, 216, 152, 26, -35, 0, 87, 126, 143, 182, 151, 95, 106, 115, 155, 103, 86, 127, 12, -41, -91, -87, -32, -52, -41, -32, -123, -147, -154, -156, -61, -37, -8, -51, -127, -132, -127, -107, -54, 1, 26, -17, -100, -61, -9, 3, 57, 117, 102, 58, -47, 24, 67, 42, 116, 141, 113, 39, -15, 63, 68, 41, 118, 80, 24, -46, -72, 12, 5, -17, 18, -43, -61, -110, -119, -42, -40, -16, 2, -11, -50)

        src = blocks.vector_source_s(data)
        enc = vocoder.codec2_encode_sp(codec2.MODE_2400)
        dec = vocoder.codec2_decode_ps(codec2.MODE_2400)
        snk = blocks.vector_sink_s()
        self.tb.connect(src, enc, dec, snk)
        self.tb.run()
        actual_result = snk.data()
        self.assertEqual(expected_data, actual_result)
        self.tb.disconnect(src, enc, dec, snk)
Example #36
0
    def stest_s002(self):
        src_data = (-100, -99, -98, -97, -96, -1)
        expected_result = (max(src_data), )

        src = blocks.vector_source_s(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data))
        op = blocks.max_ss(len(src_data))
        dst = blocks.vector_sink_s()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #37
0
    def stest_s002(self):
        src_data=(-100,-99,-98,-97,-96,-1)
        expected_result = (min(src_data),)

        src = blocks.vector_source_s(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data))
        op = blocks.min_ss(len(src_data))
        dst = blocks.vector_sink_s()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #38
0
    def stest_s001(self):
        src_data = (0, 2, -3, 0, 12, 0)
        expected_result = (min(src_data),)

        src = blocks.vector_source_s(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_short,len(src_data))
        op = blocks.min_ss(len(src_data))
        dst = blocks.vector_sink_s()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #39
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        src = blocks.lfsr_32k_source_s()
        head = blocks.head(gr.sizeof_short, 2048)
        self.dst = blocks.vector_sink_s()
        self.connect(src, head, self.dst)
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality, tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2 ** bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = blocks.vector_source_s(packet, False)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    skip = blocks.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    # metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    # va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation, digital.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = blocks.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    # tb.connect (add,metrics)
    # tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        # else:
        # print "Error in ", i

    return (ntotal, ntotal - nright)
Example #41
0
    def test_fir_filter_fsf_002(self):
        decim = 4
        taps = 20 * [0.5, 0.5]
        src_data = 40 * [1, 2, 3, 4]
        expected_data = fir_filter(src_data, taps, decim)
        expected_data = [int(e) for e in expected_data]

        src = blocks.vector_source_f(src_data)
        op = filter.fir_filter_fsf(decim, taps)
        dst = blocks.vector_sink_s()
        self.tb.connect((src, op, dst))
        self.tb.run()
        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5)
Example #42
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed):
    tb = gr.top_block()

    # TX
    numpy.random.seed(-seed)
    packet = numpy.random.randint(0, 2, Kb)  # create Kb random bits
    packet[Kb - 10:Kb] = 0
    packet[0:Kb] = 0
    src = blocks.vector_source_s(packet.tolist(), False)
    b2s = blocks.unpacked_to_packed_ss(1,
                                       gr.GR_MSB_FIRST)  # pack bits in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f, 0)  # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2),
                                  long(seed))

    # RX
    va = trellis.viterbi_combined_fs(
        f, K, 0, 0, dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    s2b = blocks.packed_to_unpacked_ss(
        1, gr.GR_MSB_FIRST)  # unpack shorts to bits
    dst = blocks.vector_sink_s()

    tb.connect(src, b2s, s2fsmi, enc, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, va, fsmi2s, s2b, dst)

    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    if len(dst.data()) != len(packet):
        print "Error: not enough data:", len(dst.data()), len(packet)
    ntotal = len(packet)
    nwrong = sum(abs(packet - numpy.array(dst.data())))
    return (ntotal, nwrong, abs(packet - numpy.array(dst.data())))
Example #43
0
 def test_002_short(self):
     minimum = 42
     maximum = 1025
     seed = 3
     n_items = 10000
     rnd_src = analog.random_uniform_source_s(minimum, maximum, seed)
     head = blocks.head(2, n_items)
     snk = blocks.vector_sink_s(1)
     self.tb.connect(rnd_src, head, snk)
     # set up fg
     self.tb.run()
     # check data
     res = snk.data()
     self.assertGreaterEqual(minimum, np.min(res))
     self.assertLess(np.max(res), maximum)
Example #44
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the outer FSM input cardinality
    #src = blocks.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False)
    enc = trellis.pccc_encoder_ss(fo, 0, fi, 0, interleaver, K)
    code = blocks.vector_sink_s()
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    metrics_in = trellis.metrics_f(
        fi.O() * fo.O(), dimensionality, constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner SISO
    scale = blocks.multiply_const_ff(1.0 / N0)
    dec = trellis.pccc_decoder_s(fo, 0, -1, fi, 0, -1, interleaver, K, IT,
                                 trellis.TRELLIS_MIN_SUM)

    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc, mod)
    #tb.connect (src,enc,mod)
    #tb.connect(enc,code)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in, scale, dec, fsmi2s, dst)

    tb.run()

    #print code.data()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
Example #45
0
    def test_002_t (self):
        # set up fg
        src_data = (1, 3, 5, 9, 10, 12, 17, 19, 21)
        expected_result = (2, 6, 10, 18, 20, 24, 34, 38, 42)
        src = blocks.vector_source_s(src_data)
        path = os.path.dirname(__file__) if len(os.path.dirname(__file__)) != 0 else '.'
        vl = verilog.verilog_axi_bb(path + "/testcases/double/double_axi.v", True, 1.0, "", 0, 0)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, vl)
        self.tb.connect(vl, dst)
        self.tb.run()
        # check data
        result_data = dst.data()
        print (expected_result)
        print (result_data)
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 9)
Example #46
0
    def test_003_t(self):
        print "-------TEST 3------------"
        # set up fg
        src_data = (0, 1, 0, 1, 0)
        expected_result = (1500, 1997, 1500, 1003, 1506, 2000, 1864, 2000, 1500, \
          1003, 1500, 1997, 1494, 1000, 1136, 1000, 1500, 1997, 1500, 1003)
        src = blocks.vector_source_b(src_data)
        pulse_shaper = pulse_shaper_bs(
            1000, 2000, 1, 4)  # (v_min, v_max, sign[+/-1], interpolation)
        dst = blocks.vector_sink_s()
        self.tb.connect(src, pulse_shaper)
        self.tb.connect(pulse_shaper, dst)

        self.tb.run()
        # check data
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #47
0
    def stest_s003(self):
        src_data0 = (0, 2, -3, 0, 12, 0)
        src_data1 = (1, 1, 1, 1, 1, 1)

        expected_result = [max(x, y) for x, y in zip(src_data0, src_data1)]

        src0 = blocks.vector_source_s(src_data0)
        src1 = blocks.vector_source_s(src_data1)
        op = blocks.max_ss(1)
        dst = blocks.vector_sink_s()

        self.tb.connect(src0, (op, 0))
        self.tb.connect(src1, (op, 1))
        self.tb.connect(op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #48
0
    def test_002_t(self):
        # set up fg
        src_data = (1, 3, 5, 9, 10, 12, 17, 19, 21)
        expected_result = (2, 6, 10, 18, 20, 24, 34, 38, 42)
        src = blocks.vector_source_s(src_data)
        vl = verilog.verilog_axi_ss(
            "/home/bowen/Downloads/double/double_axi.v", True, 1.0, "", 0, 0)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, vl)
        self.tb.connect(vl, dst)
        self.tb.run()
        # check data
        result_data = dst.data()
        print(expected_result)
        print(result_data)
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 9)
    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 run_test(fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation,
             dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    src = blocks.vector_source_s(packet, False)
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    (head, tail) = make_rx(tb, fo, fi, dimensionality, tot_constellation, K,
                           interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM)
    dst = blocks.vector_sink_s()

    tb.connect(src, enc_out, inter, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright = 0
    for i in range(ntotal):
        if packet[i] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Example #51
0
    def test_001_t(self):
        print "-------TEST 1------------"
        # set up fg
        src_data = (0, 1, 0, 1, 0)
        expected_result = (0, 2034, 0, -2034, 25, 2047, 1492, 2047, 0, -2034,
                           0, 2034, -25, -2047, -1492, -2047, 0, 2034, 0,
                           -2034)
        src = blocks.vector_source_b(src_data)
        pulse_shaper = pulse_shaper_bs(
            -2047, 2047, 1, 4)  # (v_min, v_max, sign[+/-1], interpolation)
        dst = blocks.vector_sink_s()
        self.tb.connect(src, pulse_shaper)
        self.tb.connect(pulse_shaper, dst)

        self.tb.run()
        # check data
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #52
0
    def test_001_t(self):
        # set up fg
        src_data = (1, 3, 5, 9, 10, 12, 17, 19, 21, 12, 45, 29)
        expected_result = (1, 3, 5, 9, 10, 12, 17, 19, 21, 12, 45, 29)
        src = blocks.vector_source_s(src_data)
        vl = verilog.verilog_axi_ss(
            "/home/bowen/Downloads/temp/saxi_passthru.v", True, 1.0, "-Wall",
            0, 0)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, vl)
        self.tb.connect(vl, dst)
        self.tb.run()
        # check data
        result_data = dst.data()
        print(expected_result)
        print(result_data)
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 12)
 def _tcp_client(self):
     dst = blocks.vector_sink_s()
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     for t in (0, 0.2):
         # wait until server listens
         sleep(t)
         try:
             sock.connect((self.addr, self.port))
         except socket.error as e:
             if e.errno != 111:
                 raise
             continue
         break
     fd = os.dup(sock.fileno())
     self.tb_rcv.connect(blocks.file_descriptor_source(self.itemsize, fd),
                         dst)
     self.tb_rcv.run()
     self.assertEqual(self.data, dst.data())
    def test_vector(self):
        # data
        src_data = (1 + 2j, 3 + 4j)
        expected_result = (1, 2, 3, 4)

        # blocks
        src = blocks.vector_source_c(src_data)
        cts = sandia_utils.complex_to_interleaved_short(True)
        dst = blocks.vector_sink_s(vlen=2)
        self.tb.connect(src, cts)
        self.tb.connect(cts, dst)

        # execute
        self.tb.run()
        result_data = dst.data()

        # assert
        print("got {}, expected {}".format(result_data, expected_result))
        self.assertEqual(expected_result, result_data)
    def test_001_t(self):
        # set up fg
        src_data = (1, 3, 5, 9, 10, 12, 17, 19, 21, 12, 45, 29)
        expected_result = (1, 3, 5, 9, 10, 12, 17, 19, 21, 12, 45, 29)
        src = blocks.vector_source_s(src_data)
        path = os.path.dirname(__file__) if len(
            os.path.dirname(__file__)) != 0 else '.'
        vl = verilog.verilog_axi_ss(
            path + "/testcases/passthru/saxi_passthru.v", True, 1.0, "", 0, 0)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, vl)
        self.tb.connect(vl, dst)
        self.tb.run()
        # check data
        result_data = dst.data()
        print(expected_result)
        print(result_data)
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 12)
    def test_with_scale(self):
        # data
        src_data = (1 + 1j, 2 + 2j, 3 + 3j)
        scale = 2.0
        expected_result = tuple(i * scale for i in (1, 1, 2, 2, 3, 3))

        # blocks
        src = blocks.vector_source_c(src_data)
        cts = sandia_utils.complex_to_interleaved_short(False, scale)
        dst = blocks.vector_sink_s()
        self.tb.connect(src, cts)
        self.tb.connect(cts, dst)

        # execute
        self.tb.run()
        result_data = dst.data()

        # assert
        print("got {}, expected {}".format(result_data, expected_result))
        self.assertEqual(expected_result, result_data)
Example #57
0
    def stest_s004(self):
        dim = 2
        src_data0 = (0, 2, -3, 0, 12, 0)
        src_data1 = (1, 1, 1, 1, 1, 1)

        expected_data = []
        tmp = [max(x, y) for x, y in zip(src_data0, src_data1)]
        for i in range(len(tmp) / dim):
            expected_data.append(max(tmp[i * dim:(i + 1) * dim]))

        src0 = blocks.vector_source_s(src_data0)
        s2v0 = blocks.stream_to_vector(gr.sizeof_short, dim)
        src1 = blocks.vector_source_s(src_data1)
        s2v1 = blocks.stream_to_vector(gr.sizeof_short, dim)
        op = blocks.max_ss(dim)
        dst = blocks.vector_sink_s()

        self.tb.connect(src0, s2v0, (op, 0))
        self.tb.connect(src1, s2v1, (op, 1))
        self.tb.connect(op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #58
0
    def test_004_t(self):
        print "-------TEST 4------------"
        # set up fg
        src_data = (0, 1, 0, 1, 0)
        expected_result = ( \
          3456, 3889, 4305, 4688, 5022, 5297, 5500, 5624, \
                   5664, 5618, 5489, 5282, 5004, 4665, 4280, 3862, \
                   3456, 3023, 2607, 2224, 1890, 1615, 1412, 1288, \
                   1248, 1294, 1423, 1630, 1908, 2247, 2632, 3050, \
                   3483, 3916, 4332, 4713, 5046, 5319, 5520, 5640, \
                   5678, 5630, 5498, 5350, 5255, 5179, 5122, 5087, \
                   5076, 5089, 5125, 5183, 5260, 5359, 5509, 5636, \
                   5678, 5636, 5509, 5304, 5027, 4690, 4307, 3890, \
                   3456, 3023, 2607, 2224, 1890, 1615, 1412, 1288, \
                   1248, 1294, 1423, 1630, 1908, 2247, 2632, 3050, \
                   3456, 3889, 4305, 4688, 5022, 5297, 5500, 5624, \
                   5664, 5618, 5489, 5282, 5004, 4665, 4280, 3862, \
                   3429, 2996, 2580, 2199, 1866, 1593, 1392, 1272, \
                   1234, 1282, 1414, 1562, 1657, 1733, 1790, 1825, \
                   1836, 1823, 1787, 1729, 1652, 1553, 1403, 1276, \
                   1234, 1276, 1403, 1608, 1885, 2222, 2605, 3022, \
                   3456, 3889, 4305, 4688, 5022, 5297, 5500, 5624, \
                   5664, 5618, 5489, 5282, 5004, 4665, 4280, 3862, \
                   3456, 3023, 2607, 2224, 1890, 1615, 1412, 1288, \
                   1248, 1294, 1423, 1630, 1908, 2247, 2632, 3050 )
        src = blocks.vector_source_b(src_data)
        pulse_shaper = pulse_shaper_bs(
            1234, 5678, 1, 32)  # (v_min, v_max, sign[+/-1], interpolation)
        dst = blocks.vector_sink_s()
        self.tb.connect(src, pulse_shaper)
        self.tb.connect(pulse_shaper, dst)

        self.tb.run()
        # check data
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Example #59
0
    def test_002_t(self):
        print "-------TEST 2------------"
        # set up fg
        src_data = (0, 1, 0, 1, 0)
        expected_result = ( \
          0, 399, 782,  1135,  1443, 1696,  1883,  1997, \
           2034, 1992,  1873,  1682,  1426, 1114, 759,   374, \
          0, -399,  -782, -1135, -1443, -1696, -1883, -1997, \
          -2034, -1992, -1873, -1682, -1426, -1114,  -759,  -374, \
             25,  424, 807,  1158,  1465, 1716,  1901,  2012, \
           2047, 2003,  1881,  1745,  1657, 1587,  1535,  1503, \
           1492, 1504,  1538,  1591,  1662, 1753,  1891,  2008, \
           2047, 2008,  1891,  1702,  1447, 1137, 784,   400, \
          0, -399,  -782, -1135, -1443, -1696, -1883, -1997, \
          -2034, -1992, -1873, -1682, -1426, -1114,  -759,  -374, \
          0,  399, 782,  1135,  1443, 1696,  1883,  1997, \
           2034, 1992,  1873,  1682,  1426, 1114, 759,   374, \
            -25, -424,  -807, -1158, -1465, -1716, -1901, -2012, \
          -2047, -2003, -1881, -1745, -1657, -1587, -1535, -1503, \
          -1492, -1504, -1538, -1591, -1662, -1753, -1891, -2008, \
          -2047, -2008, -1891, -1702, -1447, -1137,  -784,  -400, \
          0,  399, 782,  1135,  1443, 1696,  1883,  1997, \
           2034, 1992,  1873,  1682,  1426, 1114, 759,   374, \
          0, -399,  -782, -1135, -1443, -1696, -1883, -1997, \
          -2034, -1992, -1873, -1682, -1426, -1114,  -759,  -374)
        src = blocks.vector_source_b(src_data)
        pulse_shaper = pulse_shaper_bs(
            -2047, 2047, 1, 32)  # (v_min, v_max, sign[+/-1], interpolation)
        dst = blocks.vector_sink_s()
        self.tb.connect(src, pulse_shaper)
        self.tb.connect(pulse_shaper, dst)

        self.tb.run()
        # check data
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)