示例#1
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)
示例#3
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)
示例#4
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)
示例#5
0
    def __init__(self):
        """
        """

        v2s = blocks.vector_to_stream(gr.sizeof_char, atsc.sizeof_atsc_mpeg_packet)
        self.sink = blocks.vector_sink_b()
	gr.hier_block2.__init__(self, "vector_sink_ts",
				v2s.input_signature(),
				gr.io_signature(0, 0, 0))
        self.connect(self, v2s, self.sink)
示例#6
0
    def __init__(self):
        """
        """

        v2s = blocks.vector_to_stream(gr.sizeof_char,
                                      atsc.sizeof_atsc_mpeg_packet)
        self.sink = blocks.vector_sink_b()
        gr.hier_block2.__init__(self, "vector_sink_ts", v2s.input_signature(),
                                gr.io_signature(0, 0, 0))
        self.connect(self, v2s, self.sink)
示例#7
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)
示例#8
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)
 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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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)
示例#14
0
    def test_003(self):

        #Test streams_to_vector (using stream_to_streams & vector_to_stream).

        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_streams(gr.sizeof_int, n)
        op2 = blocks.streams_to_vector(gr.sizeof_int, n)
        op3 = blocks.vector_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        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())
示例#15
0
    def test_003(self):

        #Test streams_to_vector (using stream_to_streams & vector_to_stream).

        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_streams(gr.sizeof_int, n)
        op2 = blocks.streams_to_vector(gr.sizeof_int, n)
        op3 = blocks.vector_to_stream(gr.sizeof_int, n)
        dst = blocks.vector_sink_i()

        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())