def test_002_t (self):
		# set up fg
		# check on reverse by using two times
		test_len = 12
		in_data = range(test_len)
		vlen_in = 3
		vlen_out = 4
		
		src = blocks.vector_source_c(in_data)
		stv = blocks.stream_to_vector(8,vlen_in)
		s2ts = blocks.stream_to_tagged_stream(8,vlen_in,test_len/vlen_in,'packet_len')
		transpose1 = radar.transpose_matrix_vcvc(vlen_in,vlen_out,'packet_len')
		transpose2 = radar.transpose_matrix_vcvc(vlen_out,vlen_in,'packet_len')
		vts = blocks.vector_to_stream(8,vlen_in)
		snk = blocks.vector_sink_c()
		vts2 = blocks.vector_to_stream(8,vlen_out)
		snk2 = blocks.vector_sink_c()
		
		self.tb.connect(src,stv,s2ts,transpose1,transpose2,vts,snk)
		self.tb.connect(transpose1,vts2,snk2)
		self.tb.run()
		
		# check data
		out_data_real = [0]*len(in_data)
		out_data = snk.data()
		for k in range(len(in_data)):
			out_data_real[k] = out_data[k].real
			
		print "Input data:", in_data
		print "Output data:", out_data_real
		print "Transpose data:", snk2.data()
			
		for k in range(len(out_data_real)):
			self.assertEqual(out_data_real[k],in_data[k])
    def __init__(self, M):
        gr.hier_block2.__init__(self,
            "overlapping_parallel_to_serial_vcc",
            gr.io_signature(2, 2, gr.sizeof_gr_complex*M),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1)) # Output signature

        # Variables
        self.M = M

        # Assertions
        assert (M>0 and int(math.log(M,2))==math.log(M,2)), "M should be of 2^n!"

        # Blocks
        self.vector_to_stream0 = blocks.vector_to_stream(gr.sizeof_gr_complex*M/2, 2)
        self.vector_to_stream1 = blocks.vector_to_stream(gr.sizeof_gr_complex*M/2, 2)
        self.delay = blocks.delay(gr.sizeof_gr_complex*M/2, 1)
        self.adder = blocks.add_vcc(M/2)

        # Connections
        self.connect((self,0),self.vector_to_stream0)
        self.connect((self,1),self.vector_to_stream1)
        self.connect(self.vector_to_stream0, (self.adder,0))
        self.connect(self.vector_to_stream1, self.delay)
        self.connect(self.delay, (self.adder,1))
        self.connect((self.adder,0), blocks.vector_to_stream(gr.sizeof_gr_complex, M/2),(self,0))
示例#3
0
    def __init__(self):
        gr.top_block.__init__(self, "TEST")
        bitstream = [1, 0, 0, 1, 0, 1]
        cdma_code = [
            1, 1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1,
            -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1
        ]

        self.cdma_rx = cdmarx(len(bitstream))
        self.cdmagenerator = cdmagen(cdma_code)
        self.rrc_stream = blocks.vector_to_stream(
            np.dtype(np.float32).itemsize,
            len(cdma_code) * len(bitstream))
        self.rrc_filt = rrc_filter(500000, .0001, 1, len(bitstream))
        self.vector_source = blocks.vector_source_b(data=bitstream,
                                                    repeat=False,
                                                    vlen=1)
        self.vector_to_stream = blocks.vector_to_stream(1, 1)
        self.vector_to_stream2 = blocks.vector_to_stream(
            np.dtype(np.float32).itemsize,
            len(bitstream) * 32)
        self.vector_to_stream3 = blocks.vector_to_stream(32 * 32, 32)
        self.stream_to_vector = blocks.stream_to_vector(
            np.dtype(np.int8).itemsize, 32)
        self.cpfsk_gen = cpfsk()

        self.connect(self.vector_source, self.vector_to_stream)
        self.connect(self.vector_to_stream, self.cdmagenerator)
        self.connect(self.cdmagenerator, self.rrc_filt)
        self.connect(self.rrc_filt, self.cdma_rx)
    def test_001_t(self):
        # set up fg
        test_input = (1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7,
                      8)
        test_output = (3, 4, 5, 6)
        test_output1 = (2, 2, 2, 2)
        # set up fg
        vector_input = blocks.vector_source_f(test_input)
        s_to_v = blocks.stream_to_vector(gr.sizeof_float, 20)
        #s_to_v_1 = blocks.stream_to_vector(gr.sizeof_float,9);

        summing = stream_avg_all.stream_avg_ff(4, 5)
        v_to_s = blocks.vector_to_stream(gr.sizeof_float, 4)
        v_to_s_1 = blocks.vector_to_stream(gr.sizeof_float, 4)
        dest = blocks.vector_sink_f()
        dest_1 = blocks.vector_sink_f()

        self.tb.connect(vector_input, s_to_v)
        #self.tb.connect(s_to_v,s_to_v_1);
        self.tb.connect(s_to_v, summing)
        self.tb.connect((summing, 0), v_to_s)
        self.tb.connect((summing, 1), v_to_s_1)
        #self.tb.connect(v_to_s_1,v_to_s);
        self.tb.connect(v_to_s, dest)
        self.tb.connect(v_to_s_1, dest_1)
        self.tb.run()
        #print dest.data();
        #print dest_1.data();

        self.assertEqual(test_output, dest.data())
        self.assertEqual(test_output1, dest_1.data())
示例#5
0
    def __init__(self, fft_size=4096):
        gr.hier_block2.__init__(
            self,
            "Fast Autocor",
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.fft_size = fft_size

        ##################################################
        # Blocks
        ##################################################
        self.fft_vxx_0_0 = fft.fft_vcc(fft_size, False,
                                       (window.hamming(fft_size)), False, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True,
                                     (window.hamming(fft_size)), False, 1)
        self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff(
            (1.0 / fft_size, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (2048.0 / fft_size, ))
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_mag_squared_1 = blocks.complex_to_mag_squared(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_vector_to_stream_0, 0),
                     (self.blocks_complex_to_mag_squared_1, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.blocks_stream_to_vector_0_0, 0),
                     (self.fft_vxx_0_0, 0))
        self.connect((self.fft_vxx_0_0, 0),
                     (self.blocks_vector_to_stream_0_0, 0))
        self.connect((self.blocks_vector_to_stream_0_0, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_stream_to_vector_0_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0))
        self.connect((self.blocks_complex_to_mag_squared_1, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_float_to_complex_0, 0))
    def __init__(self, n=512):
        gr.top_block.__init__(self, "SDR Spectrum Analyzer Server")

        ##################################################
        # Variables
        ##################################################
        self.port = port = 9999
        self.gan = gan = 10
        self.fc = fc = 99700000
        self.ab = ab = 20000000
        self.N = N = 1024
        self.n = n
        self.IP = IP = "192.168.1.103"
        self.Antena = Antena = "RX2"
        self.ventana = ventana = window.blackmanharris
        self.base = base = "exponencial"

        ##################################################
        # Blocks
        ##################################################
        self.src = uhd.usrp_source(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.src.set_samp_rate(ab)
        self.src.set_center_freq(fc, 0)
        self.src.set_gain(gan, 0)
        self.src.set_antenna("RX2", 0)
        self.dbm = RadioGIS.dbm()
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, N)
        self.blocks_vector_to_stream_1 = blocks.vector_to_stream(gr.sizeof_float*1, N)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, N*n)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, N)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(N)
        self.udp_sink_0 = blocks.udp_sink(gr.sizeof_float*1, IP, port, 1472, True)
        self.RadioGIS_fft_0 = RadioGIS.fft(N, base, (ventana(N)))
        self.RadioGIS_averager_0 = RadioGIS.averager(N, n)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.RadioGIS_averager_0, 0), (self.blocks_vector_to_stream_0, 0))    
        self.connect((self.dbm, 0), (self.udp_sink_0, 0))    
        self.connect((self.RadioGIS_fft_0, 0), (self.blocks_complex_to_mag_0, 0))    
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_vector_to_stream_1, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.RadioGIS_fft_0, 0))    
        self.connect((self.blocks_stream_to_vector_1, 0), (self.RadioGIS_averager_0, 0))    
        self.connect((self.blocks_vector_to_stream_0, 0), (self.dbm, 0))    
        self.connect((self.blocks_vector_to_stream_1, 0), (self.blocks_stream_to_vector_1, 0))    
        self.connect((self.src, 0), (self.blocks_stream_to_vector_0, 0))
