コード例 #1
0
    def test_deint_001(self):
        lenx = 64
        src0 = gr.vector_source_i(range(lenx))
        op = gr.deinterleave(gr.sizeof_int, 4)
        dst0 = gr.vector_sink_i()
        dst1 = gr.vector_sink_i()
        dst2 = gr.vector_sink_i()
        dst3 = gr.vector_sink_i()

        self.tb.connect(src0, op)
        op.connect(dst0, usesPortName="long_out_0")
        op.connect(dst1, usesPortName="long_out_1")
        op.connect(dst2, usesPortName="long_out_2")
        op.connect(dst3, usesPortName="long_out_3")
        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())
コード例 #2
0
    def test_deint_001 (self):
        lenx = 64
        src0 = gr.vector_source_i (range (lenx))
        op = gr.deinterleave (gr.sizeof_int,4)
        dst0 = gr.vector_sink_i ()
        dst1 = gr.vector_sink_i ()
        dst2 = gr.vector_sink_i ()
        dst3 = gr.vector_sink_i ()

        self.tb.connect (src0, op)
        op.connect(dst0,usesPortName="long_out_0")
        op.connect(dst1,usesPortName="long_out_1")
        op.connect(dst2,usesPortName="long_out_2")
        op.connect(dst3,usesPortName="long_out_3")
        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 ())
