Beispiel #1
0
  def test_003 (self):
    stream = [ [float(0)]*10, [float(1)]*10, [float(2)]*10 ]
    mux = [ 0,2,2,1,1,2,0,2,0,0,
            1,0,1,0,1,2,1,2,1,1,
            2,0,0,2,1,2,0,1,2,0 ]

    imux = []
    for x in mux:
      imux.append(int(x))
      
    data = [gr.vector_source_f(stream[0]),
            gr.vector_source_f(stream[1]),
            gr.vector_source_f(stream[2])]
    dst = gr.vector_sink_f()

    uut = ofdm.static_mux_v(gr.sizeof_float, imux)

    self.fg.connect(data[0], (uut,0))
    self.fg.connect(data[1], (uut,1))
    self.fg.connect(data[2], (uut,2))

    self.fg.connect(uut,dst)
    self.fg.run()

    self.assertEqual(map(float,mux),list(dst.data()))
Beispiel #2
0
 def test_002_t(self):
     """
     Defined source data for three incoming port
     For one port src_data0 
     For N port src_data0,src_data1,src_data2,.......,src_dataN.
     """
     src_data0 = (1,2,3,1)
     src_data1 = (2,7,3,0) 
     src_data2 = (1,2,2,3)
     src_data3 = (25,16,4,81)
     expected_result = (8,20,13,12)
     src0 = gr.vector_source_f(src_data0)
     src1 = gr.vector_source_f(src_data1)
     src2 = gr.vector_source_f(src_data2)
     src3 = gr.vector_source_f(src_data3)
     cal_ref = Calculator("(a0*a1)+a2+sqrt(a3)",4)
     dst = gr.vector_sink_f()
     self.tb.connect(src0,(cal_ref,0))  
     self.tb.connect(src1,(cal_ref,1)) 
     self.tb.connect(src2,(cal_ref,2)) 
     self.tb.connect(src3,(cal_ref,3)) 
     self.tb.connect(cal_ref,dst)         
     self.tb.run()
     result_data = dst.data()
     print "Result data is : ",result_data
     self.assertFloatTuplesAlmostEqual(expected_result,result_data,6)
    def test_001(self):
        fg = self.fg

        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 = gr.vector_source_f (src1_data)
        s2v1 = gr.stream_to_vector(gr.sizeof_float, len(src1_data))
        fg.connect( src1, s2v1 )

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

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

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

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

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

        fg.run ()
        index = dst1.data ()
        source = dst2.data ()
        self.assertEqual ( index, (4,))
        self.assertEqual ( source, (0,))
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.gr_vector_source_x_0_0 = gr.vector_source_f((40,50,60), True, 1)
		self.gr_vector_source_x_0 = gr.vector_source_f((4,5,6), True, 1)
		self.gr_vector_sink_x_0 = gr.vector_sink_f(1)
		self.gr_sbhs_0 = gr_sbhs.gr_sbhs()
		self.gr_sbhs_0.set_parameters(1)
		    
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_float*1, "ne2.txt")
		self.gr_file_sink_0.set_unbuffered(True)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_sbhs_0, 0))
		self.connect((self.gr_vector_source_x_0_0, 0), (self.gr_sbhs_0, 1))
		self.connect((self.gr_sbhs_0, 0), (self.gr_vector_sink_x_0, 0))
		self.connect((self.gr_sbhs_0, 0), (self.gr_file_sink_0, 0))
Beispiel #5
0
    def test_stretch_01(self):
        tb = self.tb

        data = 10*[1,]
        data0 = map(lambda x: x/20.0, data)
        data1 = map(lambda x: x/10.0, data)

        expected_result0 = 10*[0.05,]
        expected_result1 = 10*[0.1,]

        src0 = gr.vector_source_f(data0, False)
        src1 = gr.vector_source_f(data1, False)
        inter = gr.streams_to_vector(gr.sizeof_float, 2)
        op = blocks.stretch_ff(0.1, 2)
        deinter = gr.vector_to_streams(gr.sizeof_float, 2)
        dst0 = gr.vector_sink_f()
        dst1 = gr.vector_sink_f()
        
        tb.connect(src0, (inter,0))
        tb.connect(src1, (inter,1))
        tb.connect(inter, op)
        tb.connect(op, deinter)
        tb.connect((deinter,0), dst0)
        tb.connect((deinter,1), dst1)
        tb.run()

        dst0_data = dst0.data()
        dst1_data = dst1.data()

        self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4)
        self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4)
 def test_interleaving(self):
     # Takes 3 streams (a, b and c)
     # Outputs 2 streams.
     # First (d) is interleaving of a and b.
     # Second (e) is interleaving of a and b and c.  c is taken in
     #     chunks of 2 which are reversed.
     A = (1, 2, 3, 4, 5)
     B = (11, 12, 13, 14, 15)
     C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90)
     expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15)
     expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95,
                   4, 14, 92, 93, 5, 15, 90, 91)
     mapping = [[(0, 0), (1, 0)], # mapping to produce D
                [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E
                ]
     srcA = gr.vector_source_f(A, False, 1)
     srcB = gr.vector_source_f(B, False, 1)
     srcC = gr.vector_source_f(C, False, 2)
     vmap =  gr.vector_map(gr.sizeof_int, (1, 1, 2), mapping)
     dstD = gr.vector_sink_f(2)
     dstE = gr.vector_sink_f(4)
     self.tb.connect(srcA, (vmap, 0))
     self.tb.connect(srcB, (vmap, 1)) 
     self.tb.connect(srcC, (vmap, 2)) 
     self.tb.connect((vmap, 0), dstD)
     self.tb.connect((vmap, 1), dstE)
     self.tb.run()
     self.assertEqual(expected_D, dstD.data())
     self.assertEqual(expected_E, dstE.data())
 def test_add_f32(self):
     tb = gr.top_block()
     src0 = gr.vector_source_f([1, 3, 5, 7, 9], False)
     src1 = gr.vector_source_f([0, 2, 4, 6, 8], False)
     adder = add_2_f32_1_f32()
     sink = gr.vector_sink_f()
     tb.connect((src0, 0), (adder, 0))
     tb.connect((src1, 0), (adder, 1))
     tb.connect(adder, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 5, 9, 13, 17))
 def test_float_to_complex_2(self):
     src1_data = (1.0, 3.0, 5.0, 7.0, 9.0)
     src2_data = (2.0, 4.0, 6.0, 8.0, 10.0)
     expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
     src1 = gr.vector_source_f(src1_data)
     src2 = gr.vector_source_f(src2_data)
     op = blocks_swig.float_to_complex()
     dst = gr.vector_sink_c()
     self.tb.connect(src1, (op, 0))
     self.tb.connect(src2, (op, 1))
     self.tb.connect(op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
    def help_stream_2ff(self, N, stream_sizes):
        v0 = gr.vector_source_f(N*[1,], False)
        v1 = gr.vector_source_f(N*[2,], False)
        
        mux = gr.stream_mux(gr.sizeof_float, stream_sizes)

        dst = gr.vector_sink_f ()

        self.tb.connect (v0, (mux,0))
        self.tb.connect (v1, (mux,1))
        self.tb.connect (mux, dst)
        self.tb.run ()

        return dst.data ()
Beispiel #10
0
    def test_002_interp(self):          
        taps = random_floats(31)
        #src_data = random_floats(10000)  # FIXME the 10k case fails!
        src_data = random_floats(1000)
        interpolation = 3

        expected_result = reference_interp_filter(src_data, interpolation, taps)

	tb = gr.top_block()
        src = gr.vector_source_f(src_data)
        op = gr.rational_resampler_base_fff(interpolation, 1, taps)
        dst = gr.vector_sink_f()
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
        result_data = dst.data()

        L1 = len(result_data)
        L2 = len(expected_result)
        L = min(L1, L2)
        if False:
            sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' %
                             (L2 - L1, len(taps), interpolation, len(src_data)))
            sys.stderr.write('  len(result_data) = %d  len(expected_result) = %d\n' %
                             (len(result_data), len(expected_result)))
        #self.assertEqual(expected_result[0:L], result_data[0:L])
        # FIXME check first 3 answers
        self.assertEqual(expected_result[3:L], result_data[3:L])