示例#7
0
    def test_001_t(self):
        vsize = 1024
        m = 10 * vsize
        V1 = np.random.random_sample(m)  # 1 many values
        V2 = np.random.random_sample(m)  # 1 many values
        V = V1 + (V2 * 1j)
        Vmag = V * V
        # create a set of vectors
        src = blocks.vector_source_c(V.tolist())
        mag = blocks.vector_source_c(Vmag.tolist())
        instream = blocks.vector_to_stream(gr.sizeof_gr_complex, vsize)
        in2stream = blocks.vector_to_stream(gr.sizeof_gr_complex, vsize)

        # setup for running test
        mode = 1
        nsigma = 5.
        sample_rate = 1.e6
        sample_delay = 3. / sample_rate
        # block we're testing
        vblock = ra_vevent(vsize, mode, nsigma, sample_rate, sample_delay)

        vsnk = blocks.vector_sink_c(vsize)
        magsnk = blocks.null_sink(1)
        rmssnk = blocks.null_sink(1)
        utcsnk = blocks.null_sink(1)

        self.tb.connect(src, instream)
        self.tb.connect(mag, in2stream)
        self.tb.connect(instream, vblock, 0)
        self.tb.connect(in2stream, vblock, 1)
        # now connect test bolck outputs a fector and two magnitudes
        self.tb.connect(vblock, vsnk, 0)
        self.tb.connect(vblock, magsnk, 1)
        self.tb.connect(vblock, rmssnk, 2)
        self.tb.connect(vblock, utcsnk, 3)
        #        self.tb.connect (v2s, snk)
        expected = V[0:vsize]
        print 'Expected: ', expected[0:7]
        outdata = None
        waittime = 0.01

        self.tb.run()
        outdata = snk.data()
        print 'Output: ', outdata[0:vsize]
        # check data
        print 'Magnitude: ', magsnk.data()
        print 'Rms      : ', magsnk.data()

        self.assertFloatTuplesAlmostEqual(1., 1., 1)
    def test_symbol_demapper_qpsk(self):
        # set up fg
        demapper = isdbt.symbol_demapper_1seg(mode=3, constellation_size=4)
        #src_data = (0.5 + 0.5j,  0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
        #            0.8 + 1.0j, -0.5 + 0.1j,  0.5 - 1.2j, -0.2 - 1.0j) * 48
        src_syms = [
            1 + 1j, 1 - 1j, -1 - 1j, -1 + 1j, 1 + 1j, -1 + 1j, 1 - 1j, -1 - 1j
        ]
        src_syms_noisy = [self.add_noise(z) for z in src_syms]
        src_data = src_syms_noisy * 48
        # normalización sqrt(2) ?
        expected_result = \
            (    0,       1,       3,       2,
                 0,       2,       1,       3) * 48

        src = blocks.vector_source_c(src_data)
        str_to_vec = blocks.stream_to_vector(gr.sizeof_gr_complex, 384)
        vec_to_str = blocks.vector_to_stream(gr.sizeof_char, 384)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, str_to_vec)
        self.tb.connect(str_to_vec, demapper)
        self.tb.connect(demapper, vec_to_str)
        self.tb.connect(vec_to_str, dst)
        self.tb.run()

        # check data
        actual_result = dst.data()
        #print "actual result", actual_result
        #print "expected result", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
示例#9
0
 def test_003_t (self):
     # set up fg
     fname = "/home/manu/repos/ldpc/gr-ldpc/python/alist-files/96.3.963"
     epsilon = 0.04
     max_iterations = 100
     encoder = ldpc.ldpc_encoder_bb(fname)
     N = encoder.get_N()
     channel = ldpc.bsc_bb(N, epsilon)
     decoder = ldpc.ldpc_decoder_bb(fname, epsilon, max_iterations)
     blk_len = encoder.get_K()
     datatpl = array.array('B')
     txdata = ()
     for i in range(blk_len):
         X = random.randint(0, 1)
         if X == 1:
             datatpl.append(1)
             txdata = txdata + (1, )
         else:
             datatpl.append(0)
             txdata = txdata + (0, )
     src = blocks.vector_source_b(datatpl)
     str2vec = blocks.stream_to_vector(1, blk_len)
     vec2str = blocks.vector_to_stream(1, blk_len)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, str2vec, encoder, channel, decoder, vec2str, dst)
     self.tb.run ()
     rxtpl = dst.data()
     self.assertTupleEqual(txdata, rxtpl)
    def test_001_t(self):
        for exponent in range(1,10):
            in_data = (1+1j, -1, 4-1j, -3-7j)
            out_data = (in_data[0]**exponent, in_data[1]**exponent, in_data[2]**exponent, in_data[3]**exponent)

            # Test streaming input
            source = blocks.vector_source_c(in_data, False, 1)
            exponentiate_const_cci = blocks.exponentiate_const_cci(exponent)
            sink = blocks.vector_sink_c(1)

            self.tb.connect(source, exponentiate_const_cci, sink)
            self.tb.run()

            self.assertAlmostEqual(sink.data(), out_data)

            # Test vector input
            for vlen in [2, 4]:
                source = blocks.vector_source_c(in_data, False, 1)
                s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen)
                exponentiate_const_cci = blocks.exponentiate_const_cci(exponent, vlen)
                v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, vlen)
                sink = blocks.vector_sink_c(1)

                self.tb.connect(source, s2v, exponentiate_const_cci, v2s, sink)
                self.tb.run()

                self.assertAlmostEqual(sink.data(), out_data)