コード例 #3
0
 def xtest_003(self):
     # number of input streams != number of output streams
     src0_data = self.make_random_int_tuple(16000)
     src1_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     src1 = gr.vector_source_i(src1_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     dst1 = gr.vector_sink_i()
     self.tb.connect(src0, (op, 0), dst0)
     self.tb.connect(src1, (op, 1))
     self.assertRaises(ValueError, self.tb.run)
コード例 #4
0
 def test_003(self):
     # number of input streams != number of output streams
     src0_data = self.make_random_int_tuple(16000)
     src1_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     src1 = gr.vector_source_i(src1_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     dst1 = gr.vector_sink_i()
     self.fg.connect(src0, (op, 0), dst0)
     self.fg.connect(src1, (op, 1))
     self.assertRaises(ValueError, self.fg.run)
コード例 #5
0
    def test_002_codem5(self):
        """ Check Golay-SD-decoding m5 for 5 possible inputs """

        expected_data = (1360, 1481, 990, 1522, 1604)
        src_data = (0.395, 0.737, 0.360, 0.688, 0.443, 0.243, 0.755, 0.045,
                    0.263, 0.587, 0.150, 0.348, 0.521, 0.742, 0.672, 0.394,
                    0.485, 0.862, 0.531, 0.526, 0.094, 0.697, 0.139, 0.193,
                    0.973, 0.933, 0.772, 0.628, 0.764, 0.366, 0.449, 0.405,
                    0.155, 0.589, 0.885, 0.515, 0.990, 0.862, 0.168, 0.769,
                    0.834, 0.439, 0.672, 0.328, 0.950, 0.791, 0.217, 0.378,
                    0.756, 0.809, 0.397, 0.770, 0.392, 0.888, 0.430, 0.822,
                    0.198, 0.271, 0.425, 0.331, 0.020, 0.443, 0.705, 0.684,
                    0.228, 0.802, 0.480, 0.528, 0.990, 0.613, 0.866, 0.001,
                    0.989, 0.880, 0.816, 0.583, 0.697, 0.930, 0.561, 0.851,
                    0.055, 0.148, 0.496, 0.190, 0.496, 0.679, 0.137, 0.112,
                    0.090, 0.535, 0.319, 0.790, 0.826, 0.749, 0.407, 0.200,
                    0.193, 0.490, 0.050, 0.363, 0.615, 0.032, 0.630, 0.553,
                    0.210, 0.845, 0.485, 0.863, 0.121, 0.017, 0.581, 0.929,
                    0.582, 0.770, 0.983, 0.891, 0.730, 0.661, 0.626, 0.084,
                    0.667, 0.247, 0.586, 0.739, 0.846, 0.575, 0.901, 0.499,
                    0.729, 0.932, 0.053, 0.574, 0.621, 0.167, 0.143, 0.106,
                    0.083, 0.948, 0.206, 0.418, 0.641, 0.565, 0.209, 0.271,
                    0.874, 0.853, 0.491, 0.124, 0.446, 0.536, 0.500, 0.696,
                    0.539, 0.282, 0.636, 0.043, 0.190, 0.147, 0.206, 0.124)
        src1 = gr.vector_source_f(src_data, 0, 32)
        coding_action = chancoding.rmg_decoder_sd_vfi(5, 5)
        sink = gr.vector_sink_i()

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

        for i in range(len(expected_data)):
            self.assertEqual(sink.data()[i], expected_data[i])
コード例 #6
0
    def test_003(self):
        # Need to add padding to keep proper alignment
        padding = tuple([0 for i in range(5)])

        scale = 2
        vlen = 3
        src_data = (0.0, 1.1, 2.2,) + padding +  \
                   (3.3, 4.4, 5.5,) + padding + \
                   (-1.1, -2.2, -3.3,) + padding
        expected_result = [0, 2, 4]
        expected_result.extend(padding)
        expected_result.extend([7, 9, 11])
        expected_result.extend(padding)
        expected_result.extend([-2, -4, -7])
        expected_result.extend(padding)

        src = gr.vector_source_f(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
        op = gr.float_to_int(vlen, scale)
        v2s = gr.vector_to_stream(gr.sizeof_int, vlen)
        dst = gr.vector_sink_i()

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

        self.assertEqual(expected_result, result_data)
コード例 #7
0
 def test_002(self):
     # 2 input streams; 2 output streams
     src0_data = self.make_random_int_tuple(16000)
     src1_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     src1 = gr.vector_source_i(src1_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     dst1 = gr.vector_sink_i()
     self.tb.connect(src0, (op, 0), dst0)
     self.tb.connect(src1, (op, 1), dst1)
     self.tb.run()
     dst0_data = dst0.data()
     dst1_data = dst1.data()
     self.assertEqual(src0_data, dst0_data)
     self.assertEqual(src1_data, dst1_data)
コード例 #8
0
    def test_int_001(self):
        lenx = 64
        src0 = range(0, lenx, 4)
        src1 = range(1, lenx, 4)
        src2 = range(2, lenx, 4)
        src3 = range(3, lenx, 4)
        a = sb.DataSource(dataFormat="long")
        b = sb.DataSource(dataFormat="long")
        c = sb.DataSource(dataFormat="long")
        d = sb.DataSource(dataFormat="long")
        op = gr.interleave(gr.sizeof_int, 4)
        dst = gr.vector_sink_i()
        a.connect(op, providesPortName="long_in_0")
        b.connect(op, providesPortName="long_in_1")
        c.connect(op, providesPortName="long_in_2")
        d.connect(op, providesPortName="long_in_3")
        a.push(src0, EOS=True)
        b.push(src1, EOS=True)
        c.push(src2, EOS=True)
        d.push(src3, EOS=True)
        self.tb.connect(op, dst)
        self.tb.run()
        expected_result = tuple(range(lenx))
        result_data = dst.data()

        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
コード例 #9
0
 def test_002(self):
     # 2 input streams; 2 output streams
     src0_data = self.make_random_int_tuple(16000)
     src1_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     src1 = gr.vector_source_i(src1_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     dst1 = gr.vector_sink_i()
     self.fg.connect(src0, (op, 0), dst0)
     self.fg.connect(src1, (op, 1), dst1)
     self.fg.run()
     dst0_data = dst0.data()
     dst1_data = dst1.data()
     self.assertEqual(src0_data, dst0_data)
     self.assertEqual(src1_data, dst1_data)
コード例 #10
0
    def test_int_001 (self):
        lenx = 64
        src0 = range (0, lenx, 4)
        src1 = range (1, lenx, 4)
        src2 = range (2, lenx, 4)
        src3 = range (3, lenx, 4)
        a = sb.DataSource(dataFormat="long")
        b = sb.DataSource(dataFormat="long")
        c = sb.DataSource(dataFormat="long")
        d = sb.DataSource(dataFormat="long")
        op = gr.interleave (gr.sizeof_int, 4)
        dst = gr.vector_sink_i ()
        a.connect(op, providesPortName="long_in_0")
        b.connect(op, providesPortName="long_in_1")
        c.connect(op, providesPortName="long_in_2")
        d.connect(op, providesPortName="long_in_3")
        a.push(src0,EOS=True)
        b.push(src1,EOS=True)
        c.push(src2,EOS=True)
        d.push(src3,EOS=True)
        self.tb.connect (op, dst)
        self.tb.run ()
        expected_result = tuple (range (lenx))
        result_data = dst.data ()

        self.assertFloatTuplesAlmostEqual (expected_result, result_data)
コード例 #11
0
    def test_001_coder3m7 (self):
        """ Check Golay-encoding m=7 for 5 possible inputs """

	src_data = (121,9,235,32,492,194,342,100,10,1)
	expected_data = (	786312737, -786354655, -786312738, -786354655,
				303895266, -303951134, -303895267, -303951134,
				-2071231372, 2071233652, -2071231372, -2071233653,
				-487776787, 487726573, 487776786, 487726573,
				2104655245, 2104656498, -2104655246, 2104656498,
				1954253691, -1954247813, 1954253691, 1954247812,
				-668457176, -668411689, -668457176, 668411688,
				773968161, 773926622, -773968162, 773926622,
				303895266, -303951134, 303895266, 303951133,
				303951133, -303895267, -303951134, -303895267)

        src1 = gr.vector_source_i(src_data)
        coding_action = chancoding.rmg_encoder_vii(7,11)
        sink = gr.vector_sink_i(4)

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

	for i in range( len(expected_data) ):
        	self.assertEqual( sink.data()[i] , expected_data[i], i)
コード例 #12
0
    def test_003_t (self):
        """ two states, random switching """
        n_bytes = 10000
        ber = (0, 0.5)
        trans_matrix = (0.5, 0.5,
                        0.5, 0.5)
        src = gr.glfsr_source_b(32)  # Create some pseudo-random bits
        head = gr.head(1, n_bytes)
        chan = cc.markovchan_bb(ber, trans_matrix, 8)
        ber = cc.ber_b(8)
        sink_state = gr.vector_sink_i()

        self.tb.connect(src, head, chan, (ber, 0))
        self.tb.connect(head, (ber, 1))
        self.tb.connect((chan, 1), sink_state)
        self.tb.run ()

        n_times_in_state_1 = np.sum(sink_state.data())
        print "\nNumber of times in state 1 = " + str(n_times_in_state_1)
        print "            Expected value = " + str(n_bytes/2)
        self.assertTrue(n_times_in_state_1 > 3500 and n_times_in_state_1 < 6500,
                 "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
        print "  Measured BER = " + str(ber.ber())
        print "Expected value = 0.25"
        self.assertTrue(abs(ber.ber()- 0.25) < 0.05,
                 msg="Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
コード例 #13
0
    def test_001_coder3m7(self):
        """ Check Golay-encoding m=7 for 5 possible inputs """

        src_data = (121, 9, 235, 32, 492, 194, 342, 100, 10, 1)
        expected_data = (786312737, -786354655, -786312738, -786354655,
                         303895266, -303951134, -303895267, -303951134,
                         -2071231372, 2071233652, -2071231372, -2071233653,
                         -487776787, 487726573, 487776786, 487726573,
                         2104655245, 2104656498, -2104655246, 2104656498,
                         1954253691, -1954247813, 1954253691, 1954247812,
                         -668457176, -668411689, -668457176, 668411688,
                         773968161, 773926622, -773968162, 773926622,
                         303895266, -303951134, 303895266, 303951133,
                         303951133, -303895267, -303951134, -303895267)

        src1 = gr.vector_source_i(src_data)
        coding_action = chancoding.rmg_encoder_vii(7, 11)
        sink = gr.vector_sink_i(4)

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

        for i in range(len(expected_data)):
            self.assertEqual(sink.data()[i], expected_data[i], i)
コード例 #14
0
    def test_003(self):
        # Need to add padding to keep proper alignment
        padding = tuple([0 for i in range(5)])

        scale = 2
        vlen = 3
        src_data = (0.0, 1.1, 2.2) + padding + (3.3, 4.4, 5.5) + padding + (-1.1, -2.2, -3.3) + padding
        expected_result = [0, 2, 4]
        expected_result.extend(padding)
        expected_result.extend([7, 9, 11])
        expected_result.extend(padding)
        expected_result.extend([-2, -4, -7])
        expected_result.extend(padding)

        src = gr.vector_source_f(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
        op = gr.float_to_int(vlen, scale)
        v2s = gr.vector_to_stream(gr.sizeof_int, vlen)
        dst = gr.vector_sink_i()

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

        self.assertEqual(expected_result, result_data)
コード例 #15
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)
コード例 #16
0
	def __init__(self, decim=16, N_id_2=0, avg_frames=1, freq_corr=0, N_id_1=134, file_name="/home/user/git/gr-lte/gr-lte/test/traces/lte_02_796m_30720k_frame.cfile"):
		gr.top_block.__init__(self, "Pss Corr Block Gui")

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.N_id_2 = N_id_2
		self.avg_frames = avg_frames
		self.freq_corr = freq_corr
		self.N_id_1 = N_id_1
		self.file_name = file_name

		##################################################
		# Variables
		##################################################
		self.vec_half_frame = vec_half_frame = 30720*5/decim
		self.transition_width = transition_width = 100e3
		self.samp_rate = samp_rate = 30720e3/decim
		self.cutoff_freq = cutoff_freq = 550e3

		##################################################
		# Blocks
		##################################################
		self.gr_vector_sink_sss10 = gr.vector_sink_i(1)
		self.gr_vector_sink_sss0 = gr.vector_sink_i(1)
		self.gr_vector_sink_pss = gr.vector_sink_i(1)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate*decim)
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, file_name, False)
		self.fir_filter_xxx_0 = filter.fir_filter_ccc(decim, (firdes.low_pass(1, decim*samp_rate, cutoff_freq, transition_width)))
		self.any_0_0_0 = sss_corr(N_id_1,N_id_2,False, decim, avg_frames,freq_corr)
		self.any_0_0 = sss_corr(N_id_1,N_id_2,True, decim, avg_frames,freq_corr)
		self.any_0 = pss_corr(N_id_2, decim, avg_frames*2,freq_corr)

		##################################################
		# Connections
		##################################################
		self.connect((self.any_0_0_0, 0), (self.gr_vector_sink_sss10, 0))
		self.connect((self.fir_filter_xxx_0, 0), (self.any_0_0_0, 0))
		self.connect((self.any_0_0, 0), (self.gr_vector_sink_sss0, 0))
		self.connect((self.fir_filter_xxx_0, 0), (self.any_0_0, 0))
		self.connect((self.any_0, 0), (self.gr_vector_sink_pss, 0))
		self.connect((self.fir_filter_xxx_0, 0), (self.any_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.fir_filter_xxx_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.gr_null_sink_0, 0))
コード例 #17
0
 def help_const_ii(self, src_data, exp_data, op):
     src = gr.vector_source_i(src_data)
     srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data))
     rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data))
     dst = gr.vector_sink_i()
     self.tb.connect(src, srcv, op, rhs, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)
コード例 #18
0
ファイル: qa_mute.py プロジェクト: GREO/GNU-Radio
 def help_ii (self, src_data, exp_data, op):
     for s in zip (range (len (src_data)), src_data):
         src = gr.vector_source_i (s[1])
         self.tb.connect (src, (op, s[0]))
     dst = gr.vector_sink_i ()
     self.tb.connect (op, dst)
     self.tb.run ()
     result_data = dst.data ()
     self.assertEqual (exp_data, result_data)
コード例 #19
0
 def test_float_to_int_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = gr.vector_source_f(src_data)
     op = blocks_swig.float_to_int()
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #20
0
 def test_and_const_ii (self):
     src_data =        (1,  2,  3,  0x5004,   0x1150)
     expected_result = (0,  2,  2,  0x5000,   0x1100)
     src = gr.vector_source_i(src_data)
     op = blocks_swig.and_const_ii (0x55AA)
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_result)
コード例 #21
0
 def run(self, n_receive=None):
     """
     Run the simulation.
     
     Args:
         n_receive: Stop after receiving this many samples.
     """
     b100.set_image(self.fpgaimage)
     # steps_rqd only in for compatibility
     from gnuradio import gr, uhd
     if n_receive is None:
         n_receive = 10000
     # Flip high and low bits of in_raw
     flipped_raw = flip_bits(self.in_raw, self.width)
     flipped_raw = unsigned_to_signed(flipped_raw, self.width)
     stream_args = uhd.stream_args(cpu_format='sc16', channels=range(1))
     from_usrp = uhd.usrp_source(device_addr='', stream_args=stream_args)
     head = gr.head(4, n_receive)
     snk = gr.vector_sink_i()
     to_usrp = uhd.usrp_sink(device_addr='', stream_args=stream_args)
     src = gr.vector_source_i(flipped_raw)
     tb = gr.top_block()
     tb.connect(from_usrp, head, snk)
     tb.connect(src, to_usrp)
     tb.run()
     self.out_raw = snk.data()
     # Remove 0's
     start_offset = None
     stop_offset = None
     enumerated_raw = list(enumerate(self.out_raw))
     for i, r in enumerated_raw:
         if r != 0:
             start_offset = i
             break
     for i, r in reversed(enumerated_raw):
         if r != 0:
             stop_offset = i
             break
     if start_offset is None or stop_offset is None:
         raise StandardError("Could not find any non-zero returned data.")
     self.out_raw = self.out_raw[start_offset:stop_offset + 1]
     # Shift to positive integers
     positive = []
     for r in self.out_raw:
         if r < 0:
             r += pow(2, self.width)
         positive.append(r)
     self.out_raw = positive
     # Flip bits in out_raw
     self.out_raw = flip_bits(self.out_raw, self.width)
     if self.output_msgs:
         header_shift = pow(2, self.width - 1)
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         self.out_samples = [
             int_to_c(s, self.width / 2 - 1) for s in samples
         ]
         self.out_messages = packets
