Esempio n. 1
0
    def test_001(self):
        tb = self.tb

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

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

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

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

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

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

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

        tb.run()
        index = dst1.data()
        source = dst2.data()
        self.assertEqual(index, (4,))
        self.assertEqual(source, (0,))
Esempio n. 2
0
    def test_001(self):
        tb = self.tb

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

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

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

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

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

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

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

        tb.run()
        index = dst1.data()
        source = dst2.data()
        self.assertEqual(index, (4, ))
        self.assertEqual(source, (0, ))
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude)
     add = blocks.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = blocks.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
Esempio n. 4
0
    def test_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 = blocks.vector_source_f(src_data, False)
        s2v = blocks.stream_to_vector(gr.sizeof_float, vlen)
        stats = blocks.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)
Esempio n. 5
0
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = blocks.vector_source_c(v0)
        src1 = blocks.vector_source_b(v1)

        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)

        # print "len(v) = %d" % (len(v))

        op = digital.ofdm_insert_preamble(fft_length, preamble)

        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = blocks.vector_sink_c()
        dst1 = blocks.vector_sink_b()

        tb.connect(src0, s2v, (op, 0))
        tb.connect(src1, (op, 1))
        tb.connect((op, 0), v2s, dst0)
        tb.connect((op, 1), dst1)

        tb.run()
        r0 = dst0.data()
        r0v = []
        for i in range(len(r0) // fft_length):
            r0v.append(r0[i * fft_length:(i + 1) * fft_length])

        r1 = dst1.data()
        self.assertEqual(len(r0v), len(r1))
        return (r1, r0v)
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = blocks.vector_source_c(v0)
        src1 = blocks.vector_source_b(v1)
        
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)

        # print "len(v) = %d" % (len(v))

        op = digital.ofdm_insert_preamble(fft_length, preamble)

        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = blocks.vector_sink_c()
        dst1 = blocks.vector_sink_b()

        tb.connect(src0, s2v, (op, 0))
        tb.connect(src1, (op, 1))
        tb.connect((op, 0), v2s, dst0)
        tb.connect((op, 1), dst1)

        tb.run()
        r0 = dst0.data()
        r0v = []
        for i in range(len(r0)//fft_length):
            r0v.append(r0[i*fft_length:(i+1)*fft_length])
            
        r1 = dst1.data()
        self.assertEqual(len(r0v), len(r1))
        return (r1, r0v)
Esempio n. 7
0
    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 = blocks.stream_to_vector(gr.sizeof_float, vlen)
        stats = blocks.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)
Esempio n. 8
0
    def help_const_ii(self, src_data, exp_data, op):
	src = blocks.vector_source_i(src_data)
	srcv = blocks.stream_to_vector(gr.sizeof_int, len(src_data))
	rhs = blocks.vector_to_stream(gr.sizeof_int, len(src_data))
        dst = blocks.vector_sink_i()
        self.tb.connect(src, srcv, op, rhs, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(exp_data, result_data)
Esempio n. 9
0
    def test_003(self):
        # Same test as above, only use 2 threads

        tb = gr.top_block()
        fft_size = 32

        tmp_data = (
            (4377 + 4516j),
            (-1706.1268310546875 + 1638.4256591796875j),
            (-915.2083740234375 + 660.69427490234375j),
            (-660.370361328125 + 381.59600830078125j),
            (-499.96044921875 + 238.41630554199219j),
            (-462.26748657226562 + 152.88948059082031j),
            (-377.98440551757812 + 77.5928955078125j),
            (-346.85821533203125 + 47.152004241943359j),
            (-295 + 20j),
            (-286.33609008789062 - 22.257017135620117j),
            (-271.52999877929688 - 33.081821441650391j),
            (-224.6358642578125 - 67.019538879394531j),
            (-244.24473571777344 - 91.524826049804688j),
            (-203.09068298339844 - 108.54627227783203j),
            (-198.45195007324219 - 115.90768432617188j),
            (-182.97744750976562 - 128.12318420410156j),
            (-167 - 180j),
            (-130.33688354492188 - 173.83778381347656j),
            (-141.19784545898438 - 190.28807067871094j),
            (-111.09677124023438 - 214.48896789550781j),
            (-70.039543151855469 - 242.41630554199219j),
            (-68.960540771484375 - 228.30015563964844j),
            (-53.049201965332031 - 291.47097778320312j),
            (-28.695289611816406 - 317.64553833007812j),
            (57 - 300j),
            (45.301143646240234 - 335.69509887695312j),
            (91.936195373535156 - 373.32437133789062j),
            (172.09465026855469 - 439.275146484375j),
            (242.24473571777344 - 504.47515869140625j),
            (387.81732177734375 - 666.6788330078125j),
            (689.48553466796875 - 918.2142333984375j),
            (1646.539306640625 - 1694.1956787109375j),
        )

        src_data = tuple([x / fft_size for x in tmp_data])

        expected_result = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(fft_size)])

        nthreads = 2

        src = blocks.vector_source_c(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        op = fft.fft_vcc(fft_size, False, [], False, nthreads)
        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_size)
        dst = blocks.vector_sink_c()
        tb.connect(src, s2v, op, v2s, dst)
        tb.run()
        result_data = dst.data()
        self.assert_fft_ok2(expected_result, result_data)