示例#11
0
    def __init__(self, sample_rate, fac_size, fac_decimation, title, autoScale,
                 grid, yMin, yMax, use_db):
        gr.hier_block2.__init__(
            self,
            "AutoCorrelatorSink",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self.fac_size = fac_size
        self.fac_decimation = fac_decimation
        self.sample_rate = sample_rate

        autoCorr = AutoCorrelator(sample_rate, fac_size, fac_decimation,
                                  use_db)
        vecToStream = blocks.vector_to_stream(gr.sizeof_float, self.fac_size)

        self.timeSink = qtgui.time_sink_f(self.fac_size // 2, sample_rate,
                                          title, 1, None)
        self.timeSink.enable_grid(grid)
        self.timeSink.set_y_axis(yMin, yMax)
        self.timeSink.enable_autoscale(autoScale)
        self.timeSink.disable_legend()
        self.timeSink.set_update_time(0.1)

        if use_db:
            self.connect(self, autoCorr, vecToStream, self.timeSink)
        else:
            norm = Normalize(self.fac_size)
            self.connect(self, autoCorr, norm, vecToStream, self.timeSink)
示例#12
0
    def __init__(self, enable, fftsize, decimation, average, wintype,
                 freq_central, bandwidth, freq_cutoff, threshold, samp_rate):
        gr.hier_block2.__init__(self, "signal_search_fft_hier",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.enable = enable
        self.average = average
        self.freq_central = freq_central
        self.freq_cutoff = freq_cutoff
        self.threshold = threshold
        self.samp_rate = samp_rate
        self.bandwidth = bandwidth
        self.wintype = wintype
        self.decimation = decimation
        self.fftsize = fftsize

        self.ecss_signal_search_fft_v = ecss.signal_search_fft_v(
            self.enable, self.fftsize, self.decimation, self.average,
            self.wintype, self.freq_central, self.bandwidth, self.freq_cutoff,
            self.threshold, self.samp_rate)
        self.blocks_stream_to_vector = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, self.fftsize * self.decimation)
        self.blocks_vector_to_stream = blocks.vector_to_stream(
            gr.sizeof_gr_complex * 1, self.fftsize * self.decimation)

        ##################################################
        # Connections
        ##################################################
        self.connect(self, (self.blocks_stream_to_vector, 0))
        self.connect((self.blocks_stream_to_vector, 0),
                     (self.ecss_signal_search_fft_v, 0))
        self.connect((self.ecss_signal_search_fft_v, 0),
                     (self.blocks_vector_to_stream, 0))
        self.connect((self.blocks_vector_to_stream, 0), self)
    def test_001_t (self):
    	# This test case is from Fundamentals of Error-Correcting
    	# Codes by Huffman and Pless. First part of Example 15.7.1.

    	# Generator matrix from textbook example
    	G = np.array([[1,0,0,0,0,1,1,1],
	                  [0,1,0,0,1,0,1,1],
	                  [0,0,1,0,1,1,0,1],
	                  [0,0,0,1,1,1,1,0]])
    	# this is the dataword to be encoded
    	dataword = (1,0,1,1)
    	# this is what the encoder should produce
    	codeword = (1,0,1,1,0,1,0,0)
    	k = len(dataword)
    	n = len(codeword)
    	src = blocks.vector_source_i(dataword)
        str2vec = blocks.stream_to_vector(4, k)
        vec2str = blocks.vector_to_stream(4, n)
        encoder = generator_matrix_encoder_ss(G)
        dst = blocks.vector_sink_i()
        self.tb.connect(src, str2vec, encoder, vec2str, dst)
        self.tb.run ()
        result_data = dst.data()
        # check data
        self.assertTupleEqual(codeword,result_data)
示例#14
0
    def __init__(self, sample_rate, fac_size, fac_rate):
        gr.hier_block2.__init__(self, "fast_autocorrelator_c",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(1, 1, gr.sizeof_float))
        # Parameters
        self.sample_rate = sample_rate
        self.fac_size = fac_size
        self.fac_rate = fac_rate
        self.window = ()

        # Block Objects For Float Fast Autocorrelator
        self.stream_to_vector = blocks.stream_to_vector(
            gr.sizeof_float, fac_size)
        self.keep_one_in_n = blocks.keep_one_in_n(
            gr.sizeof_float * fac_size,
            max(1, int(sample_rate / fac_size / fac_rate)))
        self.fac_fft = fft.fft_vfc(fac_size, True, self.window)
        self.complex_to_mag = blocks.complex_to_mag(fac_size)
        self.fac_complex_to_mag = blocks.complex_to_mag(fac_size)
        self.nlog10_ff = blocks.nlog10_ff(20, fac_size,
                                          -20 * math.log10(fac_size))
        self.single_pole_iir_filter_ff = filter.single_pole_iir_filter_ff(
            1, fac_size)
        self.fft_vfc = fft.fft_vfc(fac_size, True, self.window)
        self.vector_to_stream = blocks.vector_to_stream(
            gr.sizeof_float, self.fac_size)

        # Connections for Auto Correlator
        self.connect(self, self.stream_to_vector, self.keep_one_in_n,
                     self.fft_vfc, self.complex_to_mag, self.fac_fft,
                     self.fac_complex_to_mag, self.single_pole_iir_filter_ff,
                     self.nlog10_ff, self.vector_to_stream, self)
示例#15
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 __init__(self,subcarriers, frame_length):
    #config = station_configuration()

    total_subc = subcarriers
    vlen = total_subc

    gr.hier_block2.__init__(self,"ofdm_frame_sampler_grc",
      gr.io_signature2(2,2,gr.sizeof_gr_complex*vlen,
                       gr.sizeof_char),
      gr.io_signature2(2,2,gr.sizeof_gr_complex*vlen,
                 gr.sizeof_char))


    ft = [0] * frame_length
    ft[0] = 1

    # The next block ensures that only complete frames find their way into
    # the old outer receiver. The dynamic frame start trigger is hence
    # replaced with a static one, fixed to the frame length.

    frame_sampler = vector_sampler( gr.sizeof_gr_complex * total_subc,
                                              frame_length )
    symbol_output = blocks.vector_to_stream( gr.sizeof_gr_complex * total_subc,
                                              frame_length )
    delayed_frame_start = blocks.delay( gr.sizeof_char, frame_length - 1 )
    damn_static_frame_trigger = blocks.vector_source_b( ft, True )

    self.connect( self, frame_sampler, symbol_output, self )

    self.connect( (self,1), delayed_frame_start, ( frame_sampler, 1 ) )

    self.connect( damn_static_frame_trigger, (self,1) )
    def test_symbol_demapper_qpsk (self):
        # set up fg
        demapper = isdbt.symbol_demapper_1seg(mode=3, constellation_size=4)
        #src_data = (0.5 + 0.5j,  0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
        #            0.8 + 1.0j, -0.5 + 0.1j,  0.5 - 1.2j, -0.2 - 1.0j) * 48
        src_syms = [
            1 + 1j,  1 - 1j, -1 - 1j, -1 + 1j,
            1 + 1j, -1 + 1j,  1 - 1j, -1 - 1j ]
        src_syms_noisy = [self.add_noise(z) for z in src_syms]
        src_data = src_syms_noisy * 48
        # normalización sqrt(2) ?
        expected_result = \
            (    0,       1,       3,       2,
                 0,       2,       1,       3) * 48

        src = blocks.vector_source_c(src_data)
        str_to_vec = blocks.stream_to_vector(gr.sizeof_gr_complex, 384)
        vec_to_str = blocks.vector_to_stream(gr.sizeof_char, 384)
        dst = blocks.vector_sink_b()

        self.tb.connect(src,str_to_vec)
        self.tb.connect(str_to_vec,demapper)
        self.tb.connect(demapper,vec_to_str)
        self.tb.connect(vec_to_str,dst)
        self.tb.run()

        # check data
        actual_result = dst.data()
        #print "actual result", actual_result
        #print "expected result", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
示例#18
0
 def test_002_select_vectors(self):
     skip = 2
     len = 3
     vlen = 2
     src_data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1,
                 2, 3, 4, 5, 6, 7, 8, 9)
     trig = (0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0)
     expected_data = (6, 7, 8, 9, 10, 11, 6, 7, 8, 9)
     expected_trig = (1, 0, 0, 1, 0)
     src = blocks.vector_source_f(src_data)
     trigsrc = blocks.vector_source_b(trig)
     s2v = blocks.stream_to_vector(gr.sizeof_float, 2)
     select_vectors = dab.select_vectors(gr.sizeof_float, vlen, len, skip)
     v2s = blocks.vector_to_stream(gr.sizeof_float, 2)
     dst = blocks.vector_sink_f()
     trigdst = blocks.vector_sink_b()
     self.tb.connect(src, s2v, select_vectors, v2s, dst)
     self.tb.connect(trigsrc, (select_vectors, 1), trigdst)
     self.tb.run()
     result_data = dst.data()
     result_trig = trigdst.data()
     # print expected_result
     # print result_data
     self.assertFloatTuplesAlmostEqual(expected_data, result_data)
     self.assertEqual(expected_trig, result_trig)
	def test_002_t (self):
		# set up fg
		in_data = range(20)
		vlen_in = 5
		
		crop_x = (2,4)
		crop_y = (1,4)
		
		src = blocks.vector_source_c(in_data)
		s2v = blocks.stream_to_vector(8,vlen_in)
		s2ts = blocks.stream_to_tagged_stream(8,vlen_in,len(in_data)/vlen_in,'packet_len')
		crop = radar.crop_matrix_vcvc(vlen_in,crop_x,crop_y)
		v2s = blocks.vector_to_stream(8,crop_x[1]-crop_x[0])
		snk = blocks.vector_sink_c()
		debug = blocks.tag_debug(8,'debug')
		
		self.tb.connect(src,s2v,s2ts,crop,v2s,snk)
		self.tb.connect(v2s,debug)
		self.tb.run ()
		# check data
		ref_data = (7,8,12,13,17,18)
		out_data = snk.data()
		print "INDATA:", in_data
		print "REF: ", ref_data
		print "OUTPUT:", out_data
		for k in range(len(out_data)):
			self.assertEqual(out_data[k].real,ref_data[k])
示例#20
0
	def test_001_diff_phasor_vcc(self):
		a = [1+2j,2+3.5j,3.5+4j,4+5j,5+6j]
		b = [1j,1j,1j,1j,1j]
		c = [-1j+3,1j,-7+0j,2.5j+0.333,3.2j]
		d = [(0.35979271051026462+0.89414454782483865j),
		     (0.19421665709046287+0.024219594550527801j),
		     (0.12445564785882557+0.40766238899138718j),
		     (0.041869638845043688+0.97860437393366329j),
		     (0.068927762235083234+0.16649764877365247j)]
		e = [(0.16207552830286298+0.435385030608331j),
		     (0.47195779613669675+0.37824764113272558j),
		     (0.13911998015446148+0.6585095669811617j),
		     (0.093510743358783954+0.98446560079828938j),
		     (0.86036393297704694+0.72043005342024602j)]
		multconj = lambda x,y: x.conjugate()*y
		src_data        = a+b+c+d+e
		expected_result = [0j,0j,0j,0j,0j]+map(multconj,a,b)+map(multconj,b,c)+map(multconj,c,d)+map(multconj,d,e)
		src = blocks.vector_source_c(src_data)
		s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, 5)
		diff_phasor_vcc = grdab.diff_phasor_vcc(5)
		v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, 5)
		dst = blocks.vector_sink_c()
		self.tb.connect(src, s2v, diff_phasor_vcc, v2s, dst)
		self.tb.run()
		result_data = dst.data()
		# print expected_result
		# print result_data
		self.assertComplexTuplesAlmostEqual(expected_result, result_data, 6)
示例#21
0
	def test_003_t (self):
		# test fft against gnuradio fft
		# set up fg
		test_len = 1024*2

		packet_len = test_len
		samp_rate = 2000
		frequency = (100,100)
		amplitude = 1

		src = radar.signal_generator_cw_c(packet_len,samp_rate,frequency,amplitude)
		head = blocks.head(8,test_len)
		tsfft = radar.ts_fft_cc(packet_len)
		snk1 = blocks.vector_sink_c()
		self.tb.connect(src,head,tsfft,snk1)

		s2v = blocks.stream_to_vector(8, packet_len)
		fft_inbuild = fft.fft_vcc(test_len,True,fft.window_rectangular(0))
		snk2 = blocks.vector_sink_c()
		v2s = blocks.vector_to_stream(8, packet_len);
		self.tb.connect(head,s2v,fft_inbuild,v2s,snk2)

		self.tb.run()

		# compaire ffts
		data_tsfft = snk1.data()
		data_fft_inbuild = snk2.data()

		self.assertComplexTuplesAlmostEqual(data_tsfft,data_fft_inbuild,2) # compare inbuild fft and fft from block