コード例 #22
0
    def test_001_ii(self):
	src_data = (1, 2, 3, 4, 5, 6)
	dst_data = (6, 15)
	src = gr.vector_source_i(src_data)
	itg = blocks_swig.integrate_ii(3)
	dst = gr.vector_sink_i()
	self.tb.connect(src, itg, dst)
	self.tb.run()
	self.assertEqual(dst_data, dst.data())
コード例 #23
0
 def body_110 (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     src1 = gr.vector_source_i (src_data)
     dst1 = gr.vector_sink_i ()
     fg.connect ((src1, 0), (dst1, 0))
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (src_data, dst_data)
コード例 #24
0
 def test_float_to_int_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = gr.vector_source_f(src_data)
     op = blocks_swig.float_to_int(1, 5)
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #25
0
 def help_ii(self, src_data, exp_data, op):
     for s in zip(range(len(src_data)), src_data):
         src = gr.vector_source_i(s[1])
         self.tb.connect(src, (op, s[0]))
     dst = gr.vector_sink_i()
     self.tb.connect(op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)
コード例 #26
0
 def test_001_ii(self):
     src_data = (1, 2, 3, 4, 5, 6)
     dst_data = (6, 15)
     src = gr.vector_source_i(src_data)
     itg = gr.integrate_ii(3)
     dst = gr.vector_sink_i()
     self.tb.connect(src, itg, dst)
     self.tb.run()
     self.assertEqual(dst_data, dst.data())
コード例 #27
0
 def test_float_to_int_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = gr.vector_source_f(src_data)
     op = blocks_swig.float_to_int(1, 5)
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #28
0
 def test_float_to_int_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = gr.vector_source_f(src_data)
     op = blocks_swig.float_to_int()
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #29
0
    def help_const_ii(self, src_data, exp_data, op):
	src = gr.vector_source_i(src_data)
	srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data))
	rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data))
        dst = gr.vector_sink_i()
        self.tb.connect(src, srcv, op, rhs, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(exp_data, result_data)
コード例 #30
0
 def test_copy (self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = gr.vector_source_i(src_data)
     op = gr.copy(gr.sizeof_int, True,4)
     dst = gr.vector_sink_i()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
コード例 #31
0
 def test_skip_all(self):
     skip_cnt = len(self.src_data)
     expected_result = tuple(self.src_data[skip_cnt:])
     src1 = gr.vector_source_i (self.src_data)
     op = gr.skiphead (gr.sizeof_int, skip_cnt)
     dst1 = gr.vector_sink_i ()
     self.tb.connect (src1, op, dst1)
     self.tb.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #32
0
 def test_001(self):
     # 1 input stream; 1 output stream
     src0_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     self.fg.connect(src0, op, dst0)
     self.fg.run()
     dst0_data = dst0.data()
     self.assertEqual(src0_data, dst0_data)
コード例 #33
0
 def test_001(self):
     # 1 input stream; 1 output stream
     src0_data = self.make_random_int_tuple(16000)
     src0 = gr.vector_source_i(src0_data)
     op = gr.kludge_copy(gr.sizeof_int)
     dst0 = gr.vector_sink_i()
     self.tb.connect(src0, op, dst0)
     self.tb.run()
     dst0_data = dst0.data()
     self.assertEqual(src0_data, dst0_data)
コード例 #34
0
ファイル: qa_skiphead.py プロジェクト: monikaomsharma/sandhi
 def test_skip_all(self):
     skip_cnt = len(self.src_data)
     expected_result = tuple(self.src_data[skip_cnt:])
     src1 = gr.vector_source_i(self.src_data)
     op = gr.skiphead(gr.sizeof_int, skip_cnt)
     dst1 = gr.vector_sink_i()
     self.tb.connect(src1, op, dst1)
     self.tb.run()
     dst_data = dst1.data()
     self.assertEqual(expected_result, dst_data)
コード例 #35
0
ファイル: testbench.py プロジェクト: benreynwar/fpga-sdrlib
 def run(self, n_receive=None):
     """
     Run the simulation.
     
     Args:
         n_receive: Stop after receiving this many samples.
     """
     b100.set_image(self.fpgaimage)
     # steps_rqd only in for compatibility
     from gnuradio import gr, uhd
     if n_receive is None:
         n_receive = 10000
     # Flip high and low bits of in_raw
     flipped_raw = flip_bits(self.in_raw, self.width)
     flipped_raw = unsigned_to_signed(flipped_raw, self.width)
     stream_args = uhd.stream_args(cpu_format='sc16', channels=range(1))
     from_usrp = uhd.usrp_source(device_addr='', stream_args=stream_args)
     head = gr.head(4, n_receive)
     snk = gr.vector_sink_i()
     to_usrp = uhd.usrp_sink(device_addr='', stream_args=stream_args)
     src = gr.vector_source_i(flipped_raw)
     tb = gr.top_block()
     tb.connect(from_usrp, head, snk)
     tb.connect(src, to_usrp)
     tb.run()
     self.out_raw = snk.data()
     # Remove 0's
     start_offset = None
     stop_offset = None
     enumerated_raw = list(enumerate(self.out_raw))
     for i, r in enumerated_raw:
         if r != 0:
             start_offset = i
             break
     for i, r in reversed(enumerated_raw):
         if r != 0:
             stop_offset = i
             break
     if start_offset is None or stop_offset is None:
         raise StandardError("Could not find any non-zero returned data.")
     self.out_raw = self.out_raw[start_offset: stop_offset+1]
     # Shift to positive integers
     positive = []
     for r in self.out_raw:
         if r < 0:
             r += pow(2, self.width)
         positive.append(r)
     self.out_raw = positive
     # Flip bits in out_raw
     self.out_raw = flip_bits(self.out_raw, self.width)
     if self.output_msgs:
         header_shift = pow(2, self.width-1)
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         self.out_samples = [int_to_c(s, self.width/2-1) for s in samples]
         self.out_messages = packets
コード例 #36
0
 def body_303_hier (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (35, 38, 41, 44)
     src1 = gr.vector_source_i (src_data)
     op = gr.compose (fg, gr.add_const_ii (10), mult_add (fg, 3, 5))
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #37
0
ファイル: qa_head.py プロジェクト: GREO/gnuradio-git
 def test_head (self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4)
     src1 = gr.vector_source_i (src_data)
     op = gr.head (gr.sizeof_int, 4)
     dst1 = gr.vector_sink_i ()
     self.tb.connect (src1, op)
     self.tb.connect (op, dst1)
     self.tb.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #38
0
 def test_head(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4)
     src1 = gr.vector_source_i(src_data)
     op = gr.head(gr.sizeof_int, 4)
     dst1 = gr.vector_sink_i()
     self.tb.connect(src1, op)
     self.tb.connect(op, dst1)
     self.tb.run()
     dst_data = dst1.data()
     self.assertEqual(expected_result, dst_data)
コード例 #39
0
 def help_ii (self, src_data, exp_data, op, port_prefix='data_in_'):
     for s in zip (range (len (src_data)), src_data):
         src = gr.vector_source_i (s[1])
         src.source.connect(op,providesPortName=port_prefix+str(s[0]))
         src.streamID = str(s[0])
         self.tb.sources.append(src)
     dst = gr.vector_sink_i ()
     self.tb.connect (op, dst)
     self.tb.run ()
     result_data = dst.data ()
     self.assertEqual (exp_data, result_data)
 def test_012_connect (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (2, 3, 4, 5)
     src1 = gr.vector_source_i (src_data)
     op = gr.add_const_ii (2)
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op)
     fg.connect (op, dst1)
     # print "edge_list:", fg.edge_list
     fg.validate ()
コード例 #41
0
 def body_302_hier (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (10, 11, 12, 13)
     src1 = gr.vector_source_i (src_data)
     op = gr.compose (fg, gr.add_const_ii (10))
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #42
0
 def test_const_i(self):
     tb = self.tb
     expected_result = (1, 1, 1, 1)
     src1 = analog.sig_source_i(1e6, analog.GR_CONST_WAVE, 0, 1)
     op = gr.head(gr.sizeof_int, 4)
     dst1 = gr.vector_sink_i()
     tb.connect(src1, op)
     tb.connect(op, dst1)
     tb.run()
     dst_data = dst1.data()
     self.assertEqual(expected_result, dst_data)
コード例 #43
0
 def test_const_i (self):
     fg = self.fg
     expected_result = (1, 1, 1, 1)
     src1 = gr.sig_source_i (1e6, gr.GR_CONST_WAVE, 0, 1)
     op = gr.head (gr.sizeof_int, 4)
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op)
     fg.connect (op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #44
0
 def body_111v (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (2, 3, 4, 5)
     src1 = gr.vector_source_i (src_data)
     op = gr.add_const_ii (2)
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #45
0
 def body_300_hier (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (10, 11, 12, 13)
     src1 = gr.vector_source_i (src_data)
     op = wrap_add (fg, 10)
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #46
0
 def test_const_i (self):
     tb = self.tb
     expected_result = (1, 1, 1, 1)
     src1 = gr.sig_source_i (1e6, gr.GR_CONST_WAVE, 0, 1)
     op = gr.head (gr.sizeof_int, 4)
     dst1 = gr.vector_sink_i ()
     tb.connect (src1, op)
     tb.connect (op, dst1)
     tb.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #47
0
 def help_ii(self, src_data, exp_data, op, port_prefix='data_in_'):
     for s in zip(range(len(src_data)), src_data):
         src = gr.vector_source_i(s[1])
         src.source.connect(op, providesPortName=port_prefix + str(s[0]))
         src.streamID = str(s[0])
         self.tb.sources.append(src)
     dst = gr.vector_sink_i()
     self.tb.connect(op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)
コード例 #48
0
 def body_301_hier (self):
     fg = self.fg
     src_data = (0, 1, 2, 3)
     expected_result = (5, 8, 11, 14)
     src1 = gr.vector_source_i (src_data)
     op = mult_add (fg, 3, 5)
     dst1 = gr.vector_sink_i ()
     fg.connect (src1, op, dst1)
     fg.run ()
     dst_data = dst1.data ()
     self.assertEqual (expected_result, dst_data)
コード例 #49
0
    def test_deint_001(self):
        lenx = 64
        src = gr.vector_source_i(range(lenx))
        op = gr.deinterleave(gr.sizeof_int, 1)
        dst0 = gr.vector_sink_i()

        self.tb.connect(src, op)
        self.tb.connect((op, 0), dst0)
        self.tb.run()

        expected_result0 = tuple(range(0, lenx, 1))
        self.assertFloatTuplesAlmostEqual(expected_result0, dst0.data())
コード例 #50
0
ファイル: qa_lut.py プロジェクト: pgoeser/gnuradio-mlse
 def test_001_lut(self):
     """test with integers"""
     src = gr.vector_source_b((1, 3, 2, 0))
     table = [[1, 5, 3, 9], [2, 3, 8, -1], [3, 9, 12, 3]]
     expected_result = [table[i] for i in (1, 0, 2, 0)]
     expected_result = tuple(itertools.chain.from_iterable(expected_result))
     dst = gr.vector_sink_i(len(table[0]))
     lut = mlse_swig.lut_biv(table)
     self.tb.connect(src, lut, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEquals(expected_result, result_data)
コード例 #51
0
 def help_ii(self, size, src_data, exp_data, op):
     for s in zip(range(len(src_data)), src_data):
         src = gr.vector_source_i(s[1])
         srcv = gr.stream_to_vector(gr.sizeof_int, size)
         self.tb.connect(src, srcv)
         self.tb.connect(srcv, (op, s[0]))
     rhs = gr.vector_to_stream(gr.sizeof_int, size)
     dst = gr.vector_sink_i()
     self.tb.connect(op, rhs, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)
コード例 #52
0
    def test_001(self):

        src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3, -4.4, -5.5)
        expected_result = [int(round(s)) for s in src_data]
        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)
コード例 #53
0
    def test_002_code_r5m5 (self):
        """ Check encoding r=5 m=5 for 5 possible inputs """

        expected_data = (-1771465066, 1721341545, 252654387, 858993459, -1431672471)
        src_data = (125,182,392,16,419)
        src1 = gr.vector_source_i(src_data)
        coding_action = chancoding.rm_encoder_vii(5,5)
        sink = gr.vector_sink_i()
        self.tb.connect(src1, coding_action)
        self.tb.connect(coding_action, sink)
        self.tb.run()
        for i in range( len(expected_data) ):
            self.assertEqual( sink.data()[i] , expected_data[i], i)
コード例 #54
0
    def test_001(self):
        self.maxDiff = None
        tb = gr.top_block()
        src1 = gr.vector_source_i(range(0, 100))
        src2 = gr.vector_source_i(range(0, 100))
        src3 = gr.vector_source_i(range(0, 100))

        # itemsize, M, N, offset
        km2 = gr.keep_m_in_n(gr.sizeof_int, 4, 1, 2, 0)
        km3 = gr.keep_m_in_n(gr.sizeof_int, 4, 1, 3, 1)
        km7 = gr.keep_m_in_n(gr.sizeof_int, 4, 1, 7, 2)
        snk2 = gr.vector_sink_i()
        snk3 = gr.vector_sink_i()
        snk7 = gr.vector_sink_i()
        tb.connect(src1, km2, snk2)
        tb.connect(src2, km3, snk3)
        tb.connect(src3, km7, snk7)
        tb.run()

        self.assertEqual(range(0, 100, 2), list(snk2.data()))
        self.assertEqual(range(1, 100, 3), list(snk3.data()))
        self.assertEqual(range(2, 100, 7), list(snk7.data()))
コード例 #55
0
    def test_int_001(self):
        lenx = 64
        src0 = range(0, lenx, 1)
        a = sb.DataSource(dataFormat="long")
        op = gr.interleave(gr.sizeof_int, 1)
        dst = gr.vector_sink_i()
        a.connect(op, providesPortName="long_in")
        a.push(src0, EOS=True)
        self.tb.connect(op, dst)
        self.tb.run()
        expected_result = tuple(range(lenx))
        result_data = dst.data()

        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
コード例 #56
0
ファイル: qa_randint.py プロジェクト: pgoeser/gnuradio-mlse
 def test_001(self):
     """numbers from 0 to 6, this time in an int source"""
     src = mlse_swig.randint_i(7)
     head = gr.head(gr.sizeof_int, 10000)
     dst = gr.vector_sink_i()
     self.tb.connect(src, head, dst)
     self.tb.run()
     data = dst.data()
     a = set(data)
     self.assertEquals(a, set(range(7)))
     counts = [data.count(i) for i in range(7)]
     countdiff = max(counts) - min(counts)
     print max(counts), min(counts), countdiff
     self.assertTrue(countdiff < 500)  # this can fail by chance
コード例 #57
0
    def test_002(self):

        src_data = [1, 2, 3, 4]
        expected_result = [16777216, 33554432, 50331648, 67108864]

        src = gr.vector_source_i(src_data)
        op = gr.endian_swap(4)
        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)
コード例 #58
0
    def test_002(self):

        src_data=(-100,-99,-98,-97,-96,-1)
        expected_result = ((max(src_data)), )

        src = gr.vector_source_i(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_int, len(src_data))
        op = gr.max_(gr.sizeof_int, 1, len(src_data) )
        dst = gr.vector_sink_i()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)