Esempio n. 10
0
    def help_cc(self, size, src_data, exp_data, op):
        for s in zip(range (len (src_data)), src_data):
            src = blocks.vector_source_c(s[1])
	    srcv = blocks.stream_to_vector(gr.sizeof_gr_complex, size)
	    self.tb.connect(src, srcv)
            self.tb.connect(srcv, (op, s[0]))
	rhs = blocks.vector_to_stream(gr.sizeof_gr_complex, size)
        dst = blocks.vector_sink_c()
        self.tb.connect(op, rhs, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(exp_data, result_data)
Esempio n. 11
0
    def test_003(self):
        # Same test as above, only use 2 threads

        tb = gr.top_block()
        fft_size = 32

        tmp_data = (
            (4377 + 4516j), (-1706.1268310546875 + 1638.4256591796875j),
            (-915.2083740234375 + 660.69427490234375j),
            (-660.370361328125 + 381.59600830078125j), (-499.96044921875 +
                                                        238.41630554199219j),
            (-462.26748657226562 + 152.88948059082031j), (-377.98440551757812 +
                                                          77.5928955078125j),
            (-346.85821533203125 + 47.152004241943359j), (-295 + 20j),
            (-286.33609008789062 - 22.257017135620117j), (-271.52999877929688 -
                                                          33.081821441650391j),
            (-224.6358642578125 - 67.019538879394531j), (-244.24473571777344 -
                                                         91.524826049804688j),
            (-203.09068298339844 - 108.54627227783203j), (-198.45195007324219 -
                                                          115.90768432617188j),
            (-182.97744750976562 - 128.12318420410156j), (-167 - 180j),
            (-130.33688354492188 - 173.83778381347656j), (-141.19784545898438 -
                                                          190.28807067871094j),
            (-111.09677124023438 - 214.48896789550781j), (-70.039543151855469 -
                                                          242.41630554199219j),
            (-68.960540771484375 - 228.30015563964844j), (-53.049201965332031 -
                                                          291.47097778320312j),
            (-28.695289611816406 - 317.64553833007812j), (57 - 300j),
            (45.301143646240234 - 335.69509887695312j),
            (91.936195373535156 - 373.32437133789062j), (172.09465026855469 -
                                                         439.275146484375j),
            (242.24473571777344 - 504.47515869140625j), (387.81732177734375 -
                                                         666.6788330078125j),
            (689.48553466796875 - 918.2142333984375j), (1646.539306640625 -
                                                        1694.1956787109375j))

        src_data = tuple([x / fft_size for x in tmp_data])

        expected_result = tuple([
            complex(primes[2 * i], primes[2 * i + 1]) for i in range(fft_size)
        ])

        nthreads = 2

        src = blocks.vector_source_c(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        op = fft.fft_vcc(fft_size, False, [], False, nthreads)
        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_size)
        dst = blocks.vector_sink_c()
        tb.connect(src, s2v, op, v2s, dst)
        tb.run()
        result_data = dst.data()
        self.assert_fft_ok2(expected_result, result_data)
Esempio n. 12
0
    def test_002(self):
	src_data=(-100,-99,-98,-97,-96,-1)
	expected_result = (float(max(src_data)),)

	src = gr.vector_source_f(src_data)
	s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data))
	op = blocks.max_ff(len(src_data))
	dst = gr.vector_sink_f()

	self.tb.connect(src, s2v, op, dst)
	self.tb.run()
	result_data = dst.data()
	self.assertEqual(expected_result, result_data)