示例#22
0
文件: test.py 项目: tjt7a/GR-Router
        def __init__(self, window_size):
            gr.hier_block2.__init__(self, "FFT_IFFT",
                                    gr.io_signature(1, 1, gr.sizeof_float),
                                    gr.io_signature(1, 1, gr.sizeof_float))
            vector_to_stream = blocks.vector_to_stream(gr.sizeof_gr_complex,
                                                       window_size)
            stream_to_vector = blocks.stream_to_vector(gr.sizeof_float,
                                                       window_size)
            divide = blocks.divide_cc(1)
            complex_to_float = blocks.complex_to_float(1)
            fft_forward = fft.fft_vfc(window_size, True,
                                      (fft.window.blackmanharris(window_size)),
                                      1)
            fft_backward = fft.fft_vcc(
                window_size, False, (fft.window.blackmanharris(window_size)),
                False, 1)
            constant = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0,
                                           window_size)

            #print("1. Connect self to stream_to_vector")
            self.connect((self, 0), (stream_to_vector, 0))
            #print("2. Connect stream_to_vector to fft_forward")
            self.connect((stream_to_vector, 0), (fft_forward, 0))
            #print("3. Connect fft_forward to fft_backward")
            self.connect((fft_forward, 0), (fft_backward, 0))
            #print("4. Connect fft_backward to vector_to_stream")
            self.connect((fft_backward, 0), (vector_to_stream, 0))
            #print("5. Connect vector_to_stream to port 0 of divide")
            self.connect((vector_to_stream, 0), (divide, 0))
            #print("6. Connect constant to port 1 of divide")
            self.connect(constant, (divide, 1))
            #print("7. Connect divide to complex_to_float")
            self.connect((divide, 0), (complex_to_float, 0))
            #print("8. Connect complex_to_float to self")
            self.connect((complex_to_float, 0), (self, 0))
示例#23
0
    def test_001_t(self):
        vsize = 1024
        vdecimate = 4
        vin = numpy.zeros(2 * vsize * vdecimate)
        for i in range(vsize):
            vin[i] = float(i)
            vin[vsize + i] = vin[i]
            vin[(vsize * vdecimate) + i] = vin[i]
            vin[(vsize * (vdecimate + 1)) + i] = vin[i]
        # create a set of vectors
        src = blocks.vector_source_f(vin.tolist())
        s2v = blocks.stream_to_vector(gr.sizeof_float, vsize)
        # block we're testing
        vblock = ra_vmedian(vsize, vdecimate)

        v2s = blocks.vector_to_stream(gr.sizeof_float, vsize)
        snk = blocks.vector_sink_f(vsize)

        self.tb.connect(src, s2v)
        self.tb.connect(s2v, vblock)
        self.tb.connect(vblock, snk)
        #        self.tb.connect (v2s, snk)
        expected = vin[0:(2 * vsize)] / 2.
        expected[vsize:] = expected[0:vsize]
        print 'Expected: ', expected[0:7]
        outdata = None
        waittime = 0.01

        self.tb.run()
        outdata = snk.data()
        print 'Output: ', outdata[0:7]
        # check data
        self.assertFloatTuplesAlmostEqual(expected, outdata, 6)
示例#24
0
 def test_001_repartition_vectors(self):
     ilen = 3
     mult = 2
     div = 3
     olen = 2
     src_data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1,
                 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6)
     trig = (0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0)
     expected_data = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2,
                      3, 4, 1, 2, 3, 4, 5, 6)
     expected_trig = (1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)
     src = blocks.vector_source_b(src_data)
     trigsrc = blocks.vector_source_b(trig)
     s2v = blocks.stream_to_vector(gr.sizeof_char, ilen)
     repartition_vectors = grdab.repartition_vectors(
         gr.sizeof_char, ilen, olen, mult, div)
     v2s = blocks.vector_to_stream(gr.sizeof_char, olen)
     dst = blocks.vector_sink_b()
     trigdst = blocks.vector_sink_b()
     self.tb.connect(src, s2v, repartition_vectors, v2s, dst)
     self.tb.connect(trigsrc, (repartition_vectors, 1), trigdst)
     self.tb.run()
     result_data = dst.data()
     result_trig = trigdst.data()
     self.assertEqual(expected_data, result_data)
     self.assertEqual(expected_trig, result_trig)
    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 test_001_t (self):
        # set up fg
        test_len = 1000
        fft_len = 100;
        cp_len = fft_len/4
        
        in_data = range(0,fft_len)*(test_len/fft_len);
        
        src = blocks.vector_source_c(in_data)
        s2v = blocks.stream_to_vector(8,fft_len)
        s2ts = blocks.stream_to_tagged_stream(8,fft_len,test_len/fft_len,'packet_len')
        cp_add = digital.ofdm_cyclic_prefixer(fft_len,fft_len+cp_len,0,'packet_len')
        cp_remove = radar.ofdm_cyclic_prefix_remover_cvc(fft_len,cp_len,'packet_len')
        v2s = blocks.vector_to_stream(8,fft_len)
        snk = blocks.vector_sink_c()
        
        self.tb.connect(src,s2v,s2ts,cp_add,cp_remove,v2s,snk)
        self.tb.run ()
        
        # check data
        out_data = snk.data()
        out_data_real = [0]*len(out_data)
        for k in range(len(out_data)):
			out_data_real[k] = out_data[k].real
        
        for k in range(len(in_data)):
			self.assertEqual(in_data[k],out_data_real[k])
示例#27
0
    def test_reverse_window_shift(self):
        src_data = tuple([x / self.fft_size for x in primes_transformed])
        expected_result = (
            (-74.8629 - 63.2502j), (-3.5446 - 2.0365j), (2.9231 + 1.6827j),
            (-2.7852 - 0.8613j), (2.4763 + 2.7881j), (-2.7457 - 3.2602j),
            (4.7748 + 2.4145j), (-2.8807 - 4.5313j), (5.9949 + 4.1976j),
            (-6.1095 - 6.0681j), (5.2248 + 5.7743j), (-6.0436 - 6.3773j),
            (9.7184 + 9.2482j), (-8.2791 - 8.6507j), (6.3273 + 6.1560j),
            (-12.2841 - 12.4692j), (10.5816 + 10.0241j), (-13.0312 - 11.9451j),
            (12.2983 + 13.3644j), (-13.0372 - 14.0795j), (14.4682 + 13.3079j),
            (-16.7673 - 16.7287j), (14.3946 + 11.5916j), (-16.8368 - 21.3156j),
            (20.4528 + 16.8499j), (-18.4075 - 18.2446j), (17.7507 + 19.2109j),
            (-21.5207 - 20.7159j), (22.2183 + 19.8012j), (-22.2144 - 20.0343j),
            (17.0359 + 17.6910j), (-91.8955 - 103.1093j))
        window = fft.window.hamming(ntaps=self.fft_size)

        src = blocks.vector_source_c(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
        op = fft.fft_vcc(self.fft_size, False, window, True)
        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, self.fft_size)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, s2v, op, v2s, dst)
        self.tb.run()
        result_data = dst.data()
        self.assert_fft_ok2(expected_result, result_data)
示例#28
0
    def test_001_t(self):
        # set up fg
        #test_input =\
        #		(1+1j,2+2j,3+3j,4+4j,2-2j,3-3j,4-4j,5-5j,3+3j,4+4j,5+5j,6+6j,\
        #		4-4j,5-5j,6-6j,7-7j,5+5j,6+6j,7+7j,8+8j);
        test_input =\
          (1+1j,2+2j,3+3j,4+4j,2-2j,3-3j,4-4j,5-5j,3+3j,4+4j,5+5j,6+6j,\
          4-4j,5-5j,6-6j,7-7j)
        test_output = (5.0, 13.0, 25.0, 41.0, 25.0, 41.0, 61.0, 85.0)
        test_output1 = (2, 2, 2, 2)
        # set up fg
        vector_input = blocks.vector_source_c(test_input)
        s_to_v = blocks.stream_to_vector(gr.sizeof_gr_complex, 4)
        #s_to_v_1 = blocks.stream_to_vector(gr.sizeof_float,9);

        summing = stream_avg_all.stream_avg_cc(2, 4)
        v_to_s = blocks.vector_to_stream(gr.sizeof_float, 4)
        dest = blocks.vector_sink_f(1)

        self.tb.connect(vector_input, s_to_v)
        #self.tb.connect(s_to_v,dest);
        self.tb.connect(s_to_v, summing)
        self.tb.connect(summing, v_to_s)
        #self.tb.connect(v_to_s_1,v_to_s);
        self.tb.connect(v_to_s, dest)
        self.tb.run()
        #print dest.data();
        #print dest_1.data();

        self.assertEqual(test_output, dest.data())
        self.tb.run()