Beispiel #11
0
    def xtest_004_decim_random_vals(self):
        MAX_TAPS = 9
        MAX_DECIM = 7
        OUTPUT_LEN = 9

        random.seed(0)    # we want reproducibility

        for ntaps in xrange(1, MAX_TAPS + 1):
            for decim in xrange(1, MAX_DECIM+1):
                for ilen in xrange(ntaps + decim, ntaps + OUTPUT_LEN*decim):
                    src_data = random_floats(ilen)
                    taps = random_floats(ntaps)
                    expected_result = reference_dec_filter(src_data, decim, taps)

                    tb = gr.top_block()
                    src = gr.vector_source_f(src_data)
                    op = gr.rational_resampler_base_fff(1, decim, taps)
                    dst = gr.vector_sink_f()
                    tb.connect(src, op, dst)
                    tb.run()
                    tb = None
                    result_data = dst.data()
                    L1 = len(result_data)
                    L2 = len(expected_result)
                    L = min(L1, L2)
                    if False:
                        sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % (L2 - L1, ntaps, decim, ilen))
                        sys.stderr.write('  len(result_data) = %d  len(expected_result) = %d\n' %
                                         (len(result_data), len(expected_result)))
                    self.assertEqual(expected_result[0:L], result_data[0:L])
Beispiel #12
0
    def xtest_005_interp_random_vals(self):
        MAX_TAPS = 9
        MAX_INTERP = 7
        INPUT_LEN = 9

        random.seed(0)    # we want reproducibility

        for ntaps in xrange(1, MAX_TAPS + 1):
            for interp in xrange(1, MAX_INTERP+1):
                for ilen in xrange(ntaps, ntaps + INPUT_LEN):
                    src_data = random_floats(ilen)
                    taps = random_floats(ntaps)
                    expected_result = reference_interp_filter(src_data, interp, taps)

                    tb = gr.top_block()
                    src = gr.vector_source_f(src_data)
                    op = gr.rational_resampler_base_fff(interp, 1, taps)
                    dst = gr.vector_sink_f()
                    tb.connect(src, op, dst)
                    tb.run()
                    tb = None
                    result_data = dst.data()
                    L1 = len(result_data)
                    L2 = len(expected_result)
                    L = min(L1, L2)
                    #if True or abs(L1-L2) > 1:
                    if False:
                        sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' % (L2 - L1, ntaps, interp, ilen))
                        #sys.stderr.write('  len(result_data) = %d  len(expected_result) = %d\n' %
                        #                 (len(result_data), len(expected_result)))
                    #self.assertEqual(expected_result[0:L], result_data[0:L])
                    # FIXME check first ntaps+1 answers
                    self.assertEqual(expected_result[ntaps+1:L], result_data[ntaps+1:L])
Beispiel #13
0
    def transform(self, src_data, rate, freq):
	src = gr.vector_source_f(src_data, False)
        dft = gr.goertzel_fc(rate, rate, freq)
	dst = gr.vector_sink_c()
	self.tb.connect(src, dft, dst)
	self.tb.run()
	return dst.data()	
Beispiel #14
0
    def xtest_fff_003(self):
        random.seed(0)
        for i in xrange(25):
            sys.stderr.write("\n>>> Loop = %d\n" % (i,))
            src_len = 4096
            src_data = make_random_float_tuple(src_len)
            ntaps = int(random.uniform(2, 1000))
            taps = make_random_float_tuple(ntaps)
            expected_result = reference_filter_fff(1, taps, src_data)

            src = gr.vector_source_f(src_data)
            op = gr.fft_filter_fff(1, taps)
            dst = gr.vector_sink_f()
    	    tb = gr.top_block()
            tb.connect(src, op, dst)
            tb.run()
            result_data = dst.data()

            #print "src_len =", src_len, " ntaps =", ntaps
            try:
                self.assert_fft_float_ok2(expected_result, result_data, abs_eps=1.0)
            except:
                expected = open('expected', 'w')
                for x in expected_result:
                    expected.write(`x` + '\n')
                actual = open('actual', 'w')
                for x in result_data:
                    actual.write(`x` + '\n')
                raise