Esempio n. 13
0
 def test_ff_003(self):
     block_size = 2
     src_data = (0, 1000, 2000, 3000, 4000, 5000)
     expected_result = (0, 125, 250, 484.375, 718.75, 1048.828125)
     src = blocks.vector_source_f(src_data)
     s2p = blocks.stream_to_vector(gr.sizeof_float, block_size)
     op = filter.single_pole_iir_filter_ff (0.125, block_size)
     p2s = blocks.vector_to_stream(gr.sizeof_float, block_size)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, s2p, op, p2s, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(expected_result, result_data, 3)
Esempio n. 14
0
    def test_001(self):
        src_data = (0, 0.2, -0.3, 0, 12, 0)
        expected_result = (float(max(src_data)), )

        src = blocks.vector_source_f(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data))
        op = blocks.max_ff(len(src_data))
        dst = blocks.vector_sink_f()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Esempio n. 15
0
 def test_ff_003(self):
     block_size = 2
     src_data = (0, 1000, 2000, 3000, 4000, 5000)
     expected_result = (0, 125, 250, 484.375, 718.75, 1048.828125)
     src = blocks.vector_source_f(src_data)
     s2p = blocks.stream_to_vector(gr.sizeof_float, block_size)
     op = filter.single_pole_iir_filter_ff(0.125, block_size)
     p2s = blocks.vector_to_stream(gr.sizeof_float, block_size)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, s2p, op, p2s, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(expected_result, result_data, 3)
Esempio n. 16
0
    def test_001(self):
        src_data = (0,0.2,-0.3,0,12,0)
        expected_result = (float(max(src_data)),)

        src = gr.vector_source_f(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data))
        op = blocks.max_ff(len(src_data))
        dst = gr.vector_sink_f()

        self.tb.connect(src, s2v, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
Esempio n. 17
0
    def test_002(self):
	src_data=(-100,-99,-98,-97,-96,-1)
	expected_result = (float(max(src_data)),)

	src = blocks.vector_source_f(src_data)
	s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data))
	op = blocks.max_ff(len(src_data))
	dst = blocks.vector_sink_f()

	self.tb.connect(src, s2v, op, dst)
	self.tb.run()
	result_data = dst.data()
	self.assertEqual(expected_result, result_data)
Esempio n. 18
0
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 1
     carr_offset = -2
     freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency
     occupied_carriers = ((-2, -1, 1, 2),)
     pilot_carriers = ((-3,),(3,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = (1, 2, 3, 4)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_data))
     offsettag = gr.tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, (1.0/fft_len,)*fft_len, True)
     oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0/fft_len)
     mixer = blocks.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     sink2 = blocks.vector_sink_c(fft_len)
     self.tb.connect(rx_fft, sink2)
     serializer = digital.ofdm_serializer_vcc(
             alloc, "", 0, "ofdm_sync_carr_offset", True
     )
     sink = blocks.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             blocks.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(oscillator, (mixer, 1))
     self.tb.run ()
     self.assertComplexTuplesAlmostEqual(sink.data()[-len(occupied_carriers[0]):], tx_data, places=4)
Esempio n. 19
0
    def __init__(self, ts):
        """
        Pad tranport stream packets to 256 bytes and reformat appropriately.

        Args:
            ts: MPEG transport stream. (sequence of ints in [0,255]; len(ts) % 188 == 0)
        """

        src = blocks.vector_source_b(pad_transport_stream(ts))
        s2v = blocks.stream_to_vector(gr.sizeof_char, atsc.sizeof_atsc_mpeg_packet)

	gr.hier_block2.__init__(self, "vector_source_ts",
				gr.io_signature(0, 0, 0),
				s2v.output_signature())
        self.connect(src, s2v, self)
Esempio n. 20
0
    def test_002(self):
        vector_length = 10
        repeats = 10
        value = [0.5+i for i in range(0, vector_length)]
        src_data = value * repeats

        src = blocks.vector_source_f(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_float, vector_length)
        dst = blocks.probe_signal_vf(vector_length)

        self.tb.connect(src, s2v, dst)
        self.tb.run()
        output = dst.level()
        self.assertEqual(len(output), vector_length)
        self.assertAlmostEqual(value[3], output[3], places=6)