示例#29
0
def ms_to_file(hb,block,filename,N=4096,delay=0,fft=False,scale=1):
  streamsize = determine_streamsize(block)
  vlen = streamsize/gr.sizeof_gr_complex

  blks = [block]

  if fft and vlen > 1:
    gr_fft = fft_blocks.fft_vcc(vlen,True,[],True)
    blks.append(gr_fft)

  mag_sqrd = gr.complex_to_mag_squared(vlen)
  blks.append(mag_sqrd)

  if vlen > 1:
    v2s = blocks.vector_to_stream(gr.sizeof_float,vlen)
    blks.append(v2s)

  if delay != 0:
    delayline = delayline_ff(delay)
    blks.append(delayline)

  gr_scale = gr.multiply_const_ff(scale)
  blks.append(gr_scale)

  filter = gr.fir_filter_fff(1,[1.0/N]*N)
  blks.append(filter)

  for i in range(len(blks)-1):
    hb.connect(blks[i],blks[i+1])

  log_to_file(hb,filter,filename)
示例#30
0
def ofdm_mapper(bits_per_channel, bitdata):
  bits = sum(bits_per_channel)
  vlen = len(bits_per_channel)
  ofdm_blocks = len( bitdata ) / bits
  
  assert( ( len( bitdata ) % bits ) == 0 )

  cv_src = blocks.vector_source_b(bits_per_channel,True,vlen)
  data_src = blocks.vector_source_b(bitdata)
  trigger = [0]*ofdm_blocks
  trigger[0] = 1
  trigger = blocks.vector_source_b( trigger )
  mapper = ofdm.generic_mapper_bcv(vlen)
  v2s = blocks.vector_to_stream(gr.sizeof_gr_complex,vlen)
  dst = blocks.vector_sink_c()

  fg = gr.top_block()

  fg.connect(data_src, (mapper,0))
  fg.connect(cv_src,(mapper,1))
  fg.connect( trigger, ( mapper, 2 ) )
  fg.connect(mapper,v2s,dst)
  fg.run()

  ofdm_symbol = dst.data()
  return ofdm_symbol
示例#31
0
def ofdm_mapper(bits_per_channel, bitdata):
    bits = sum(bits_per_channel)
    vlen = len(bits_per_channel)
    ofdm_blocks = len(bitdata) / bits

    assert ((len(bitdata) % bits) == 0)

    cv_src = blocks.vector_source_b(bits_per_channel, True, vlen)
    data_src = blocks.vector_source_b(bitdata)
    trigger = [0] * ofdm_blocks
    trigger[0] = 1
    trigger = blocks.vector_source_b(trigger)
    mapper = ofdm.generic_mapper_bcv(vlen)
    v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, vlen)
    dst = blocks.vector_sink_c()

    fg = gr.top_block()

    fg.connect(data_src, (mapper, 0))
    fg.connect(cv_src, (mapper, 1))
    fg.connect(trigger, (mapper, 2))
    fg.connect(mapper, v2s, dst)
    fg.run()

    ofdm_symbol = dst.data()
    return ofdm_symbol
  def BuildFFT(self,scope=True):
    fft0w = filter.window.blackmanharris(2048)
    fft0 = fft.fft_vcc(2048, True, fft0w, True)

    fft1w = filter.window.blackmanharris(2048)
    fft1 = fft.fft_vcc(2048, True, fft1w, True)

    self.connect(self.rx0,blocks.stream_to_vector(gr.sizeof_gr_complex, 2048),fft0)
    self.connect(self.rx1,blocks.stream_to_vector(gr.sizeof_gr_complex, 2048),fft1)

    v2s = blocks.vector_to_stream(gr.sizeof_float,20)

    fp2 = findphase_c(2048)
    self.connect(fft0,(fp2,0))
    self.connect(fft1,(fp2,1))
    self.connect(fp2,v2s)

    if scope:
      self.ffth = qtgui.histogram_sink_f(100,360,-179,180,"FFT Phase Histogram")
      #self.ffth.enable_autoscale(False)
      self.ffth.enable_accumulate(True)
      self.ffth.enable_grid(True)
      #self.histo.enable_menu(True)
      self.connect(v2s,self.ffth)

      self.ffthqt = sip.wrapinstance(self.ffth.pyqwidget(), QtGui.QWidget)
      self.ffthqt.show()
示例#33
0
    def test_001_t(self):
        for exponent in range(1, 10):
            in_data = (1 + 1j, -1, 4 - 1j, -3 - 7j)
            out_data = (in_data[0]**exponent, in_data[1]**exponent,
                        in_data[2]**exponent, in_data[3]**exponent)

            # Test streaming input
            source = blocks.vector_source_c(in_data, False, 1)
            exponentiate_const_cci = blocks.exponentiate_const_cci(exponent)
            sink = blocks.vector_sink_c(1)

            self.tb.connect(source, exponentiate_const_cci, sink)
            self.tb.run()

            self.assertAlmostEqual(sink.data(), out_data)

            # Test vector input
            for vlen in [2, 4]:
                source = blocks.vector_source_c(in_data, False, 1)
                s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen)
                exponentiate_const_cci = blocks.exponentiate_const_cci(
                    exponent, vlen)
                v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, vlen)
                sink = blocks.vector_sink_c(1)

                self.tb.connect(source, s2v, exponentiate_const_cci, v2s, sink)
                self.tb.run()

                self.assertAlmostEqual(sink.data(), out_data)
示例#34
0
def ms_to_file(hb, block, filename, N=4096, delay=0, fft=False, scale=1):
    streamsize = determine_streamsize(block)
    vlen = streamsize / gr.sizeof_gr_complex

    blks = [block]

    if fft and vlen > 1:
        gr_fft = fft_blocks.fft_vcc(vlen, True, [], True)
        blks.append(gr_fft)

    mag_sqrd = gr.complex_to_mag_squared(vlen)
    blks.append(mag_sqrd)

    if vlen > 1:
        v2s = blocks.vector_to_stream(gr.sizeof_float, vlen)
        blks.append(v2s)

    if delay != 0:
        delayline = delayline_ff(delay)
        blks.append(delayline)

    gr_scale = gr.multiply_const_ff(scale)
    blks.append(gr_scale)

    filter = gr.fir_filter_fff(1, [1.0 / N] * N)
    blks.append(filter)

    for i in range(len(blks) - 1):
        hb.connect(blks[i], blks[i + 1])

    log_to_file(hb, filter, filename)
示例#35
0
		def __init__(self, window_size):
			gr.hier_block2.__init__(self, "FFT_IFFT", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float))
			vector_to_stream = blocks.vector_to_stream(gr.sizeof_gr_complex, window_size)
			stream_to_vector = blocks.stream_to_vector(gr.sizeof_float, window_size)
			divide = blocks.divide_cc(1)
			complex_to_float = blocks.complex_to_float(1)
			fft_forward = fft.fft_vfc(window_size, True, (fft.window.blackmanharris(window_size)), 1)
			fft_backward = fft.fft_vcc(window_size, False, (fft.window.blackmanharris(window_size)), False, 1)
			constant = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, window_size)

			#print("1. Connect self to stream_to_vector")
			self.connect((self, 0), (stream_to_vector, 0))
			#print("2. Connect stream_to_vector to fft_forward")
			self.connect((stream_to_vector, 0), (fft_forward, 0))
			#print("3. Connect fft_forward to fft_backward")
			self.connect((fft_forward, 0), (fft_backward, 0))
			#print("4. Connect fft_backward to vector_to_stream")
			self.connect((fft_backward, 0), (vector_to_stream, 0))
			#print("5. Connect vector_to_stream to port 0 of divide")
			self.connect((vector_to_stream, 0), (divide, 0))
			#print("6. Connect constant to port 1 of divide")
			self.connect(constant, (divide, 1))
			#print("7. Connect divide to complex_to_float")
			self.connect((divide, 0), (complex_to_float, 0))
			#print("8. Connect complex_to_float to self")
			self.connect((complex_to_float, 0), (self, 0))
示例#36
0
    def test_003_t(self):
        # test fft against gnuradio fft
        # set up fg
        test_len = 1024 * 2

        packet_len = test_len
        samp_rate = 2000
        frequency = (100, 100)
        amplitude = 1

        src = radar.signal_generator_cw_c(packet_len, samp_rate, frequency,
                                          amplitude)
        head = blocks.head(8, test_len)
        tsfft = radar.ts_fft_cc(packet_len)
        snk1 = blocks.vector_sink_c()
        self.tb.connect(src, head, tsfft, snk1)

        s2v = blocks.stream_to_vector(8, packet_len)
        fft_inbuild = fft.fft_vcc(test_len, 1, fft.window_rectangular(0))
        snk2 = blocks.vector_sink_c()
        v2s = blocks.vector_to_stream(8, packet_len)
        self.tb.connect(head, s2v, fft_inbuild, v2s, snk2)

        self.tb.run()

        # compaire ffts
        data_tsfft = snk1.data()
        data_fft_inbuild = snk2.data()

        self.assertComplexTuplesAlmostEqual(
            data_tsfft, data_fft_inbuild,
            2)  # compare inbuild fft and fft from block