Beispiel #15
0
    def test_002(self):
        udp_rcv = gr.udp_source( gr.sizeof_float, '0.0.0.0', 0, eof=False )
        rcv_port = udp_rcv.get_port()

        udp_snd = gr.udp_sink( gr.sizeof_float, '127.0.0.1', 65500 )
        udp_snd.connect( 'localhost', rcv_port )

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = gr.vector_source_f(src_data)
        dst = gr.vector_sink_f()

        self.tb_snd.connect( src, udp_snd )
        self.tb_rcv.connect( udp_rcv, dst )

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(3.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(self.timeout)  # source ignores EOF?
    def test_deint_001 (self):
        lenx = 64
        src0 = gr.vector_source_f (range (lenx))
        op = gr.deinterleave (gr.sizeof_float,4)
        dst0 = gr.vector_sink_f ()
        dst1 = gr.vector_sink_f ()
        dst2 = gr.vector_sink_f ()
        dst3 = gr.vector_sink_f ()

        self.tb.connect (src0, op)
        op.connect(dst0,usesPortName="float_out_1")
        op.connect(dst1,usesPortName="float_out_2")
        op.connect(dst2,usesPortName="float_out_3")
        op.connect(dst3,usesPortName="float_out_4")
        self.tb.run ()

        expected_result0 = tuple (range (0, lenx, 4))
        expected_result1 = tuple (range (1, lenx, 4))
        expected_result2 = tuple (range (2, lenx, 4))
        expected_result3 = tuple (range (3, lenx, 4))

        self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data())
        self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data())
        self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ())
        self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
Beispiel #17
0
    def test_deint_001 (self):
        lenx = 64
        src = gr.vector_source_f (range (lenx))
        op = gr.deinterleave (gr.sizeof_float)
        dst0 = gr.vector_sink_f ()
        dst1 = gr.vector_sink_f ()
        dst2 = gr.vector_sink_f ()
        dst3 = gr.vector_sink_f ()

        self.tb.connect (src, op)
        self.tb.connect ((op, 0), dst0)
        self.tb.connect ((op, 1), dst1)
        self.tb.connect ((op, 2), dst2)
        self.tb.connect ((op, 3), dst3)
        self.tb.run ()

        expected_result0 = tuple (range (0, lenx, 4))
        expected_result1 = tuple (range (1, lenx, 4))
        expected_result2 = tuple (range (2, lenx, 4))
        expected_result3 = tuple (range (3, lenx, 4))

        self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ())
        self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ())
        self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ())
        self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
 def test_fir_filter_fcc_002(self):
     self.generate_fcc_source()
     expected_data = ((-6.94218761055e-05-9.90489479591e-06j),
                      (-2.56973435171e-05+8.05932795629e-05j),
                      (7.01698663761e-05+7.36373840482e-05j),
                      (7.57163215894e-05-4.65324592369e-05j),
                      (-3.01657128148e-05-0.000122838056996j),
                      (-9.53659764491e-05-3.73945695173e-05j),
                      (-2.33501577895e-05+0.000109135726234j),
                      (6.65136758471e-05+0.000125709688291j),
                      (3.08501912514e-05-9.16842873266e-06j),
                      (-2.64703612629e-05-0.000135892929393j),
                      (0.000136643866426-0.000162003751029j),
                      (0.000501801609062-0.000185820827028j),
                      (0.000694551155902-0.000299874518532j),
                      (0.000424396857852-0.00038379128091j),
                      (-9.1786707344e-05-0.000242479465669j),
                      (-0.000337087287335+7.45999423089e-05j),
                      (-0.000116414521472+0.000258556567132j),
                      (0.000215422536712+0.000116706112749j),
                      (0.000224391726078-0.000156330308528j),
                      (-5.96956087975e-05-0.000211163976928j))
     src = gr.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcc(4, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
 def test_fir_filter_fcf_001(self):
     self.generate_fcf_source()
     expected_data = ((0.000247188087087-0.000157509770361j),
                      (-0.000155229790835-0.000246197130764j),
                      (-0.000264906557277+0.000174603672349j),
                      (6.99016964063e-05+0.000174961372977j),
                      (-5.48477692064e-05-0.0001131295503j),
                      (-0.000237467131228+0.000118011368613j),
                      (0.000136614587973+0.000229531884543j),
                      (0.000229347482673-0.000166581812664j),
                      (-0.000106010869786-0.000150042149471j),
                      (2.92293734674e-05+0.000142060467624j),
                      (0.000228707227507-9.30760797928e-05j),
                      (-0.000124306126963-0.000216641055886j),
                      (-0.000204823678359+0.00016052465071j),
                      (0.00012825592421+0.000133123627165j),
                      (-1.18284006021e-05-0.000159015646204j),
                      (-0.000219973371713+7.5438656495e-05j),
                      (0.000114713984658+0.000205190401175j),
                      (0.000185727752978-0.000154630601173j),
                      (-0.000141745767905-0.000120098840853j),
                      (-3.9850056055e-07+0.000168364742422j))
     src = gr.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcf(1, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
Beispiel #20
0
    def test_006_interp_decim(self):
        taps = (0,1,0,0)
        src_data = range(10000)
        interp = 3
        decimation = 2

        expected_result = reference_interp_dec_filter(src_data, interp, decimation, taps)

	tb = gr.top_block()
        src = gr.vector_source_f(src_data)
        op = gr.rational_resampler_base_fff(interp, decimation, taps)
        dst = gr.vector_sink_f()
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
        result_data = dst.data()

        L1 = len(result_data)
        L2 = len(expected_result)
        L = min(L1, L2)
        if False:
            sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' %
                             (L2 - L1, len(taps), decimation, len(src_data)))
            sys.stderr.write('  len(result_data) = %d  len(expected_result) = %d\n' %
                             (len(result_data), len(expected_result)))
        self.assertEqual(expected_result[1:L], result_data[1:L])
    def xtest_004(self):
        vlen = 4
        tune = counter4(self, 1)
        tune_delay = 1
        dwell_delay = 2
        msgq = gr.msg_queue()

        src_data = tuple([float(x) for x in
                          ( 1,  2,  3,  4,
                            9,  6, 11,  8,
                            5, 10,  7, 12,
                            13, 14, 15, 16
                            )])

        expected_results = tuple([float(x) for x in
                                  ( 9, 10, 11, 12)])

        src = gr.vector_source_f(src_data, False)
        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
        stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay)
        self.tb.connect(src, s2v, stats)
        self.tb.run()
        self.assertEqual(1, msgq.count())
        for i in range(1):
            m = parse_msg(msgq.delete_head())
            #print "m =", m.center_freq, m.data
            self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