Esempio n. 21
0
    def test_002(self):
        vector_length = 10
        repeats = 10
        value = [0.5 + i for i in range(0, vector_length)]
        src_data = value * repeats

        src = blocks.vector_source_f(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_float, vector_length)
        dst = blocks.probe_signal_vf(vector_length)

        self.tb.connect(src, s2v, dst)
        self.tb.run()
        output = dst.level()
        self.assertEqual(len(output), vector_length)
        self.assertAlmostEqual(value[3], output[3], places=6)
Esempio n. 22
0
 def test_cc_003(self):
     block_size = 2
     src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000),
                 complex(3000,-3000), complex(4000,-4000), complex(5000,-5000))
     expected_result = (complex(0,0), complex(125,-125), complex(250,-250),
                        complex(484.375,-484.375), complex(718.75,-718.75),
                        complex(1048.828125,-1048.828125))
     src = blocks.vector_source_c(src_data)
     s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, block_size)
     op = filter.single_pole_iir_filter_cc(0.125, block_size)
     p2s = blocks.vector_to_stream(gr.sizeof_gr_complex, block_size)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, s2p, op, p2s, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_result, result_data, 3)
Esempio n. 23
0
    def __init__(self, ts):
        """
        Pad tranport stream packets to 256 bytes and reformat appropriately.

        Args:
            ts: MPEG transport stream. (sequence of ints in [0,255]; len(ts) % 188 == 0)
        """

        src = blocks.vector_source_b(pad_transport_stream(ts))
        s2v = blocks.stream_to_vector(gr.sizeof_char,
                                      atsc.sizeof_atsc_mpeg_packet)

        gr.hier_block2.__init__(self, "vector_source_ts",
                                gr.io_signature(0, 0, 0),
                                s2v.output_signature())
        self.connect(src, s2v, self)
Esempio n. 24
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset / 2, max_offset / 2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [
         rand_range(min_chan_ampl, max_chan_ampl) *
         numpy.exp(1j * rand_range(0, 2 * numpy.pi))
         for x in range(fft_len)
     ]
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude)
     add = blocks.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = blocks.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(
         noise, blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len),
         (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [
         0,
     ] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(
                 pmt.c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i],
                                    channel_est[i],
                                    places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est,
                                           -carr_offset_hat)))
Esempio n. 25
0
 def test_cc_003(self):
     block_size = 2
     src_data = (complex(0, 0), complex(1000, -1000), complex(2000, -2000),
                 complex(3000, -3000), complex(4000,
                                               -4000), complex(5000, -5000))
     expected_result = (complex(0, 0), complex(125,
                                               -125), complex(250, -250),
                        complex(484.375,
                                -484.375), complex(718.75, -718.75),
                        complex(1048.828125, -1048.828125))
     src = blocks.vector_source_c(src_data)
     s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, block_size)
     op = filter.single_pole_iir_filter_cc(0.125, block_size)
     p2s = blocks.vector_to_stream(gr.sizeof_gr_complex, block_size)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, s2p, op, p2s, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_result, result_data, 3)
Esempio n. 26
0
    def test_004(self):

        #Test vector_to_streams.

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

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_vector(gr.sizeof_int, n)
        op2 = blocks.vector_to_streams(gr.sizeof_int, n)
        op3 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

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

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Esempio n. 27
0
    def test_004(self):

        #Test vector_to_streams.

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

        src = blocks.vector_source_i(src_data)
        op1 = blocks.stream_to_vector(gr.sizeof_int, n)
        op2 = blocks.vector_to_streams(gr.sizeof_int, n)
        op3 = blocks.streams_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

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

        self.tb.run()
        self.assertEqual(expected_results, dst.data())
Esempio n. 28
0
    def __init__(self, item_size, sample_rate, vec_rate, vec_len):
        """
        Create the block chain.

        Args:
            item_size: the number of bytes per sample
            sample_rate: the rate of incoming samples
            vec_rate: the rate of outgoing vectors (same units as sample_rate)
            vec_len: the length of the outgoing vectors in items
        """
        self._vec_rate = vec_rate
        self._vec_len = vec_len
        self._sample_rate = sample_rate

        gr.hier_block2.__init__(self, "stream_to_vector_decimator",
                                gr.io_signature(1, 1, item_size),         # Input signature
                                gr.io_signature(1, 1, item_size*vec_len)) # Output signature

        s2v = blocks.stream_to_vector(item_size, vec_len)
        self.one_in_n = blocks.keep_one_in_n(item_size*vec_len, 1)
        self._update_decimator()
        self.connect(self, s2v, self.one_in_n, self)