示例#37
0
    def test_window(self):
        src_data = tuple([
            complex(primes[2 * i], primes[2 * i + 1])
            for i in range(self.fft_size)
        ])
        expected_result = (
            (2238.9174 + 2310.4750j), (-1603.7416 - 466.7420j),
            (116.7449 - 70.8553j), (-13.9157 + 19.0855j), (-4.8283 + 16.7025j),
            (-43.7425 + 16.9871j), (-16.1904 + 1.7494j), (-32.3797 + 6.9964j),
            (-13.5283 + 7.7721j), (-24.3276 - 7.5378j), (-29.2711 + 4.5709j),
            (-2.7124 - 6.6307j), (-33.5486 - 8.3485j), (-8.3016 - 9.9534j),
            (-18.8590 - 8.3501j), (-13.9092 - 1.1396j), (-17.7626 - 26.9281j),
            (0.0182 - 8.9000j), (-19.9143 - 14.1320j), (-10.3073 - 15.5759j),
            (3.5800 - 29.1835j), (-7.5263 - 1.5900j), (-3.0392 - 31.7445j),
            (-15.1355 - 33.6158j), (28.2345 - 11.4373j), (-6.0055 - 27.0418j),
            (5.2074 - 21.2431j), (23.1617 - 31.8610j), (13.6494 - 11.1982j),
            (14.7145 - 14.4113j), (-60.0053 + 114.7418j), (-440.1561 -
                                                           1632.9807j))
        window = fft.window.hamming(ntaps=self.fft_size)

        src = blocks.vector_source_c(src_data)
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
        op = fft.fft_vcc(self.fft_size, True, window, False)
        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, self.fft_size)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, s2v, op, v2s, dst)
        self.tb.run()
        result_data = dst.data()
        self.assert_fft_ok2(expected_result, result_data)
示例#38
0
    def test_001_t(self):
        # set up fg
        test_len = 1000
        fft_len = 100
        cp_len = fft_len / 4

        in_data = list(range(0, fft_len)) * (test_len // fft_len)

        src = blocks.vector_source_c(in_data)
        s2v = blocks.stream_to_vector(8, fft_len)
        s2ts = blocks.stream_to_tagged_stream(8, fft_len, test_len / fft_len,
                                              'packet_len')
        cp_add = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 0,
                                              'packet_len')
        cp_remove = radar.ofdm_cyclic_prefix_remover_cvc(
            fft_len, cp_len, 'packet_len')
        v2s = blocks.vector_to_stream(8, fft_len)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, s2v, s2ts, cp_add, cp_remove, v2s, snk)
        self.tb.run()

        # check data
        out_data = snk.data()
        out_data_real = [0] * len(out_data)
        for k in range(len(out_data)):
            out_data_real[k] = out_data[k].real

        for k in range(len(in_data)):
            self.assertEqual(in_data[k], out_data_real[k])
	def test_001_ofdm_coarse_frequency_correct(self):
		fft_length   = 10
		num_carriers = 2
		cp_length    = 3
		src_data0        = [0,1,2,3,4,5,6,7,8,9,1,2,0,5,7,6,0,4,0,6,1,1,1,0.8,0.1,1.3,1,0.7,1,1,0,1,2,3,4,5,6,7,8,9]
		expected_result0 = [7,9,5,6,0.8,1.3,3,5]
		offset           = [3,3,-1,-1,-1,-1,-1,-1]
		frame_index      = [0,0, 0, 0, 0, 0, 1, 1]
		expected_result0 = [complex(expected_result0[i])*cmath.exp(-2j*cmath.pi*offset[i]*cp_length/float(fft_length)*frame_index[i]) for i in range(0,8)]
		src_data1 = [1,1,1,0]
		expected_result1 = (1,1,1,0)
		src0 = blocks.vector_source_c(src_data0)
		src1 = blocks.vector_source_b(src_data1)
		s2v0 = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)
		ofdm_coarse_frequency_correct = grdab.ofdm_coarse_frequency_correct(fft_length,num_carriers,cp_length)
		v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex, num_carriers)
		dst0 = blocks.vector_sink_c()
		dst1 = blocks.vector_sink_b()
		self.tb.connect(src0, s2v0, (ofdm_coarse_frequency_correct,0))
		self.tb.connect(src1, (ofdm_coarse_frequency_correct,1))
		self.tb.connect((ofdm_coarse_frequency_correct,0), v2s0, dst0)
		self.tb.connect((ofdm_coarse_frequency_correct,1), dst1)
		self.tb.run()
		result_data0 = dst0.data()
		result_data1 = dst1.data()
		# print expected_result0
		# print result_data0
		self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 4)
		self.assertEqual(result_data1, expected_result1)
	def test_001_t (self):
		# set up fg
		# check samples on output
		test_len = 12
		in_data = range(test_len)
		vlen_in = 3
		vlen_out = 4
		
		src = blocks.vector_source_c(in_data)
		stv = blocks.stream_to_vector(8,vlen_in)
		s2ts = blocks.stream_to_tagged_stream(8,vlen_in,test_len/vlen_in,'packet_len')
		transpose = radar.transpose_matrix_vcvc(vlen_in,vlen_out,'packet_len')
		vts = blocks.vector_to_stream(8,vlen_out)
		snk = blocks.vector_sink_c()
		
		self.tb.connect(src,stv,s2ts,transpose,vts,snk)
		self.tb.run()
		
		# check data
		out_data = snk.data()
		ref_data = [0]*len(in_data)
		counter = 0;
		for k in range(vlen_in):
			for l in range(test_len/vlen_in):
				ref_data[counter] = in_data[l*vlen_in+k]
				counter = counter+1
			
		out_data_real = [0]*len(in_data)
		for k in range(len(in_data)):
			out_data_real[k] = out_data[k].real
				
		for k in range(len(out_data_real)):
			self.assertEqual(out_data_real[k],ref_data[k])
	def test_002_ofdm_remove_first_symbol_vcc(self):
		src_data0        = (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7)
		src_data1        = (1,0,0,1,0,0)
		expected_result0 = (3,4,5,6,7,8,2,3,4,5,6,7)
		expected_result0 = [x+0j for x in expected_result0]
		expected_result1 = (1,0,1,0)
		src0 = blocks.vector_source_c(src_data0)
		src1 = blocks.vector_source_b(src_data1)
		s2v0 = blocks.stream_to_vector(gr.sizeof_gr_complex,3)
		ofdm_remove_first_symbol = grdab.ofdm_remove_first_symbol_vcc(3)
		v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex,3)
		dst0 = blocks.vector_sink_c()
		dst1 = blocks.vector_sink_b()
		self.tb.connect(src0, s2v0, (ofdm_remove_first_symbol,0))
		self.tb.connect(src1, (ofdm_remove_first_symbol,1))
		self.tb.connect((ofdm_remove_first_symbol,0), v2s0, dst0)
		self.tb.connect((ofdm_remove_first_symbol,1), dst1)
		self.tb.run()
		result_data0 = dst0.data()
		result_data1 = dst1.data()
		# print src_data0
		# print expected_result0
		# print result_data0
		self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 6)
		self.assertEqual(result_data1, expected_result1)
示例#42
0
    def test_multithreaded(self):
        nthreads = nthreads_min
        while nthreads < nthreads_max:
            fft_size_pow = fft_size_pow_min
            while fft_size_pow < fft_size_pow_max:
                self.fft_size = 2**fft_size_pow
                print "fft_size:\t%d" % self.fft_size
                print "nthreads:\t%d" % nthreads
                src_data = tuple(
                    [x / self.fft_size for x in primes_transformed])
                #expected_result = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)])

                src = blocks.vector_source_c(src_data)
                s2v = blocks.stream_to_vector(gr.sizeof_gr_complex,
                                              self.fft_size)
                op = fft.fft_vcc(self.fft_size, True, [], False, nthreads)
                v2s = blocks.vector_to_stream(gr.sizeof_gr_complex,
                                              self.fft_size)
                dst = blocks.vector_sink_c()
                self.tb.connect(src, s2v, op, v2s, dst)
                start = time.time()
                self.tb.run()
                end = time.time()
                totaltime = end - start
                print "execTime: %6.6f" % totaltime
                #print(op.pc_work_time())
                # print(op.pc_noutput_items_var())
                result_data = dst.data()
                #self.assert_fft_ok2(expected_result, result_data)
                fft_size_pow = fft_size_pow + 1
            nthreads = nthreads + 1
	def test_002_t (self):
		# set up fg
		in_data = range(20)
		vlen_in = 5

		crop_x = (2,4)
		crop_y = (1,4)

		src = blocks.vector_source_c(in_data)
		s2v = blocks.stream_to_vector(8,vlen_in)
		s2ts = blocks.stream_to_tagged_stream(8,vlen_in,len(in_data)/vlen_in,'packet_len')
		crop = radar.crop_matrix_vcvc(vlen_in,crop_x,crop_y)
		v2s = blocks.vector_to_stream(8,crop_x[1]-crop_x[0])
		snk = blocks.vector_sink_c()
		debug = blocks.tag_debug(8,'debug')

		self.tb.connect(src,s2v,s2ts,crop,v2s,snk)
		self.tb.connect(v2s,debug)
		self.tb.run ()
		# check data
		ref_data = (7,8,12,13,17,18)
		out_data = snk.data()
		print("INDATA:", in_data)
		print("REF: ", ref_data)
		print("OUTPUT:", out_data)
		for k in range(len(out_data)):
			self.assertEqual(out_data[k].real,ref_data[k])