Beispiel #22
0
    def test_001_t (self):
    	
    	src_data = [0]*10
	src_data1 = [1]*20
	src_data = src_data+src_data1
 	
	#expected_result = (-2.0, 0.0, 5.0, 8.0, 9.0, 11.0, 14.0, 18.0)
	
	src0 = gr.vector_source_f(src_data)
	sqr = dsim()
	sqr.set_parameters(2,0.5,1,.1,10,1)

	#Preload
	sqr.input_config(1).preload_items = 1
	dst = gr.vector_sink_f()
	
	self.tb.connect(src0, (sqr,0)) # src0(vector_source) -> sqr_input_0
	self.tb.connect((sqr,0), (sqr,1)) # sqr_output_0 -> sqr_input_1
	self.tb.connect(sqr,dst) # sqr_output_0 -> dst (vector_source)

	self.tb.run()

	result_data = dst.data()
	
	
	import  matplotlib.pyplot as plt
    	plt.plot(result_data)
	print "result", result_data
    	plt.show()
 def test_fir_filter_fcf_002(self):
     self.generate_fcf_source()
     expected_data = ((7.3052920925e-05-3.91741014028e-06j),
                      (3.11913172482e-05-0.000109872074972j),
                      (-0.000128646017401-3.49857727997e-05j),
                      (-5.49546712136e-05+8.96326746442e-05j),
                      (5.14321582159e-05+9.64698920143e-05j),
                      (0.000120189361041+2.4231892894e-05j),
                      (0.000100405508419-0.000223224604269j),
                      (-0.000274751859251-2.33274622587e-05j),
                      (1.52600114234e-06+0.000133301247843j),
                      (3.77224641852e-05+5.29596509296e-05j),
                      (-3.60160379387e-06+0.000247975171078j),
                      (0.00113093166146-0.000663110695314j),
                      (0.00059568521101-0.00099650840275j),
                      (-0.000475480686873+0.000250602373853j),
                      (0.000191397906747+0.000271986238658j),
                      (0.000247183139436-0.000157510468853j),
                      (-5.48357638763e-05-0.000113135029096j),
                      (-0.00010601492977-0.00015005269961j),
                      (-0.000204817260965+0.000160534662427j),
                      (0.000114742244477+0.000205190313864j))
     src = gr.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcf(4, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
    def test02(self):
        # Test float/float version
        omega = 2
        gain_omega = 0.01
        mu = 0.5
        gain_mu = 0.01
        omega_rel_lim = 0.001

        self.test = digital_swig.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_rel_lim)

        data = 100 * [1]
        self.src = gr.vector_source_f(data, False)
        self.snk = gr.vector_sink_f()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()

        expected_result = 100 * [0.99972]  # doesn't quite get to 1.0
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 30
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp :]
        dst_data = dst_data[len_d - Ncmp :]

        # print expected_result
        # print dst_data

        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
 def test_fir_filter_fcc_001(self):
     self.generate_fcc_source()
     expected_data = ((-0.000337088305969+7.46004516259e-05j),
                      (-5.63409266761e-05+0.000301144464174j),
                      (9.16960561881e-05-2.89259278361e-05j),
                      (-0.000231866899412-6.25764005235e-05j),
                      (-0.000116414688819+0.000258557556663j),
                      (0.000206079319469+5.05045172758e-05j),
                      (-3.85114690289e-05-0.00019276549574j),
                      (-0.000146380873048+0.000112079876999j),
                      (0.000215423395275+0.000116706331028j),
                      (0.000136050162837-0.000232611957472j),
                      (-0.000155499437824-5.41604022146e-05j),
                      (0.000106907449663+0.00016310159117j),
                      (0.000224392410018-0.000156331108883j),
                      (-0.000131131906528-0.000172063446371j),
                      (-5.92393880652e-05+0.00016801241145j),
                      (0.000214921761653-5.32235890205e-06j),
                      (-5.96960526309e-05-0.000211164733628j),
                      (-0.000193948610104+0.000113364716526j),
                      (0.000134820176754+0.000142527525895j),
                      (4.74465123261e-05-0.000175131688593j))
     src = gr.vector_source_f(self.src_data)
     op  = filter.freq_xlating_fir_filter_fcc(1, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
    def test_001_codeallr2m3 (self):
        """ Check Golay-SD-decoding m=3 for all possible inputs """

	src_data = (	0.648,0.680,0.636,0.946,0.209,0.710,0.237,0.120,
			0.608,0.451,0.459,0.662,0.771,0.351,0.663,0.417,
			0.842,0.833,0.257,0.614,0.583,0.541,0.870,0.265,
			0.319,0.120,0.940,0.646,0.480,0.640,0.545,0.648,
			0.544,0.722,0.523,0.994,0.219,0.106,0.110,0.064)
	expected_data = (	6,
				0,
				14,
				1,
				22)
        src1 = gr.vector_source_f(src_data,0,8)
        coding_action = chancoding.rmg_decoder_sd_vfi(3,1)
        sink = gr.vector_sink_i()

        self.tb.connect(src1, coding_action)
        self.tb.connect(coding_action, sink)
        self.tb.run()

        self.assertEqual( coding_action.get_vlen_in(), 8)
        self.assertEqual( coding_action.get_vlen_out(), 1)
        self.assertEqual( coding_action.get_num_bits_out(), 5)

	for i in range( len(expected_data) ):
        	self.assertEqual( sink.data()[i] , expected_data[i], i)
Beispiel #27
0
    def test_005_(self):

        src_data = (1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)

        dwav = numpy.array(src_data)
        wvps = numpy.zeros(3)
        # wavelet power spectrum
        scl = 1.0/sqr(dwav[0])
        k = 1
        for e in range(len(wvps)):
            wvps[e] = scl*sqr(dwav[k:k+(01<<e)]).sum()
            k += 01<<e

        src = gr.vector_source_f(src_data, False, len(src_data))
        kon = wavelet_swig.wvps_ff(len(src_data))
        dst = gr.vector_sink_f(int(math.ceil(math.log(len(src_data), 2))))

        self.tb.connect(src, kon)
        self.tb.connect(kon, dst)

        self.tb.run()
        snk_data = dst.data()

        sum = 0
        for (u,v) in zip(snk_data, wvps):
            w = u - v
            sum += w * w
        sum /= float(len(snk_data))
        assert sum < 1e-6
Beispiel #28
0
    def test_001(self):
        port = 65500

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = gr.vector_source_f(src_data)
        udp_snd = gr.udp_sink( gr.sizeof_float, 'localhost', port )
        self.tb_snd.connect( src, udp_snd )

        udp_rcv = gr.udp_source( gr.sizeof_float, 'localhost', port )
        dst = gr.vector_sink_f()
        self.tb_rcv.connect( udp_rcv, dst )

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(3.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(not self.timeout)
Beispiel #29
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-I", "--audio-input", type="string", default="",
                          help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=8000,
                          help="set sample rate to RATE (8000)")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        src = audio.source (sample_rate, options.audio_input)
        dst = audio.sink (sample_rate, options.audio_output)

	vec1 = [1, -1]
	vsource = gr.vector_source_f(vec1, True)
	multiply = gr.multiply_ff()

	self.connect(src, (multiply, 0))
	self.connect(vsource, (multiply, 1))
	self.connect(multiply, dst)
 def test_fir_filter_fff_001(self):
     src_data = 40*[1, 2, 3, 4]
     expected_data = (0.5, 1.5, 3.0, 5.0, 5.5, 6.5, 8.0, 10.0,
                      10.5, 11.5, 13.0, 15.0, 15.5, 16.5, 18.0,
                      20.0, 20.5, 21.5, 23.0, 25.0, 25.5, 26.5,
                      28.0, 30.0, 30.5, 31.5, 33.0, 35.0, 35.5,
                      36.5, 38.0, 40.0, 40.5, 41.5, 43.0, 45.0,
                      45.5, 46.5, 48.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0)
     src = gr.vector_source_f(src_data)
     op  = filter.fir_filter_fff(1, 20*[0.5, 0.5])
     dst = gr.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(expected_data, result_data, 5)
Beispiel #31
0
    def test_01(self):
        tb = self.tb

        data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0)

        src = gr.vector_source_f(data, False)
        regen = blocks.peak_detector_fb()
        dst = gr.vector_sink_b()

        tb.connect(src, regen)
        tb.connect(regen, dst)
        tb.run()

        dst_data = dst.data()

        self.assertEqual(expected_result, dst_data)
Beispiel #32
0
    def add_source(self, signal=None):
        try:
            if signal is None:
                src = gr.message_source(gr.sizeof_float,
                                        1)  # queue depth 1, MUST BE 1
                self.sources.append(src)
                self.lengths.append(0)
                self.is_const.append(False)
            else:
                src = gr.vector_source_f(list(signal), True)
                self.sources.append(src)
                self.lengths.append(len(signal))
                self.is_const.append(True)

            id = len(self.sources) - 1
            self.tb.connect(src, (self.mux, id))
        except Exception, ex:
            print repr(ex)
            raise RuntimeError, "Could not connect new source to mux"
Beispiel #33
0
 def test_031_multiple_internal_inputs(self):
     tb = gr.top_block()
     src = gr.vector_source_f([
         1.0,
     ])
     hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float),
                         gr.io_signature(1, 1, gr.sizeof_float))
     m1 = gr.multiply_const_ff(1.0)
     m2 = gr.multiply_const_ff(2.0)
     add = gr.add_ff()
     hb.connect(hb, m1)  # m1 is connected to hb external input #0
     hb.connect(hb, m2)  # m2 is also connected to hb external input #0
     hb.connect(m1, (add, 0))
     hb.connect(m2, (add, 1))
     hb.connect(add, hb)  # add is connected to hb external output #0
     dst = gr.vector_sink_f()
     tb.connect(src, hb, dst)
     tb.run()
     self.assertEquals(dst.data(), (3.0, ))
Beispiel #34
0
    def xtest_fff_005(self):
        random.seed(0)
        for i in xrange(25):
            sys.stderr.write("\n>>> Loop = %d\n" % (i,))
            src_len = 4*1024
            src_data = make_random_float_tuple(src_len)
            ntaps = int(random.uniform(2, 1000))
            taps = make_random_float_tuple(ntaps)
            expected_result = reference_filter_fff(1, taps, src_data)

            src = gr.vector_source_f(src_data)
            op = gr.fft_filter_fff(1, taps)
            dst = gr.vector_sink_f()
    	    tb = gr.top_block()
            tb.connect(src, op, dst)
            tb.run()
            result_data = dst.data()

            self.assert_fft_float_ok2(expected_result, result_data, abs_eps=2.0)
Beispiel #35
0
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.pmt_from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs * msg_interval):
            src_data.append(float(i))
        src = gr.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()

        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)

        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(
            pmt.pmt_symbol_to_string(
                pmt.pmt_vector_ref(msg_gen.message_ports_out(), 0)),
            'out_port')
        self.assertEqual(
            pmt.pmt_symbol_to_string(
                pmt.pmt_vector_ref(msg_cons.message_ports_in(), 0)), 'in_port')

        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.pmt_equal(msg_list[i], msg_cons.msg_list[i]))
Beispiel #36
0
    def test_006(self):
        vlen = 128
        syms = 4
        bin1 = vlen / 2 - vlen / 4
        bin2 = vlen / 2 + vlen / 3
        bin1_val = 1.0j
        bin2_val = -1.0

        vec = numpy.array(numpy.zeros(vlen), numpy.complex)
        vec[bin1] = bin1_val
        vec[bin2] = bin2_val
        vec = concatenate([vec] * syms)

        epsilon = [1, -4, 5, 2]
        frame_trigger = [1] * syms

        expec = numpy.array(numpy.zeros(vlen * syms), numpy.complex)
        for i in range(syms):
            expec[bin1 + i * vlen + epsilon[i]] = bin1_val
            expec[bin2 + i * vlen + epsilon[i]] = bin2_val

        freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen)

        fft = gr.fft_vcc(vlen, True, [], True)  # natural order, dc = vlen / 2
        ifft = gr.fft_vcc(vlen, False, [], True)
        fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen)

        src = gr.vector_source_c(vec)
        dst = gr.vector_sink_c()
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        eps = gr.vector_source_f(epsilon)
        trig = gr.vector_source_b(frame_trigger)

        self.fg.connect(src, s2v, ifft, (freq_shift, 0))
        self.fg.connect(eps, (freq_shift, 1))
        self.fg.connect(trig, (freq_shift, 2))
        self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
        self.fg.run()

        self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5)