示例#44
0
    def __init__(self,
                 block_size,
                 one_in,
                 item_size=gr.sizeof_gr_complex,
                 vector_output=False):

        logger.info('%s will reduce stream to %3.0f%%.' %
                    (self.__class__.__name__, 100.0 / one_in))

        out_sig_item_size = item_size * (block_size if vector_output else 1)

        gr.hier_block2.__init__(self, self.__class__.__name__,
                                gr.io_signature(1, 1, item_size),
                                gr.io_signature(1, 1, out_sig_item_size))

        self.s2v = blocks.stream_to_vector(item_size, block_size)
        self.keeper = blocks.keep_one_in_n(item_size * block_size, one_in)

        self.connect(self, self.s2v, self.keeper)

        if vector_output:
            self.connect(self.keeper, self)
        else:
            self.v2s = blocks.vector_to_stream(item_size, block_size)
            self.connect(self.keeper, self.v2s, self)
示例#45
0
 def test_001_diff_phasor_vcc(self):
     a = [1 + 2j, 2 + 3.5j, 3.5 + 4j, 4 + 5j, 5 + 6j]
     b = [1j, 1j, 1j, 1j, 1j]
     c = [-1j + 3, 1j, -7 + 0j, 2.5j + 0.333, 3.2j]
     d = [(0.35979271051026462 + 0.89414454782483865j),
          (0.19421665709046287 + 0.024219594550527801j),
          (0.12445564785882557 + 0.40766238899138718j),
          (0.041869638845043688 + 0.97860437393366329j),
          (0.068927762235083234 + 0.16649764877365247j)]
     e = [(0.16207552830286298 + 0.435385030608331j),
          (0.47195779613669675 + 0.37824764113272558j),
          (0.13911998015446148 + 0.6585095669811617j),
          (0.093510743358783954 + 0.98446560079828938j),
          (0.86036393297704694 + 0.72043005342024602j)]
     multconj = lambda x, y: x.conjugate() * y
     src_data = a + b + c + d + e
     expected_result = [0j, 0j, 0j, 0j, 0j] + map(multconj, a, b) + map(
         multconj, b, c) + map(multconj, c, d) + map(multconj, d, e)
     src = blocks.vector_source_c(src_data)
     s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, 5)
     diff_phasor_vcc = dab.diff_phasor_vcc(5)
     v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, 5)
     dst = blocks.vector_sink_c()
     self.tb.connect(src, s2v, diff_phasor_vcc, v2s, dst)
     self.tb.run()
     result_data = dst.data()
     # print expected_result
     # print result_data
     self.assertComplexTuplesAlmostEqual(expected_result, result_data, 6)
示例#46
0
    def __init__(self, size, factor, itemsize=gr.sizeof_gr_complex):
        """
        size: (int) vector size (FFT size) of next block
        factor: (int) output will have this many more samples than input
        
        If size is not divisible by factor, then the output will necessarily have jitter.
        """
        size = int(size)
        factor = int(factor)
        # assert size % factor == 0
        offset = size // factor

        gr.hier_block2.__init__(
            self, type(self).__name__,
            gr.io_signature(1, 1, itemsize),
            gr.io_signature(1, 1, itemsize),
        )
        
        if factor == 1:
            # No duplication needed; simplify flowgraph
            # GR refused to connect self to self, so insert a dummy block
            self.connect(self, blocks.copy(itemsize), self)
        else:
            interleave = blocks.interleave(itemsize * size)
            self.connect(
                interleave,
                blocks.vector_to_stream(itemsize, size),
                self)
        
            for i in xrange(0, factor):
                self.connect(
                    self,
                    blocks.delay(itemsize, (factor - 1 - i) * offset),
                    blocks.stream_to_vector(itemsize, size),
                    (interleave, i))
示例#47
0
 def test_002_ofdm_remove_first_symbol_vcc(self):
     src_data0 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7)
     src_data1 = (1, 0, 0, 1, 0, 0)
     expected_result0 = (3, 4, 5, 6, 7, 8, 2, 3, 4, 5, 6, 7)
     expected_result0 = [x + 0j for x in expected_result0]
     expected_result1 = (1, 0, 1, 0)
     src0 = blocks.vector_source_c(src_data0)
     src1 = blocks.vector_source_b(src_data1)
     s2v0 = blocks.stream_to_vector(gr.sizeof_gr_complex, 3)
     ofdm_remove_first_symbol = dab.ofdm_remove_first_symbol_vcc(3)
     v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex, 3)
     dst0 = blocks.vector_sink_c()
     dst1 = blocks.vector_sink_b()
     self.tb.connect(src0, s2v0, (ofdm_remove_first_symbol, 0))
     self.tb.connect(src1, (ofdm_remove_first_symbol, 1))
     self.tb.connect((ofdm_remove_first_symbol, 0), v2s0, dst0)
     self.tb.connect((ofdm_remove_first_symbol, 1), dst1)
     self.tb.run()
     result_data0 = dst0.data()
     result_data1 = dst1.data()
     # print src_data0
     # print expected_result0
     # print result_data0
     self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 6)
     self.assertEqual(result_data1, expected_result1)
示例#48
0
    def __init__(self, fname, epsilon, max_iterations):
        gr.top_block.__init__(self)

        self.src = blocks.vector_source_b(())
#        self.encoder = ldpc.ldpc_encoder_bf(fname)
#        self.decoder = ldpc.ldpc_decoder_fb(fname, epsilon, max_iterations)
#        self.encoder = ldpc.ldpc_encoder_bb(fname)
#        self.decoder = ldpc.ldpc_decoder_bb(fname, epsilon, max_iterations)
#        self.K = self.encoder.get_K()
#        self.N = self.encoder.get_N()
        self.K = 100
        self.N = 100
        print self.K
        print self.N
        copy = ldpc.copy_bb(self.K)
        self.dst = blocks.vector_sink_b()
        fsink1 = blocks.file_sink(gr.sizeof_char*self.K, "in")
        fsink1.set_unbuffered(False)
        fsink2 = blocks.file_sink(gr.sizeof_char*self.K, "out")
        fsink2.set_unbuffered(False)
#        fsink3 = blocks.file_sink(gr.sizeof_float*1, "encout")
#        fsink3.set_unbuffered(False)
        fsink3 = blocks.file_sink(gr.sizeof_char*self.N, "encout")
        fsink3.set_unbuffered(False)

        inFile = "/home/manu/Downloads/in.flac"
        outFile = "/home/manu/out.flac"
        source = blocks.file_source(gr.sizeof_char*self.K, inFile, False)
        sink = blocks.file_sink(gr.sizeof_char*self.K, outFile)
        unpack2pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        pack2unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        rsource= blocks.vector_source_b(map(int, np.random.randint(0x00, 0x02, 1000)), True)


#        str2Kvec = blocks.stream_to_vector(1, self.K)
#        str2Nvec = blocks.stream_to_vector(4, self.N)
#        Kvec2str = blocks.vector_to_stream(1, self.K)
#        Nvec2str = blocks.vector_to_stream(4, self.N)
        str2Kvec = blocks.stream_to_vector(1, self.K)
        str2Nvec = blocks.stream_to_vector(1, self.N)
        Kvec2str = blocks.vector_to_stream(1, self.K)
        Nvec2str = blocks.vector_to_stream(1, self.N)

        self.noise = analog.noise_source_f(analog.GR_GAUSSIAN, epsilon, 0)
        self.adder = blocks.add_vff(1)

        self.connect(source, copy, sink)