Beispiel #37
0
    def test_008(self):
        vlen = 128
        syms = 4
        bin1 = vlen / 2 + 4
        bin1_val = 1.0
        cp_length = vlen / 4

        expec = numpy.array(numpy.zeros(vlen), numpy.complex)
        expec[bin1] = bin1_val
        expec = concatenate([expec] * syms)

        epsilon = [-0.5]
        frame_trigger = numpy.concatenate([[1], [0] * (syms - 1)])

        freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen, cp_length)

        fft = gr.fft_vcc(vlen, True, [], True)  # natural order, dc = vlen / 2
        fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen)

        sampler = ofdm.vector_sampler(gr.sizeof_gr_complex, vlen)

        trigger_vec = concatenate([[0] * (vlen + cp_length - 1), [1]])
        trigger_vec = concatenate([trigger_vec] * syms)
        trigger = gr.vector_source_b(trigger_vec.tolist())

        src = gr.sig_source_c(vlen, gr.GR_COS_WAVE, 4.5, 1.0,
                              0.0)  # bin vlen/2 + 4.5
        dst = gr.vector_sink_c()
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        eps = gr.vector_source_f(epsilon)
        trig = gr.vector_source_b(frame_trigger.tolist())

        self.fg.connect(src, (sampler, 0))
        self.fg.connect(trigger, (sampler, 1))
        self.fg.connect(sampler, (freq_shift, 0))
        self.fg.connect(eps, (freq_shift, 1))
        self.fg.connect(trig, (freq_shift, 2))
        self.fg.connect(freq_shift, fft, fft_scale, v2s, dst)
        self.fg.run()

        self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5, 1e-5)
Beispiel #38
0
    def test_002(self):
        # Need to add padding to keep proper alignment
        padding = tuple([0 for i in range(2)])

        src_data = (2147483647, 2147483648, 2200000000, -2147483648,
                    -2147483649, -2200000000) + padding
        expected_result = [
            2147483647, 2147483647, 2147483647, -2147483647, -2147483647,
            -2147483647
        ]
        expected_result.extend(padding)
        src = gr.vector_source_f(src_data)
        op = gr.float_to_int()
        dst = gr.vector_sink_i()

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

        self.assertEqual(expected_result, result_data)
Beispiel #39
0
    def setUp(self):
        self.tb = gr.top_block()

        print "qa_descrambling_vfvf START"

        cell_id = 124

        inf = open('/home/demel/exchange/matlab_pbch_demod_p.txt')
        intu = range(480)
        for i in range(480):
            intu[i] = float(inf.readline())

        self.src = gr.vector_source_f(intu, True, 480)
        self.ld = lte_swig.descrambling_vfvf()
        self.ld.set_cell_id(cell_id)

        self.sink = gr.vector_sink_f(120)
        self.head = gr.head(480 * 4, 10)

        self.tb.connect(self.src, self.head, self.ld, self.sink)
    def setUp (self):
        print "qa_lte_rate_unmatch_vff START"   
    	inf=open('/home/demel/exchange/matlab_pbch_descr.txt')
    	intu=range(120)
    	for i in range(120):
    		intu[i]=float(inf.readline())
    		#print line
    		#intu[i]=float(line)
    	invec=intu	# invec is a sample vector interleaved from Matlab
   	
        self.tb   = gr.top_block ()
        self.src  = gr.vector_source_f( invec, True, 40)
        self.vtos = gr.vector_to_stream(1*gr.sizeof_float,40)        
        self.stov = gr.stream_to_vector(1*gr.sizeof_float,1*120)
        self.head = gr.head(120*4,1)
        self.lru  = lte_swig.rate_unmatch_vff() # 124
        self.sink = gr.vector_sink_f(120)
        

        self.tb.connect(self.src, self.vtos, self.stov, self.head, self.lru, self.sink)
Beispiel #41
0
    def test_004(self):
        ''' Test impulse response - short form, ff '''
        src_data = [
            1,
        ] + 100 * [
            0,
        ]
        expected_result = ((-0.029296875), (-0.0302734375), (0.96875),
                           (-0.0302734375), (-0.029296875))

        src = gr.vector_source_f(src_data)
        op = gr.dc_blocker_ff(32, False)
        dst = gr.vector_sink_f()

        self.tb.connect(src, op, dst)
        self.tb.run()

        # only test samples around D-1
        result_data = dst.data()[29:34]
        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
Beispiel #42
0
    def xtest_003_interp(self):
        taps = random_floats(9)
        src_data = random_floats(10000)
        decimation = 3

        expected_result = reference_dec_filter(src_data, decimation, taps)

	tb = gr.top_block()
        src = gr.vector_source_f(src_data)
        op = filter.rational_resampler_base_fff(1, decimation, taps)
        dst = gr.vector_sink_f()
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
        result_data = dst.data()

        N = 10
        offset = 10#len(taps)-1
        print expected_result[100+offset:100+offset+N]
        print result_data[100:100+N]
Beispiel #43
0
    def test_006_interp_decim(self):
        taps = random_floats(31)
        src_data = random_floats(10000)
        interp = 3
        decimation = 2

        expected_result = reference_interp_dec_filter(src_data, interp, decimation, taps)

	tb = gr.top_block()
        src = gr.vector_source_f(src_data)
        op = filter.rational_resampler_base_fff(interp, decimation, taps)
        dst = gr.vector_sink_f()
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
        result_data = dst.data()

        N = 1000
        offset = len(taps)/2
        self.assertFloatTuplesAlmostEqual(expected_result[offset:offset+N], result_data[0:N], 5)
Beispiel #44
0
    def test_pwr_squelch_004(self):
        alpha = 0.0001
        thr = -25

        src_data = map(lambda x: float(x) / 10.0, range(1, 40))
        src = gr.vector_source_f(src_data)
        op = analog.pwr_squelch_ff(thr, alpha)
        dst = gr.vector_sink_f()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        expected_result = src_data
        expected_result[0:20] = 20 * [
            0,
        ]

        result_data = dst.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
Beispiel #45
0
    def test_003(self):
        ''' Test impulse response - long form, ff '''
        src_data = [
            1,
        ] + 100 * [
            0,
        ]
        expected_result = ((-0.02072429656982422), (-0.02081298828125),
                           (0.979156494140625), (-0.02081298828125),
                           (-0.02072429656982422))

        src = gr.vector_source_f(src_data)
        op = gr.dc_blocker_ff(32, True)
        dst = gr.vector_sink_f()

        self.tb.connect(src, op, dst)
        self.tb.run()

        # only test samples around 2D-2
        result_data = dst.data()[60:65]
        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
Beispiel #46
0
    def test_001(self):
        src_data = 200 * [
            0,
        ] + 200 * [
            0.5,
        ] + 200 * [
            1,
        ]
        expected_result = 200*[1,] + \
            sig_source_f(1, 0.125, 1, 200) + \
            sig_source_f(1, 0.25, 1, 200)

        src = gr.vector_source_f(src_data)
        op = blocks_swig.vco_f(1, math.pi / 2.0, 1)
        dst = gr.vector_sink_f()

        self.tb.connect(src, op, dst)
        self.tb.run()

        result_data = dst.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5)
    def test_deint_001(self):
        lenx = 63
        src0 = gr.vector_source_f(range(lenx))
        op = gr.deinterleave(gr.sizeof_float, 3)
        dst0 = gr.vector_sink_f()
        dst1 = gr.vector_sink_f()
        dst2 = gr.vector_sink_f()

        self.tb.connect(src0, op)
        op.connect(dst0, usesPortName="float_out_1")
        op.connect(dst1, usesPortName="float_out_2")
        op.connect(dst2, usesPortName="float_out_3")
        self.tb.run()

        expected_result0 = tuple(range(0, lenx, 3))
        expected_result1 = tuple(range(1, lenx, 3))
        expected_result2 = tuple(range(2, lenx, 3))

        self.assertFloatTuplesAlmostEqual(expected_result0, dst0.data())
        self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data())
        self.assertFloatTuplesAlmostEqual(expected_result2, dst2.data())
Beispiel #48
0
    def test_001_t(self):
        src_data = (0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1)
        expected_result = (-2.0, 0.0, 5.0, 8.0, 9.0, 11.0, 14.0, 18.0)

        src0 = gr.vector_source_f(src_data)
        sqr = square3_ff()

        #Preload
        sqr.input_config(1).preload_items = 1
        dst = gr.vector_sink_f()

        self.tb.connect(src0, (sqr, 0))  # src0(vector_source) -> sqr_input_0
        #self.tb.connect((sqr,0), (sqr,1)) # sqr_output_0 -> sqr_input_1
        self.tb.connect(sqr, dst)  # sqr_output_0 -> dst (vector_source)

        self.tb.run()

        result_data = dst.data()
        print str(result_data), "Result data"
        print str(expected_result), "expected "
    def test_003_f_1(self):
        #Test streams_to_vector (using stream_to_streams & vector_to_stream).

        n = 1
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = gr.vector_source_f(src_data)
        op1 = gr.stream_to_streams_comp(gr.sizeof_float, n)
        op2 = gr.streams_to_vector_comp(gr.sizeof_float, n)
        op3 = gr.vector_to_stream_comp(gr.sizeof_float, n)
        dst = gr.vector_sink_f()

        self.tb.connect(src, op1)
        for i in range(n):
            self.tb.connect((op1, i), (op2, i))
        self.tb.connect(op2, op3, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Beispiel #50
0
    def test_001_t (self):
    	
    	src0 = numpy.arange(0,3.1416,1)

	src0 = gr.vector_source_f(src0)
	expected_result = (0.0, 0.8414709568023682, 0.9092974066734314, 0.14112000167369843)

	sqr = generic()
	sqr.set_parameters("sin",1)

	dst = gr.vector_sink_f()
	
	self.tb.connect(src0, (sqr,0)) # src0(vector_source) -> sqr_input_0
	self.tb.connect(sqr,dst) # sqr_output_0 -> dst (vector_source)

	self.tb.run()

	result_data = dst.data()
	print result_data, "Result data"
	
   	self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
Beispiel #51
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()


    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo,0) # initial state = 0
    inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi,0) # initial state = 0
    mod = gr.chunks_to_symbols_sf(constellation,dimensionality)

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

    # RX
    metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
    gnd = gr.vector_source_f([0],True);
    siso_in = trellis.siso_f(fi,K,0,-1,True,False,trellis.TRELLIS_MIN_SUM) # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float)
    va_out = trellis.viterbi_s(fo,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = gr.check_lfsr_32k_s()
    
    tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics_in)
    tb.connect (gnd,(siso_in,0))
    tb.connect (metrics_in,(siso_in,1))
    tb.connect (siso_in,deinter,va_out,fsmi2s,dst)

    tb.run()
    
    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
    def test_003(self):

        scale = 2
        vlen = 3
        # Pad source data becasue of gr_sptr->output_multiple
        src_data = (0.0, 1.1, 2.2,0,0,0,0,0,0,0,0,0,0,0,0,0, \
            3.3, 4.4, 5.5,0,0,0,0,0,0,0,0,0,0,0,0,0, \
            -1.1, -2.2, -3.30,0,0,0,0,0,0,0,0,0,0,0,0,0)
        expected_result = [0, 2, 4,0,0,0,0,0,0,0,0,0,0,0,0,0, \
            7, 9, 11,0,0,0,0,0,0,0,0,0,0,0,0,0,\
            -2, -4, -7,0,0,0,0,0,0,0,0,0,0,0,0,0]
        src = gr.vector_source_f(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
        op = gr.float_to_short(vlen, scale)
        v2s = gr.vector_to_stream(gr.sizeof_short, vlen)
        dst = gr.vector_sink_s()

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

        self.assertEqual(expected_result, result_data)
Beispiel #53
0
    def test_01(self):
        tb = self.tb

        N = 10000
        seed = 0
        data = make_random_float_tuple(N, 1)
        expected_result = N * [
            0,
        ]

        src = gr.vector_source_f(data, False)
        op = blocks.moving_average_ff(100, 0.001)
        dst = gr.vector_sink_f()

        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()

        dst_data = dst.data()

        # make sure result is close to zero
        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1)