示例#49
0
    def __init__(self, update_period=32, window=1024, step_size=0.001, num_ports=2):
        gr.hier_block2.__init__(
            self, "Phase Align",
            gr.io_signaturev(num_ports, num_ports, gen_sig_io(num_ports)),
            gr.io_signaturev(num_ports, num_ports, gen_sig_io(num_ports)),
        )
        self.message_port_register_hier_in("Trigger")

        ##################################################
        # Parameters
        ##################################################
        self.update_period = update_period
        self.window = window
        self.step_size = step_size
        self.num_ports = num_ports

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

        ##################################################
        # Blocks
        ##################################################

        # Const block for reference signal to do nothing
        self.blocks_add_const_vxx_0 = blocks.add_const_vcc((0, ))
        self.connect((self, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self, 0))

        for p in range(num_ports-1):
            # Create PC object
            object_name_pc = 'wifius_phase_correct_vci_'+str(p)
            setattr(self, object_name_pc, wifius.phase_correct_vci(1024, samp_rate, window, step_size, update_period, False))

            # Add Stream To Vector For Ref
            object_name_vr = 'blocks_stream_to_vector_a_'+str(p)
            setattr(self, object_name_vr, blocks.stream_to_vector(gr.sizeof_gr_complex*1, window))

            # Add Stream To Vector For Next Signal
            object_name_sv = 'blocks_stream_to_vector_b_'+str(p)
            setattr(self, object_name_sv, blocks.stream_to_vector(gr.sizeof_gr_complex*1, window))

            # Add Vector To Stream For Output of PC
            object_name_vs = 'blocks_vector_to_stream_'+str(p)
            setattr(self, object_name_vs, blocks.vector_to_stream(gr.sizeof_gr_complex*1, window))

            # Make Connections
            self.connect((self, 0),   (getattr(self,object_name_vr), 0))
            self.connect((self, p+1), (getattr(self,object_name_sv), 0))

            self.connect((getattr(self,object_name_vr), 0), (getattr(self,object_name_pc), 0))
            self.connect((getattr(self,object_name_sv), 0), (getattr(self,object_name_pc), 1))

            self.connect((getattr(self,object_name_pc), 0), (getattr(self,object_name_vs), 0))

            self.connect((getattr(self,object_name_vs), 0), (self, p+1))

            self.msg_connect((self, 'Trigger'), (getattr(self,object_name_pc), 'set_enable_sync'))
示例#50
0
 def entropy_joint(self, src_vector0, src_vector1, expected_entropy, window):
   src0 = blocks.vector_source_b(src_vector0)
   src1 = blocks.vector_source_b(src_vector1)
   v2s0 = blocks.vector_to_stream(gr.sizeof_char, 1)
   v2s1 = blocks.vector_to_stream(gr.sizeof_char, 1)
   entropy = qitkat.entropy_bf(window)
   data = blocks.vector_sink_f()
   self.tb.connect(src0, v2s0)
   self.tb.connect(v2s0, (entropy, 0))
   self.tb.connect(src1, v2s1)
   self.tb.connect(v2s1, (entropy, 1))
   self.tb.connect(entropy, data)
   self.tb.run()
   obs = data.data()
   exp = expected_entropy
   for i in range(len(obs)):
     self.assertAlmostEqual(exp,round(obs[i], self.rounddigits), self.precision)
示例#51
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        port    = int(args[0])
        outfile = None
    elif nargs == 2:
        port    = int(args[0])
        outfile  = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py port [output_file]\n");
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    tx_gain = 83 # max 89.5

    tb = gr.top_block()

    out = uhd.usrp_sink(
        	device_addr="recv_frame_size=65536,num_recv_frames=128,send_frame_size=65536,num_send_frames=128,master_clock_rate=" + str(symbol_rate*4),
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		otw_format="sc16",
        		channels=range(1),
        	),
        )
    out.set_samp_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_gain(tx_gain, 0)

    #src = blocks.udp_source(gr.sizeof_char*1, "127.0.0.1", port, 18800, True)
    src = grc_blks2.tcp_source(gr.sizeof_char*1, "127.0.0.1", port, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc = filter.fft_filter_ccc(1, firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate/2, 0.1152, 100))

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
示例#52
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)
	def test_002_t (self):
		#print "TEST: discarded carriers and num sync words"
		# set up fg
		test_len = 200
		vlen = 20
		ts_len = test_len/vlen
		
		discarded_carriers = (-8,-4,-2,1,2,3,9)
		num_sync_words = 2
		
		in_data0 = [0]*test_len
		in_data1 = [0]*test_len
		for k in range(test_len):
			in_data0[k] = complex(k-4, k+1)
			in_data1[k] = complex(k+3, k-2)
			
		src0 = blocks.vector_source_c(in_data0)
		s2v0 = blocks.stream_to_vector(8,vlen)
		s2ts0 = blocks.stream_to_tagged_stream(8,vlen,ts_len,'packet_len')
		src1 = blocks.vector_source_c(in_data1)
		s2v1 = blocks.stream_to_vector(8,vlen)
		s2ts1 = blocks.stream_to_tagged_stream(8,vlen,ts_len,'packet_len')
		div = radar.ofdm_divide_vcvc(vlen,vlen,discarded_carriers,num_sync_words)
		v2s = blocks.vector_to_stream(8,vlen)
		snk = blocks.vector_sink_c()
		
		self.tb.connect(src0,s2v0,s2ts0)
		self.tb.connect(src1,s2v1,s2ts1)
		self.tb.connect((s2ts0,0),(div,0))
		self.tb.connect((s2ts1,0),(div,1))
		self.tb.connect(div,v2s,snk)
		
		self.tb.run ()
		
		# get ref data
		discarded_carriers_shift = [0]*len(discarded_carriers)
		for k in range(len(discarded_carriers)):
			discarded_carriers_shift[k] = discarded_carriers[k] + vlen/2
		ref_data = [0]*test_len
		for k in range(test_len/vlen):
			for l in range(vlen):
				if k < num_sync_words: # do not process sync words with discarded carriers
					ref_data[vlen*k+l] = in_data0[vlen*k+l]/in_data1[vlen*k+l]
				else: # process discarded carriers
					if l in discarded_carriers_shift: # if actual item shall be discarded
						ref_data[vlen*k+l] = 0
					else: # if actual item shall NOT be discarded
						ref_data[vlen*k+l] = in_data0[vlen*k+l]/in_data1[vlen*k+l]
		
		# check data
		#print "REF"
		#print ref_data
		out_data =  snk.data()
		#print "DATA"
		#print out_data
		for k in range(len(out_data)):
			self.assertAlmostEqual(ref_data[k], out_data[k],4)
 def test_002_t(self):
     self.tb2 = gr.top_block()
     N_rb_dl = 50
     phich_dur = 0
     phich_res = 1.0
     N_ant = 2
     data = []
     test_len = 100
     my_res = []
     for i in range(test_len):
         mib = lte_test.pack_mib(N_rb_dl, phich_dur, phich_res, i)
         crc = lte_test.crc_checksum(mib, N_ant)
         conv = lte_test.convolutional_encoder_sorted(crc)
         convit = lte_test.convolutional_encoder(crc)
         my_res.extend(lte_test.nrz_encoding(convit) )
         rated = lte_test.rate_match(conv)
         nrz = lte_test.nrz_encoding(rated)
         data.extend(nrz)
     
     srcf = blocks.vector_source_f(data, False, 120)
     snkf = blocks.file_sink(gr.sizeof_float*120, "/home/johannes/tests/rated.dat")
     self.tb2.connect(srcf, snkf)
     
     src1 = blocks.vector_source_f(data, False, 120)
             
     vts0 = blocks.vector_to_stream(40*gr.sizeof_float, 3)
     sts0 = blocks.stream_to_streams(40*gr.sizeof_float, 3)        
     self.tb2.connect(src1, vts0, sts0)
     
     
     inter = blocks.interleave(gr.sizeof_float)
     for i in range(3):
         deint = lte.subblock_deinterleaver_vfvf(40, 1)
         vts1 = blocks.vector_to_stream(1*gr.sizeof_float, 40)
         self.tb2.connect( (sts0, i), deint, vts1, (inter, i))
     stv = blocks.stream_to_vector(1*gr.sizeof_float, 120)
     snk = blocks.vector_sink_f(120)        
     self.tb2.connect(inter, stv, snk)
     
     self.tb2.run()
     res = snk.data()
     print res[110:130]
     
     self.assertFloatTuplesAlmostEqual(tuple(my_res), res)
示例#55
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)
示例#56
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile  = args[0]
        outfile = None
    elif nargs == 2:
        infile  = args[0]
        outfile  = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py input_file [output_file]\n");
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    txvga1_gain = -4
    txvga2_gain = 25

    tb = gr.top_block()

    src = blocks.file_source(gr.sizeof_char, infile, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc_taps = firdes.root_raised_cosine(0.1, symbol_rate*2, symbol_rate/2, 0.1152, 200)
    rrc = filter.rational_resampler_ccc(interpolation=2, decimation=3, taps=rrc_taps, fractional_bw=None, )

    out = osmosdr.sink(args="bladerf=0,buffers=128,buflen=32768")
    out.set_sample_rate(symbol_rate * 2 / 3)
    out.set_center_freq(center_freq, 0)
    out.set_freq_corr(0, 0)
    out.set_gain(txvga2_gain, 0)
    out.set_bb_gain(txvga1_gain, 0)
    out.set_bandwidth(6000000, 0)

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()