Beispiel #54
0
    def test_001_interp(self):
        taps = [1, 10, 100, 1000, 10000]
        src_data = (0, 2, 3, 5, 7, 11, 13, 17)
        interpolation = 3
        xr = (0,2,20,200,2003,20030,
              300,3005,30050,
              500,5007,50070,
              700,7011,70110,
              1100,11013,110130,
              1300,13017,130170,
              1700.0,17000.0,170000.0)
        expected_result = tuple([float(x) for x in xr])

	tb = gr.top_block()
        src = gr.vector_source_f(src_data)
        op = filter.rational_resampler_base_fff(interpolation, 1, taps)
        dst = gr.vector_sink_f()
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Beispiel #55
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Corr Test Gui")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=2,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.gr_vector_source_x_0 = gr.vector_source_f((concatenate((ones(10),zeros(200)),1)), True, 1)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_float*1, samp_rate)
		self.fir_filter_xxx_0 = filter.fir_filter_fff(1, (ones(10)))

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.fir_filter_xxx_0, 0))
		self.connect((self.fir_filter_xxx_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.wxgui_scopesink2_0, 1))
    def test_001_t (self):
        """ Simplest possible test: put in zeros, then header,
        then payload, trigger signal, try to demux.
        The return signal from the header parser is faked via _post()
        """
        n_zeros = 100
        header = (1, 2, 3)
        payload = tuple(range(17))
        data_signal = (0,) * n_zeros + header + payload
        trigger_signal = [0,] * len(data_signal)
        trigger_signal[n_zeros] = 1

        data_src = gr.vector_source_f(data_signal, False)
        trigger_src = gr.vector_source_b(trigger_signal, False)
        hpd = digital.header_payload_demux(
            len(header), 1, 0, "frame_len", "detect", False, gr.sizeof_float
        )
        self.assertEqual(pmt.pmt_length(hpd.message_ports_in()), 1)
        header_sink = gr.vector_sink_f()
        payload_sink = gr.vector_sink_f()

        self.tb.connect(data_src,    (hpd, 0))
        self.tb.connect(trigger_src, (hpd, 1))
        self.tb.connect((hpd, 0), header_sink)
        self.tb.connect((hpd, 1), payload_sink)
        self.tb.start()
        time.sleep(.2) # Need this, otherwise, the next message is ignored
        hpd.to_basic_block()._post(
                pmt.pmt_intern('header_data'),
                pmt.pmt_from_long(len(payload))
        )
        while len(payload_sink.data()) < len(payload):
            time.sleep(.2)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(header_sink.data(),  header)
        self.assertEqual(payload_sink.data(), payload)
def make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
    metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
    scale = gr.multiply_const_ff(1.0/N0)
    gnd = gr.vector_source_f([0],True);

    inter=[]
    deinter=[]
    siso_in=[]
    siso_out=[]

    # generate all blocks
    for it in range(IT):
      inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) )
      siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) )
      deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) )
      if it < IT-1:
        siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) )
      else:
        siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed

    # connect first stage
    tb.connect (gnd,inter[0])
    tb.connect (metrics_in,scale)
    tb.connect (scale,(siso_in[0],1))

    # connect the rest
    for it in range(IT):
      if it < IT-1:
        tb.connect (metrics_in,(siso_in[it+1],1))
        tb.connect (siso_in[it],deinter[it],(siso_out[it],1))
        tb.connect (gnd,(siso_out[it],0))
        tb.connect (siso_out[it],inter[it+1])
        tb.connect (inter[it],(siso_in[it],0))
      else:
        tb.connect (siso_in[it],deinter[it],siso_out[it])
        tb.connect (inter[it],(siso_in[it],0))

    return (metrics_in,siso_out[IT-1])
Beispiel #58
0
    def test_001(self):
        src_data = range(1000)
        expected_result = range(1000)

        filename = "tmp.32f"
        src = gr.vector_source_f(src_data)
        snk = blocks.file_sink(gr.sizeof_float, filename)
        snk.set_unbuffered(True)

        src2 = blocks.file_source(gr.sizeof_float, filename)
        snk2 = gr.vector_sink_f()

        self.tb.connect(src, snk)
        self.tb.run()

        self.tb.disconnect(src, snk)
        self.tb.connect(src2, snk2)
        self.tb.run()

        os.remove(filename)

        result_data = snk2.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
    def test_001_f(self):

        #Test stream_to_streams.

        n = 4
        src_len = n * 8
        src_data = range(src_len)

        expected_results = calc_expected_result(src_data, n)
        src = gr.vector_source_f(src_data)
        op = gr.stream_to_streams_comp(gr.sizeof_float, n)
        self.tb.connect(src, op)

        dsts = []
        for i in range(n):
            dst = gr.vector_sink_f()
            self.tb.connect((op, i), (dst, 0))
            dsts.append(dst)

        self.tb.run()

        for d in range(n):
            self.assertEqual(expected_results[d], dsts[d].data())
Beispiel #60
0
    def test_001_codeallr2m3(self):
        """ Check Golay-SD-decoding m=3 for all possible inputs """

        src_data = (0.648, 0.680, 0.636, 0.946, 0.209, 0.710, 0.237, 0.120,
                    0.608, 0.451, 0.459, 0.662, 0.771, 0.351, 0.663, 0.417,
                    0.842, 0.833, 0.257, 0.614, 0.583, 0.541, 0.870, 0.265,
                    0.319, 0.120, 0.940, 0.646, 0.480, 0.640, 0.545, 0.648,
                    0.544, 0.722, 0.523, 0.994, 0.219, 0.106, 0.110, 0.064)
        expected_data = (6, 0, 14, 1, 22)
        src1 = gr.vector_source_f(src_data, 0, 8)
        coding_action = chancoding.rmg_decoder_sd_vfi(3, 1)
        sink = gr.vector_sink_i()

        self.tb.connect(src1, coding_action)
        self.tb.connect(coding_action, sink)
        self.tb.run()

        self.assertEqual(coding_action.get_vlen_in(), 8)
        self.assertEqual(coding_action.get_vlen_out(), 1)
        self.assertEqual(coding_action.get_num_bits_out(), 5)

        for i in range(len(expected_data)):
            self.assertEqual(sink.data()[i], expected_data[i], i)