Ejemplo n.º 1
1
    def test_002_cc(self):
        N = 10000        # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        freq = 10
        data = sig_source_c(fs, freq, 1, N)
        signal = blocks.vector_source_c(data)
        op = filter.fractional_resampler_cc(0.0, rrate)
        snk = blocks.vector_sink_c()

        self.tb.connect(signal, op, snk)
        self.tb.run() 

        Ntest = 5000
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs/rrate), xrange(L))

        phase = 0.1884
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
    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)
Ejemplo n.º 3
0
    def test_001_simple_receiver(self):
        # make sure advanced receiver works like simple receiver in case no IC iterations are applied!
        reps = 5
        alpha = .5
        M = 127
        K = 16
        L = 2
        taps = filters.get_frequency_domain_filter('rrc', alpha, M, K, L)
        data = np.array([], dtype=np.complex)
        ref = np.array([], dtype=np.complex)
        for i in xrange(reps):
            d = utils.get_random_qpsk(M * K)
            ref = np.append(ref, gfdm_demodulate_block(d, taps, K, M, L))
            data = np.append(data, d)
        # print data
        # print ref
        # print "MAXIMUM ref value: ", np.max(abs(ref))

        src = blocks.vector_source_c(data)
        est_data = np.ones(len(data), dtype=np.complex)
        est_src = blocks.vector_source_c(est_data)
        gfdm_constellation = digital.constellation_qpsk().base()
        mod = gfdm.advanced_receiver_sb_cc(M, K, L, 0,
                                           taps, gfdm_constellation, np.arange(K))
        dst = blocks.vector_sink_c()

        self.tb.connect(src, (mod, 0), dst)
        self.tb.connect(est_src, (mod, 1))
        # set up fg
        self.tb.run()
        # check data
        res = np.array(dst.data())

        self.assertComplexTuplesAlmostEqual(ref, res, 4)
Ejemplo n.º 4
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     self.N_rb_dl = N_rb_dl = 6
     self.key = "symbol"
     self.out_key = "subframe"
     self.msg_buf_name = "cell_id"
     n_carriers = 12*N_rb_dl
     n_cfi_vec = 16
     intu = np.zeros(n_carriers,dtype=np.complex)
     
     self.src0 = blocks.vector_source_c( intu, False, n_carriers)
     self.src1 = blocks.vector_source_c( intu, False, n_carriers)
     self.src2 = blocks.vector_source_c( intu, False, n_carriers)
     
     self.demux = lte.pcfich_demux_vcvc(N_rb_dl, self.key, self.out_key, self.msg_buf_name)
             
     self.snk0 = blocks.vector_sink_c(n_cfi_vec)
     self.snk1 = blocks.vector_sink_c(n_cfi_vec)
     self.snk2 = blocks.vector_sink_c(n_cfi_vec)
     
     self.tag = blocks.tag_debug(n_cfi_vec * 8, "TAG")
     
     self.tb.connect(self.src0, (self.demux,0) )
     self.tb.connect( (self.demux,0), self.snk0)
     self.tb.connect(self.src1, (self.demux,1) )
     self.tb.connect( (self.demux,1), self.snk1)
     self.tb.connect(self.src2, (self.demux,2) )
     self.tb.connect( (self.demux,2), self.snk2)
     self.tb.connect( (self.demux,0), self.tag)
Ejemplo n.º 5
0
	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)
Ejemplo n.º 6
0
 def test_add_fc32(self):
     tb = gr.top_block()
     src0 = blocks.vector_source_c([1, 3j, 5, 7j, 9], False)
     src1 = blocks.vector_source_c([0, 2j, 4, 6j, 8], False)
     adder = add_2_fc32_1_fc32()
     sink = blocks.vector_sink_c()
     tb.connect((src0, 0), (adder, 0))
     tb.connect((src1, 0), (adder, 1))
     tb.connect(adder, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 5j, 9, 13j, 17))
Ejemplo n.º 7
0
    def test_002_pcfich(self):
        print "test_002_pcfich"
        
        # some constants
        cell_id = 124
        N_ant = 2
        style= "tx_diversity"
        vlen = 16
        ns = 0
        
        # new top_block because even the interface changes
        self.tb2 = gr.top_block()
        
        # generate test data together with the expected output
        data = []
        exp_res = []
        for cfi in range(4):
            cfi_seq = get_cfi_sequence(cfi+1)
            scr_cfi_seq = scramble_cfi_sequence(cfi_seq, cell_id, ns)
            mod_cfi_seq = qpsk_modulation(scr_cfi_seq)
            lay_cfi_seq = layer_mapping(mod_cfi_seq, N_ant, style)
            lay_cfi_prep = prepare_for_demapper_block(lay_cfi_seq, N_ant, style)
            exp_res.extend(lay_cfi_prep)
            pc_cfi_seq = pre_coding(lay_cfi_seq, N_ant, style)
            pc_cfi_seq = [pc_cfi_seq[0][i]+pc_cfi_seq[1][i] for i in range(len(pc_cfi_seq[0]))]
            data.extend(pc_cfi_seq)

        # dummy channel estimates        
        intu2 = [complex(1,0)]*len(data)
        intu3 = [complex(1,0)]*len(data)
               
        # get blocks
        self.src1 = blocks.vector_source_c( data, False, vlen)
        self.src2 = blocks.vector_source_c( intu2, False, vlen)
        self.src3 = blocks.vector_source_c( intu3, False, vlen)
        self.pd = lte_swig.pre_decoder_vcvc(1, vlen, style)
        self.snk = blocks.vector_sink_c(vlen)
        
        # connect all blocks
        self.tb2.connect(self.src1, (self.pd,0) )
        self.tb2.connect(self.src2, (self.pd,1) )
        self.tb2.connect(self.src3, (self.pd,2) )
        self.tb2.connect(self.pd, self.snk)
        
        self.pd.set_N_ant(N_ant)
        
        # run flowgraph
        self.tb2.run()
        
        # compare result with expected result
        res = self.snk.data()

        self.assertComplexTuplesAlmostEqual(res, exp_res)
Ejemplo n.º 8
0
 def test_001_parts(self):
     print "test 001 PARTS!!!"
     # This test is for integration
     # all parts expect Demux are tested if they decode CFI correctly
     
     self.tb2 = gr.top_block ()
     
     cell_id = 124
     N_ant = 2
     style = "tx_diversity"
     cvlen = 16
     key = "subframe"
     msg_buf_name = "cfi"
     cfi = 1
     
     data = []
     exp_pc = []
     for ns in range(10):
         cfi_seq = get_cfi_sequence(cfi)
         scr = scramble_cfi_sequence(cfi_seq, cell_id, 2*ns)
         mod = qpsk_modulation(scr)
         lay = layer_mapping(mod, N_ant, style)
         prc = pre_coding(lay, N_ant, style)
         prc_prep = [prc[0][i]+prc[1][i] for i in range(len(prc[0]))]
         #print np.shape(prc)
         prep = prepare_for_demapper_block(lay, N_ant, style)
         exp_pc.extend(prep)
         data.extend(prc_prep)
           
     taglist = get_tag_list(len(data)/16, key, 10)
     self.src = blocks.vector_source_c(data, False, cvlen, taglist)
   
     h0 = [complex(1,0)]*len(data)
     h1 = [complex(1,0)]*len(data)
     self.src1 = blocks.vector_source_c(h0, False, cvlen)
     self.src2 = blocks.vector_source_c(h1, False, cvlen)
     self.predecoder = lte.pre_decoder_vcvc(N_ant, cvlen, style)
     self.snk = blocks.vector_sink_c(cvlen)
     self.demapper = lte.layer_demapper_vcvc(N_ant, cvlen, style)
     self.qpsk = lte.qpsk_soft_demod_vcvf(cvlen)
     self.descr = lte.pcfich_descrambler_vfvf(key, msg_buf_name)
     self.descr.set_cell_id(cell_id)
     self.cfi = lte.cfi_unpack_vf(key, msg_buf_name)
     
     self.tb2.connect(self.src, (self.predecoder, 0))
     self.tb2.connect(self.src1, (self.predecoder, 1))
     self.tb2.connect(self.src2, (self.predecoder, 2))
     self.tb2.connect(self.predecoder, self.demapper)
     self.tb2.connect(self.predecoder, self.snk)
     self.tb2.connect(self.demapper, self.qpsk, self.descr, self.cfi)
     
     self.tb2.run()
     print "test 001 PARTS FINISHED!!!\n"
Ejemplo n.º 9
0
	def __init__(self):
		gr.top_block.__init__(self)
		

		usage = "%prog: [options] samples_file"
		parser = OptionParser(option_class=eng_option, usage=usage)
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
  		parser.add_option("-s", "--resample-fixed", type="float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
  		parser.add_option('-r', '--sample-rate', type="int", default=2048000,
	     		help="Use non-standard sample rate (default=%default)")
  		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
	     		help="Enable individual carrier magnitude equalizer")
  		parser.add_option('-d', '--debug', action="store_true", default=False,
	     		help="Write output to files")
  		parser.add_option('-v', '--verbose', action="store_true", default=False,
	     		help="Print status messages")
		(options, args) = parser.parse_args ()
	
		dp = parameters.dab_parameters(options.dab_mode, verbose=options.verbose, sample_rate=options.sample_rate)

		rp = parameters.receiver_parameters(options.dab_mode, input_fft_filter=options.filter_input, autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, equalize_magnitude=options.equalize_magnitude, verbose=options.verbose)

		if len(args)<1:
			if options.verbose: print "-> using repeating random vector as source"
			self.sigsrc = blocks.vector_source_c([10e6*(random.random() + 1j*random.random()) for i in range(0,100000)],True)
			self.ns_simulate = blocks.vector_source_c([0.01]*dp.ns_length+[1]*dp.symbols_per_frame*dp.symbol_length,1)
			self.mult = blocks.multiply_cc() # simulate null symbols ...
			self.src = blocks.throttle( gr.sizeof_gr_complex,2048000)
			self.connect(self.sigsrc, (self.mult, 0))
			self.connect(self.ns_simulate, (self.mult, 1))
			self.connect(self.mult, self.src)
		else:
			filename = args[0]
			if options.verbose: print "-> using samples from file " + filename
			self.src = blocks.file_source(gr.sizeof_gr_complex, filename, False)

		self.dab_demod = ofdm.ofdm_demod(dp, rp, debug=options.debug, verbose=options.verbose)
		
		self.connect(self.src, self.dab_demod)

		# sink output to nowhere 
		self.nop0 = blocks.nop(gr.sizeof_char*dp.num_carriers/4)
		self.nop1 = blocks.nop(gr.sizeof_char)
		self.connect((self.dab_demod,0),self.nop0)
		self.connect((self.dab_demod,1),self.nop1)
    def test_001_t (self):
        # set up fg
	src1 = blocks.vector_source_c( (complex(1,1),complex(2,2)) )
	src2 = blocks.vector_source_c( (complex(3,3),complex(4,4)) )
	src3 = blocks.vector_source_c( (complex(5,5),complex(6,6)) )
	test = radar.FMCW_generate_IQ_cc(2)
	snk = blocks.vector_sink_c()
	self.tb.connect(src1,(test,0))
	self.tb.connect(src2,(test,1))
	self.tb.connect(src3,(test,2))
	self.tb.connect(test,snk)
        self.tb.run ()
        # check data
	ref_data = ( complex(1,1),complex(2,2),complex(3,3),complex(4,4),complex(5,5),complex(6,6) )
	self.assertTupleEqual(ref_data,snk.data())
Ejemplo n.º 11
0
    def test01(self):
        # Test complex/complex version
        omega = 2
        gain_omega = 0.001
        mu = 0.5
        gain_mu = 0.01
        omega_rel_lim = 0.001

        self.test = digital.clock_recovery_mm_cc(omega, gain_omega,
                                                 mu, gain_mu,
                                                 omega_rel_lim)
        
        data = 100*[complex(1, 1),]
        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()
        
        expected_result = 100*[complex(0.99972, 0.99972)] # doesn't quite get to 1.0
        dst_data = self.snk.data()

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

        #print expected_result
        #print dst_data
        
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
Ejemplo n.º 12
0
    def test_003_block_pinching(self):
        n_reps = 1
        n_subcarriers = 8
        n_timeslots = 8
        block_len = n_subcarriers * n_timeslots
        cp_len = 8
        ramp_len = 4
        cs_len = ramp_len * 2
        window_len = get_window_len(cp_len, n_timeslots, n_subcarriers, cs_len)
        window_taps = get_raised_cosine_ramp(ramp_len, window_len)
        data = np.arange(block_len, dtype=np.complex) + 1
        ref = add_cyclic_starfix(data, cp_len, cs_len)
        ref = pinch_block(ref, window_taps)
        data = np.tile(data, n_reps)
        ref = np.tile(ref, n_reps)
        print "input is: ", len(data), " -> " , len(ref)
        # short_window = np.concatenate((window_taps[0:ramp_len], window_taps[-ramp_len:]))
        prefixer = gfdm.cyclic_prefixer_cc(block_len, cp_len, cs_len, ramp_len, window_taps)
        src = blocks.vector_source_c(data)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, prefixer, dst)
        self.tb.run()

        res = np.array(dst.data())
        print ref[-10:]
        print res[-10:]

        self.assertComplexTuplesAlmostEqual(res, ref, 4)
Ejemplo n.º 13
0
    def test_04(self):
        tb = self.tb

        N = 10000  # number of samples
        history = 100  # num of samples to average
        data = make_random_complex_tuple(N, 1)  # generate random data

        #  pythonic MA filter
        data_padded = (history-1)*[0.0+1j*0.0]+list(data)  # history  
        expected_result = []
        moving_sum = sum(data_padded[:history-1])
        for i in range(N):
            moving_sum += data_padded[i+history-1]
            expected_result.append(moving_sum)
            moving_sum -= data_padded[i]

        src = blocks.vector_source_c(data, False)
        op  = blocks.moving_average_cc(history, 1)
        dst = blocks.vector_sink_c()
        
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
    
        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
Ejemplo n.º 14
0
    def test03(self):
        # Test complex/complex version with varying input
        omega = 2
        gain_omega = 0.01
        mu = 0.25
        gain_mu = 0.1
        omega_rel_lim = 0.0001

        self.test = digital.clock_recovery_mm_cc(omega, gain_omega,
                                                 mu, gain_mu,
                                                 omega_rel_lim)
        
        data = 1000*[complex(1, 1), complex(1, 1), complex(-1, -1), complex(-1, -1)]
        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()
        
        expected_result = 1000*[complex(-1.2, -1.2), complex(1.2, 1.2)]
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 100
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]
        
        #print expected_result
        #print dst_data
        
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
	def test_006_t(self):
		M = 2**7
		num = 2**15
		src_data = list()
		for i in range(num*M):
			src_data.append(int(random.random()*10)+1+(int(random.random()*10)+1)*1j)
		src = blocks.vector_source_c(src_data,vlen=M)
		# snk1 = blocks.vector_sink_c(vlen=4)
		pre = ofdm.fbmc_oqam_preprocessing_vcvc(M=M,offset=0, theta_sel=0)
		post = ofdm.fbmc_oqam_postprocessing_vcvc(M=M, offset=0, theta_sel=0)
		dst = blocks.vector_sink_c(vlen=M)
		self.tb.connect(src,pre,post,dst)
		# self.tb.connect(pre,snk1)
		self.tb.run ()
		# check data
		result_data = dst.data()
		print result_data==tuple(src_data)
# 		list1 = []
# 		list2 = []
# 		for i in range(0,2000000):#,len(result_data)):
# 			if result_data[i] != src_data[i]:
# 				list1.append(result_data[i])
# 			else:
# 				list2.append(src_data[i])
#  				
# 		print len(list1)
# 		print len(list2)
				
		self.assertComplexTuplesAlmostEqual(tuple(src_data),result_data,7)
Ejemplo n.º 16
0
    def test_001_t(self):
        nsubcarrier = 4
        ntimeslots = 16
        filter_alpha = 0.35
        tag_key = "frame_len"
        fft_length = nsubcarrier * ntimeslots
        taps = get_frequency_domain_filter('rrc', filter_alpha, ntimeslots, nsubcarrier, 2)

        data = get_random_qpsk(nsubcarrier * ntimeslots)
        # data = np.zeros(nsubcarrier)
        # data[0] = 1
        # data = np.repeat(data, ntimeslots)
        D = get_data_matrix(data, nsubcarrier, group_by_subcarrier=False)
        print D

        md = gfdms.modulator_cc(nsubcarrier, ntimeslots, filter_alpha, fft_length, 1, tag_key)
        tagger = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, fft_length, tag_key)
        src = blocks.vector_source_c(data)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, tagger, md, dst)
        self.tb.run()

        res = np.array(dst.data())
        print res
        ref = gfdm_modulate_block(D, taps, ntimeslots, nsubcarrier, 2, True)
        print ref

        self.assertComplexTuplesAlmostEqual(ref, res, 2)
Ejemplo n.º 17
0
    def test_001_setup(self):
        multiple = 6
        overlap = 1  # must be 1 in this test!
        L = 4
        taps = np.array([0, 1, 2, 1])
        taps = np.append(taps, [0.0, ])
        data = np.arange(1, multiple * L + 1, dtype=np.complex)

        try:  # make sure ctor checks work correctly!
            dummy = fbmc.tx_sdft_vcc([1, 1, 1], L)
        except RuntimeError as e:
            s = str(e)
            pos = s.find("number of filter taps must be equal to")
            if pos < 0:
                raise

        tx_sdft = fbmc.tx_sdft_vcc(taps, L)
        src = blocks.vector_source_c(data, vlen=L)
        snk = blocks.vector_sink_c(vlen=1)
        # set up fg
        self.tb.connect(src, tx_sdft, snk)

        self.tb.run()
        # check data

        print "L: ", tx_sdft.L()
        print "overlap: ", tx_sdft.overlap()
        print "taps: ", tx_sdft.taps()

        res = snk.data()
        print res
Ejemplo n.º 18
0
    def test_001(self):
        """ Run test:
        - No overlap
        - Hamming window from Python
        - Constant input signal of amplitude 1

        The given input signal has a known power of 1. Therefore, the integral of the
        PSD estimation result should be pretty close to 1."""
        fft_len = 256
        overlap = 0
        alpha = 0.1
        window = hamming(fft_len)

        src_data = (1,) * (100 * fft_len)
        src = blocks.vector_source_c(src_data, False)
        welch = specest.welchsp(fft_len, overlap, alpha, False, window)
        sink = blocks.vector_sink_f(fft_len)

        self.tb.connect(src, welch, sink)
        self.tb.run()

        dst_data =  sink.data()
        dst_data = array(dst_data[-fft_len:])
        power_est = sum(dst_data) * 2 * pi / fft_len
        print power_est

        self.assertAlmostEqual(power_est, 1, 3)
Ejemplo n.º 19
0
    def test_001_t(self):
        cell_id = 124
        fftlen = 128
        N_rb_dl = 6
        N_ant = 1
        outkey = 'symbol'
        initial_offset = 1459
        frame = phy.generate_phy_frame(cell_id, N_rb_dl, N_ant)
        time_frame = phy.transform_to_time_domain(frame, fftlen)
        samples = phy.transform_to_stream_cp(time_frame, fftlen)
        samps = samples[0]
        samps = np.append(np.zeros(initial_offset, dtype=complex), samps)
        tag_list = self.get_tag_list(fftlen, initial_offset, 20, 10, 'slot', 'pss_tagger')

        src = blocks.vector_source_c(samps, tags=tag_list, repeat=False)
        ext = lte.mimo_remove_cp(fftlen, N_ant, outkey)
        snk = blocks.vector_sink_c(fftlen)

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

        # check data
        n_syms = 139
        res = snk.data()[0:fftlen * n_syms]
        ref = time_frame.flatten()[0:fftlen * n_syms]
        self.assertComplexTuplesAlmostEqual(res, ref, 5)
Ejemplo n.º 20
0
    def test_quad_demod_001(self):
        f = 1000.0
        fs = 8000.0

        src_data = []
        for i in xrange(200):
            ti = i/fs
            src_data.append(cmath.exp(2j*cmath.pi*f*ti))

        # f/fs is a quarter turn per sample.
        # Set the gain based on this to get 1 out.
        gain = 1.0/(cmath.pi/4)

        expected_result = [0,] + 199*[1.0]

        src = blocks.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = blocks.vector_sink_f()
        
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()
        
        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
Ejemplo n.º 21
0
    def test_001_t (self):
      	# to test a complex distorsion added to the symbols that translates all symbols by a constant value
	# Each vector has all constellation values
	number_of_vectors = 5000
	dim_constellation = 16
	# real and imaginary part of the distorsion added to the symbols
	distorsion_real = 0.1
	distorsion_imag =0.1
	# call the probe_mer constructor with the symbol table and alpha value for averaging
 	self.mer_probe_cs_cf_0 = mer.probe_cs_cf((0.9487+0.9487j,0.9487+0.3162j, 0.3162+0.9487j, 0.3162 +0.3162j,0.9487-0.9487j,0.9487- 0.3162j, 0.3162-0.9487j, 0.3162- 0.3162j,-0.9487+0.9487j,-0.9487+ 0.3162j,- 0.3162+0.9487j,- 0.3162+ 0.3162j,-0.9487-0.9487j,-0.9487- 0.3162j,-0.3162-0.9487j,-0.3162- 0.3162j),0.005)
        #source data to test is a vector of the cosntellation table * number_of_vectors
        src_data = (0.9487+0.9487j,0.9487+0.3162j, 0.3162+0.9487j, 0.3162 +0.3162j,0.9487-0.9487j,0.9487- 0.3162j, 0.3162-0.9487j, 0.3162- 0.3162j,-0.9487+0.9487j,-0.9487+ 0.3162j,- 0.3162+0.9487j,- 0.3162+ 0.3162j,-0.9487-0.9487j,-0.9487- 0.3162j,-0.3162-0.9487j,-0.3162- 0.3162j)*number_of_vectors
	# Add the aditive distorsion to the source data
	src_data = [x+distorsion_real+distorsion_imag*(1j) for x in src_data]
	# create a vector source with the source data and a vector sink block to receive the CS value
        self.src = blocks.vector_source_c(src_data,False)
	self.dst0 = blocks.vector_sink_f()
	#Connect the blocks
        self.tb.connect((self.src, 0), (self.mer_probe_cs_cf_0, 0))    
        self.tb.connect((self.mer_probe_cs_cf_0, 0),(self.dst0, 0))    
	self.tb.run ()   
	# The CS result is the average of the last values of received in the destination vector	
	result_data1 = np.mean(self.dst0.data()[number_of_vectors*dim_constellation-dim_constellation:number_of_vectors*dim_constellation])
	print " result cs = ", result_data1
	#Calculate the theoretical CS error from the distorsion values	
	cs = distorsion_real*distorsion_real+distorsion_imag*distorsion_imag
	print " expected result = ", cs
	expected_result1 = cs
	#Tests that the error is less than 0.1%
	self.assertLessEqual(abs((result_data1-expected_result1)/expected_result1), 0.001 )
Ejemplo n.º 22
0
 def setup_test05(self):
     print "... benchmarking 8-PSK demapper"
     self.nobits = 4
     self.data_subcarriers = 200
     
     self.blks = self.N*(10 + 1)
     self.tb = gr.top_block()
         
     #self.bitmap = [self.nobits]*self.data_subcarriers
     self.demodulator = generic_demapper_vcb(self.data_subcarriers,10)
     const =  self.demodulator.get_constellation( self.nobits )
     assert( len( const ) == 2**self.nobits )
            
 
     self.bitdata = [random()+1j*random() for i in range(self.blks*self.data_subcarriers)]
     self.src = blocks.vector_source_c(self.bitdata,False, self.data_subcarriers)
     #self.src = symbol_random_src( const, self.data_subcarriers )
     
     self.bitmap = [0]*self.data_subcarriers + [self.nobits]*self.data_subcarriers      
     self.bitmap_src = blocks.vector_source_b(self.bitmap,True, self.data_subcarriers)
     
     #self.bmaptrig_stream = [1, 2]+[0]*(11-2)
     #self.bitmap_trigger = blocks.vector_source_b(self.bmaptrig_stream, True)
     
     self.snk = blocks.null_sink(gr.sizeof_char)
             
     self.tb.connect(self.src,self.demodulator,self.snk)
     self.tb.connect(self.bitmap_src,(self.demodulator,1))
Ejemplo n.º 23
0
	def __init__(self):
		gr.top_block.__init__(self)
		
		usage = "%prog: [options] samples_file"
		parser = OptionParser(option_class=eng_option, usage=usage)
		(options, args) = parser.parse_args ()
		if len(args)<1:
			# print "using gaussian noise as source"
			# self.sigsrc = gr.noise_source_c(gr.GR_GAUSSIAN,10e6)
			print "using repeating random vector as source"
			self.sigsrc = blocks.vector_source_c([10e6*(random.random() + 1j*random.random()) for i in range(0,100000)],True)
			self.src = blocks.throttle( gr.sizeof_gr_complex,2048000)
			self.connect(self.sigsrc, self.src)
		else:
			filename = args[0]
			print "using samples from file " + filename
			self.src = blocks.file_source(gr.sizeof_gr_complex, filename, False)

		dp = parameters.dab_parameters(1)
		rp = parameters.receiver_parameters(1)
		self.sync_dab = ofdm_sync_dab(dp, rp, False)
		self.nop0 = blocks.nop(gr.sizeof_gr_complex)
		self.nop1 = blocks.nop(gr.sizeof_char)
		self.connect(self.src, self.sync_dab, self.nop0)
		self.connect((self.sync_dab,1), self.nop1)
Ejemplo n.º 24
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        data = 2.0*scipy.random.randint(0, 2, N) - 1.0
        data = scipy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_fll = blocks.vector_sink_c()
        self.vsnk_frq = blocks.vector_sink_f()
        self.vsnk_phs = blocks.vector_sink_f()
        self.vsnk_err = blocks.vector_sink_f()

        self.connect(self.src, self.rrc, self.chn, self.fll, self.vsnk_fll)
        self.connect(self.rrc, self.vsnk_src)
        self.connect((self.fll,1), self.vsnk_frq)
        self.connect((self.fll,2), self.vsnk_phs)
        self.connect((self.fll,3), self.vsnk_err)
    def test_1seg_mode3 (self):
        # set up fg

        total_segments = 1; 
        mode = 3; 
        total_carriers = total_segments*96*2**(mode-1)
        deinterleaver_1seg = isdbt.frequency_deinterleaver_1seg(mode=3)

        # the random array of indices
        src_data = (249, 272, 269, 137, 309, 24, 255, 327, 294, 197, 364, 3, 160, 1, 46, 354, 104, 113, 195, 193, 59, 236, 90, 288, 292, 224, 258, 382, 163, 85, 153, 89, 350, 277, 298, 237, 230, 345, 135, 127, 340, 349, 366, 77, 180, 25, 11, 333, 332, 157, 239, 383, 91, 18, 314, 185, 10, 43, 102, 169, 162, 37, 0, 194, 117, 290, 233, 270, 278, 343, 338, 204, 317, 130, 273, 336, 377, 55, 315, 51, 304, 72, 23, 208, 266, 98, 174, 209, 35, 303, 82, 379, 9, 365, 295, 378, 257, 78, 225, 134, 48, 76, 84, 265, 337, 284, 240, 238, 114, 179, 341, 280, 58, 109, 101, 56, 96, 141, 281, 107, 12, 188, 253, 44, 232, 22, 32, 375, 120, 73, 215, 320, 326, 176, 356, 28, 248, 228, 212, 66, 282, 30, 80, 62, 371, 106, 344, 339, 328, 145, 200, 149, 63, 139, 210, 42, 368, 81, 131, 252, 216, 155, 361, 306, 19, 293, 275, 105, 330, 235, 171, 289, 16, 26, 348, 13, 158, 95, 61, 41, 316, 170, 29, 71, 52, 53, 261, 21, 254, 119, 192, 100, 69, 111, 276, 283, 99, 260, 103, 60, 259, 227, 285, 358, 65, 50, 251, 321, 45, 359, 144, 199, 268, 143, 83, 64, 219, 152, 211, 229, 7, 325, 296, 222, 331, 167, 8, 47, 267, 164, 201, 203, 112, 36, 67, 17, 220, 118, 299, 124, 198, 150, 357, 133, 380, 108, 116, 308, 196, 38, 367, 175, 244, 305, 223, 205, 74, 183, 27, 287, 190, 88, 243, 246, 33, 165, 302, 279, 182, 213, 376, 245, 355, 31, 381, 191, 132, 57, 217, 313, 307, 291, 319, 115, 256, 4, 34, 136, 166, 142, 312, 286, 370, 94, 373, 110, 97, 362, 14, 329, 226, 93, 122, 86, 351, 92, 324, 352, 221, 70, 40, 49, 353, 335, 75, 140, 318, 186, 271, 172, 123, 151, 156, 184, 79, 231, 242, 363, 54, 374, 138, 297, 202, 241, 154, 125, 5, 147, 369, 148, 263, 173, 274, 322, 177, 262, 161, 128, 214, 264, 206, 129, 15, 234, 347, 207, 126, 334, 68, 159, 189, 178, 310, 87, 300, 6, 250, 39, 20, 181, 323, 2, 247, 121, 342, 346, 301, 218, 372, 311, 360, 187, 168, 146)
       
        
        src_data = src_data*total_segments*3

	expected_result = range(96*2**(mode-1))*total_segments*3

        src = blocks.vector_source_c(src_data, False, total_carriers)
        dst = blocks.vector_sink_c(total_carriers)

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

        # check data
        actual_result = dst.data()
 #       print "src data: ", src_data
 #       print "actual result: ", actual_result
 #       print "expected result: ", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
    def test_1seg_mode1 (self):
        # set up fg

        total_segments = 1; 
        mode = 1; 
        total_carriers = total_segments*96*2**(mode-1)
        deinterleaver_1seg = isdbt.frequency_deinterleaver_1seg(mode)

        # the random array of indices
        
        src_data = (32, 26, 69, 51, 35, 61, 8, 39, 46, 10, 87, 34, 20, 23, 74, 15, 38, 6, 22, 45, 55, 50, 41, 42, 95, 59, 52, 76, 33, 68, 80, 60, 89, 88, 25, 37, 47, 79, 27, 48, 73, 85, 63, 66, 78, 36, 18, 82, 40, 62, 91, 9, 14, 94, 64, 5, 44, 77, 92, 29, 67, 49, 90, 2, 31, 13, 17, 54, 81, 53, 21, 19, 58, 16, 56, 84, 70, 43, 28, 75, 0, 7, 93, 72, 71, 11, 57, 65, 83, 12, 86, 30, 3, 1, 4, 24)
        src_data = src_data*total_segments

	expected_result = range(96*2**(mode-1))*total_segments

        src = blocks.vector_source_c(src_data, False, total_carriers)
        dst = blocks.vector_sink_c(total_carriers)

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

        # check data
        actual_result = dst.data()
        print "src data: ", src_data
        print "actual result: ", actual_result
        print "expected result: ", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
Ejemplo n.º 27
0
    def test_001_t(self):
        num_frames = 5
        total_subcarriers = 8
        used_subcarriers = 4
        channel_map = ft.get_channel_map(used_subcarriers, total_subcarriers)
        payload_symbols = 8
        overlap = 4
        num_preamble_symbols = 4

        payload = ft.get_payload(payload_symbols, used_subcarriers)
        frame = ft.get_frame(payload, total_subcarriers, channel_map, payload_symbols, overlap)
        frame = np.tile(frame, num_frames).flatten()
        payload = np.tile(payload, num_frames).flatten()

        # set up fg
        src = blocks.vector_source_c(frame, repeat=False, vlen=total_subcarriers)
        deframer = fbmc.deframer_vcb(used_subcarriers, total_subcarriers, num_preamble_symbols, payload_symbols, overlap, channel_map)
        snk = blocks.vector_sink_b(1)
        self.tb.connect(src, deframer, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        print res
        print payload

        self.assertTupleEqual(tuple(payload), tuple(res))
    def test_1seg_mode2 (self):
        # set up fg

        total_segments = 1; 
        mode = 2; 
        total_carriers = total_segments*96*2**(mode-1)
        deinterleaver_1seg = isdbt.frequency_deinterleaver_1seg(mode)

        # the random array of indices
        src_data = (78, 120, 35, 91, 150, 6, 129, 160, 159, 169, 59, 148, 114, 154, 37, 123, 162, 5, 139, 70, 89, 136, 106, 128, 69, 65, 163, 190, 26, 184, 170, 151, 155, 50, 182, 1, 25, 16, 57, 73, 153, 158, 47, 12, 166, 55, 42, 28, 15, 112, 147, 61, 97, 186, 10, 156, 131, 71, 107, 191, 101, 83, 121, 175, 168, 100, 119, 2, 41, 17, 140, 72, 33, 8, 13, 84, 21, 74, 27, 23, 126, 165, 85, 111, 53, 77, 36, 105, 76, 66, 143, 187, 95, 7, 30, 142, 125, 49, 0, 132, 108, 86, 117, 167, 179, 48, 178, 20, 185, 145, 189, 109, 45, 81, 40, 181, 3, 62, 88, 127, 94, 92, 44, 133, 146, 67, 172, 99, 29, 141, 38, 104, 113, 102, 51, 4, 90, 135, 134, 68, 82, 110, 34, 11, 161, 137, 116, 103, 174, 144, 19, 39, 149, 98, 18, 115, 63, 171, 180, 157, 96, 64, 79, 31, 118, 14, 130, 58, 9, 188, 54, 177, 152, 164, 87, 24, 22, 52, 122, 173, 46, 80, 124, 43, 32, 138, 183, 56, 176, 60, 93, 75)
        
        src_data = src_data*total_segments

	expected_result = range(96*2**(mode-1))*total_segments

        src = blocks.vector_source_c(src_data, False, total_carriers)
        dst = blocks.vector_sink_c(total_carriers)

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

        # check data
        actual_result = dst.data()
#        print "src data: ", src_data
#        print "actual result: ", actual_result
#        print "expected result: ", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
Ejemplo n.º 29
0
    def check_channelizer(self, channelizer_block):
        signals = list()
        add = blocks.add_cc()
        for i in range(len(self.freqs)):
            f = self.freqs[i] + i*self.fs
            data = sig_source_c(self.ifs, f, 1, self.N)
            signals.append(blocks.vector_source_c(data))
            self.tb.connect(signals[i], (add,i))

        #s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self.M)

        #self.tb.connect(add, s2ss)
        self.tb.connect(add, channelizer_block)

        snks = list()
        for i in range(self.M):
            snks.append(blocks.vector_sink_c())
            #self.tb.connect((s2ss,i), (channelizer_block,i))
            self.tb.connect((channelizer_block, i), snks[i])

        self.tb.run()

        L = len(snks[0].data())

        expected_data = self.get_expected_data(L)
        received_data = [snk.data() for snk in snks]

        for expected, received in zip(expected_data, received_data):
            self.compare_data(expected, received)
Ejemplo n.º 30
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)
Ejemplo n.º 31
0
    def test_002_t(self):
        tkey = 'packet_len'
        tsrc = 'testsrc'
        ptkey = pmt.intern(tkey)
        ptsrc = pmt.intern(tsrc)
        pre_padding = 17
        post_padding = 23
        n_bursts = 3
        tags = []
        burst_len = 128
        offset = 0
        data = np.array((), dtype=np.complex)
        ref = np.array((), dtype=np.complex)
        for i in range(n_bursts):
            tag = gr.tag_utils.python_to_tag(
                (offset, ptkey, pmt.from_long(burst_len * (i + 1)), ptsrc))
            tags.append(tag)
            offset += burst_len * (i + 1)

            d = np.arange(burst_len * (i + 1)) + 1
            d = d.astype(data.dtype)
            data = np.append(data, d)
            r = np.concatenate((np.zeros(pre_padding, dtype=d.dtype), d,
                                np.zeros(post_padding, dtype=d.dtype)))
            ref = np.append(ref, r)
        # ref = np.concatenate((np.zeros(pre_padding, dtype=data.dtype),
        #                       data, np.zeros(post_padding, dtype=data.dtype)))

        src = blocks.vector_source_c(data, tags=tags)
        uut = gfdm.short_burst_shaper(pre_padding, post_padding, tkey)
        snk = blocks.vector_sink_c()
        # set up fg
        self.tb.connect(src, uut, snk)
        self.tb.run()
        # check data
        res = np.array(snk.data())
        print(res)

        self.assertComplexTuplesAlmostEqual(ref, res)
Ejemplo n.º 32
0
 def test_tag(self):
     # Send data through bpsk receiver
     # followed by qpsk receiver
     data = [0.9 + 0j, 0.1 + 0.9j, -1 - 0.1j, -0.1 - 0.6j] * 2
     bpsk_data = [1, 1, 0, 0]
     qpsk_data = [1, 3, 0, 0]
     first_tag = gr.tag_t()
     first_tag.key = pmt.intern("set_constellation")
     first_tag.value = digital.bpsk_constellation().as_pmt()
     first_tag.offset = 0
     second_tag = gr.tag_t()
     second_tag.key = pmt.intern("set_constellation")
     second_tag.value = digital.qpsk_constellation().as_pmt()
     second_tag.offset = 4
     src = blocks.vector_source_c(data, False, 1, [first_tag, second_tag])
     decoder = digital.constellation_receiver_cb(
         digital.bpsk_constellation().base(), 0, 0, 0)
     snk = blocks.vector_sink_b()
     tb = gr.top_block()
     tb.connect(src, decoder, snk)
     tb.run()
     self.assertEqual(list(snk.data()), bpsk_data + qpsk_data)
Ejemplo n.º 33
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.input_file is not None:
            src = blocks.file_source(gr.sizeof_gr_complex,
                                     options.filename,
                                     repeat=True)
        else:
            src = blocks.vector_source_c((.5, ) * int(1e6) * 2, repeat=True)
        # Setup USRP
        self.u = uhd.usrp_sink(options.args, uhd.stream_args('fc32'),
                               "packet_len")
        if (options.spec):
            self.u.set_subdev_spec(options.spec, 0)
        if (options.antenna):
            self.u.set_antenna(options.antenna, 0)
        self.u.set_samp_rate(options.rate)
        # Gain is set in the hopper block
        if options.gain is None:
            g = self.u.get_gain_range()
            options.gain = float(g.start() + g.stop()) / 2.0
        print "-- Setting gain to {} dB".format(options.gain)
        r = self.u.set_center_freq(options.freq)
        if not r:
            print '[ERROR] Failed to set base frequency.'
            raise SystemExit, 1
        hopper_block = FrequencyHopperSrc(
            options.num_bursts,
            options.num_channels,
            options.freq_delta,
            options.freq,
            options.samp_per_burst,
            1.0,
            options.hop_time / 1000.,
            options.post_tuning,
            options.gain,
            options.verbose,
        )
        self.connect(src, hopper_block, self.u)
Ejemplo n.º 34
0
    def test_002_update(self):
        start_time = 0.1
        self.duration = 125000
        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 250000)
        self.utag = timing_utils.add_usrp_tags_c(1090e6, 250000, 0, start_time)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")

        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tag_dbg, 0))

        self.tb.start()
        time.sleep(.01)
        #print("Dumping tags")
        for t in self.tag_dbg.current_tags():
            #print( 'Tag:' , t.key, ' ', t.value )
            if pmt.eq(t.key, pmt.intern("rx_freq")):
                self.assertAlmostEqual(1090e6, pmt.to_double(t.value))
            if pmt.eq(t.key, pmt.intern("rx_rate")):
                self.assertAlmostEqual(250000, pmt.to_double(t.value))

        self.utag.update_tags(
            self.makeDict(freq=1091e6,
                          rate=260000,
                          epoch_int=0,
                          epoch_frac=start_time + .3))
        time.sleep(.01)
        #print("Dumping tags")
        for t in self.tag_dbg.current_tags():
            #print( 'Tag:' , t.key, ' ', t.value )
            if pmt.eq(t.key, pmt.intern("rx_freq")):
                self.assertAlmostEqual(1091e6, pmt.to_double(t.value))
            if pmt.eq(t.key, pmt.intern("rx_rate")):
                self.assertAlmostEqual(260000, pmt.to_double(t.value))

        time.sleep(.1)
        self.tb.stop()
Ejemplo n.º 35
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset,
                 poffset):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(sps, sps, 1.0, rolloff,
                                                    ntaps)

        data = 2.0 * numpy.random.randint(0, 2, N) - 1.0
        data = numpy.exp(1j * poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.cst = digital.costas_loop_cc(bw, 2)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_cst = blocks.vector_sink_c()
        self.vsnk_frq = blocks.vector_sink_f()

        self.connect(self.src, self.rrc, self.chn, self.cst, self.vsnk_cst)
        self.connect(self.rrc, self.vsnk_src)
        self.connect((self.cst, 1), self.vsnk_frq)
Ejemplo n.º 36
0
    def test_000(self):
        N = 1000  # number of samples to use
        M = 5  # Number of channels
        fs = 1000  # baseband sampling rate
        ifs = M * fs  # input samp rate to decimator

        taps = filter.firdes.low_pass_2(
            M,
            ifs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        data = sig_source_c(fs, freq, 1, N)
        signal = blocks.vector_source_c(data)
        pfb = filter.pfb_interpolator_ccf(M, taps)
        snk = blocks.vector_sink_c()

        self.tb.connect(signal, pfb)
        self.tb.connect(pfb, snk)

        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / ifs, xrange(L))

        # Create known data as complex sinusoids at freq
        # of the channel at the interpolated rate.
        phase = 0.62833
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:],
                                            dst_data[-Ntest:], 4)
Ejemplo n.º 37
0
    def test_rx_rate_tag(self):
        src_data = [1, 2, 3, 4, 5, 6]
        tag = gr.tag_t()
        tag.key = pmt.string_to_symbol("rx_rate")
        tag.value = pmt.to_pmt(20)
        tag.offset = 0

        src = blocks.vector_source_c(src_data, tags=(tag,))
        thr = blocks.throttle(gr.sizeof_gr_complex, 10, ignore_tags=False)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, thr, dst)

        start_time = time.perf_counter()
        self.tb.run()
        end_time = time.perf_counter()

        total_time = end_time - start_time
        self.assertGreater(total_time, 0.3)
        self.assertLess(total_time, 0.4)

        dst_data = dst.data()
        self.assertEqual(src_data, dst_data)
Ejemplo n.º 38
0
    def test_001(self):
        ''' Test impulse response - long form, cc '''
        src_data = [
            1,
        ] + 100 * [
            0,
        ]
        expected_result = ((-0.02072429656982422 + 0j),
                           (-0.02081298828125 + 0j), (0.979156494140625 + 0j),
                           (-0.02081298828125 + 0j),
                           (-0.02072429656982422 + 0j))

        src = blocks.vector_source_c(src_data)
        op = filter.dc_blocker_cc(32, True)
        dst = blocks.vector_sink_c()

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

        # only test samples around 2D-2
        result_data = dst.data()[60:65]
        self.assertComplexTuplesAlmostEqual(expected_result, result_data)
Ejemplo n.º 39
0
 def test_005_both_1sym_force(self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     ref_symbol = (0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = [0, 0, 0, 2, 2, 2, 2.5, 3, 2.5, 2, 2.5, 3, 2, 1, 1, 0]
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, ref_symbol, 1)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.to_long(tag.value), carr_offset)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.c32vector_elements(tag.value), channel)
Ejemplo n.º 40
0
    def test_001_t(self):
        n_frames = 500
        burst_len = 383
        gap_len = 53
        tag_key = 'energy_start'

        data = np.arange(burst_len)
        ref = np.array([], dtype=np.complex)
        tags = []
        for i in range(n_frames):
            frame = np.ones(burst_len) * (i + 1)
            ref = np.concatenate((ref, frame))
            tag = gr.tag_t()
            tag.key = pmt.string_to_symbol(tag_key)
            tag.offset = burst_len + i * (burst_len + gap_len)
            tag.srcid = pmt.string_to_symbol('qa')
            tag.value = pmt.PMT_T
            tags.append(tag)
            data = np.concatenate((data, frame, np.zeros(gap_len)))
        # print(np.reshape(data, (-1, burst_len)))
        # print('data len', len(data), 'ref len', len(ref))

        src = blocks.vector_source_c(data, False, 1, tags)
        burster = gfdm.extract_burst_cc(burst_len, tag_key)
        snk = blocks.vector_sink_c()
        self.tb.connect(src, burster, snk)
        self.tb.run()

        res = np.array(snk.data())
        rx_tags = snk.tags()
        for i, t in enumerate(rx_tags):
            assert pmt.symbol_to_string(t.key) == tag_key
            assert pmt.to_long(t.value) == burst_len
            assert pmt.symbol_to_string(t.srcid) == burster.name()
            assert t.offset == i * burst_len
            # print t.offset, t.value

        # check data
        self.assertComplexTuplesAlmostEqual(ref, res)
 def test_001c_carrier_offset_cp (self):
     """
     Same as before, but put a carrier offset in there and a CP
     """
     fft_len = 8
     cp_len = 2
     n_syms = 3
     # cp_len/fft_len == 1/4, therefore, the phase is rotated by
     # carr_offset * \pi/2 in every symbol
     occupied_carriers = ((-2, -1, 1, 2),)
     carr_offset = -1
     tx_data = (
             0,-1j,-1j, 0,-1j,-1j, 0, 0,
             0, -1, -1, 0, -1, -1, 0, 0,
             0, 1j, 1j, 0, 1j, 1j, 0, 0,
     )
     # Rx'd signal is corrected
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (0, 0, 1, 1, 0, 1, 1, 0))
     offset_tag = gr.tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key),
         eq,
         sink
     )
     self.tb.run ()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data()[0], places=4)
Ejemplo n.º 42
0
	def test_003_ofdm_sampler(self):
		fft_len = 4
		src_data0 = (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0)
		src_data1 = (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
		expected_result0 = (0,1,2,3,7,8,9,0,4,5,6,7)
		expected_result0 = [x+0j for x in expected_result0]
		expected_result1 = (1,0,0)
		src0 = blocks.vector_source_c(src_data0)
		src1 = blocks.vector_source_b(src_data1)
		ofdm_sampler = grdab.ofdm_sampler(fft_len,3,5,3)
		v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex,fft_len)
		dst0 = blocks.vector_sink_c()
		dst1 = blocks.vector_sink_b()
		self.tb.connect(src0, (ofdm_sampler,0))
		self.tb.connect(src1, (ofdm_sampler,1))
		self.tb.connect((ofdm_sampler,0), v2s0, dst0)
		self.tb.connect((ofdm_sampler,1), dst1)
		self.tb.run()
		result_data0 = dst0.data()
		result_data1 = dst1.data()
		self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 6)
		self.assertEqual(result_data1, expected_result1)
Ejemplo n.º 43
0
    def __init__(self, args):
        gr.top_block.__init__(self, "Benchmark Copy", catch_exceptions=True)

        ##################################################
        # Variables
        ##################################################
        nsamples = args.samples
        veclen = args.veclen
        self.actual_samples = actual_samples = int(nsamples / veclen)
        num_blocks = args.nblocks

        ##################################################
        # Blocks
        ##################################################
        copy_blocks = []
        for i in range(num_blocks):
            copy_blocks.append(blocks.copy(gr.sizeof_gr_complex * veclen))

        # self.src = blocks.null_source(
        # gr.sizeof_gr_complex*veclen)
        # self.snk = blocks.null_sink(
        #     gr.sizeof_gr_complex*veclen)
        rollover = 1234
        input_data = [complex(i, -i) for i in range(rollover + 1)]
        self.src = blocks.vector_source_c(input_data, True)
        self.snk = bench.seqval_c(rollover)
        self.head_blk = blocks.head(gr.sizeof_gr_complex * veclen,
                                    actual_samples)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.head_blk, 0), (copy_blocks[0], 0))
        self.connect((self.src, 0), (self.head_blk, 0))

        for i in range(1, num_blocks):
            self.connect((copy_blocks[i - 1], 0), (copy_blocks[i], 0))

        self.connect((copy_blocks[num_blocks - 1], 0), (self.snk, 0))
Ejemplo n.º 44
0
    def test_qpsk_nonzeroevm(self):
        # set up fg
        expected_result = list(numpy.zeros((self.num_data, )))

        self.cons = cons = digital.constellation_qpsk().base()
        self.data = data = [
            random.randrange(len(cons.points())) for x in range(self.num_data)
        ]
        self.symbols = symbols = numpy.squeeze(
            [cons.map_to_points_v(i) for i in data])

        evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT)
        vso = blocks.vector_source_c(symbols, False, 1, [])
        mc = blocks.multiply_const_cc(3.0 + 2.0j)
        vsi = blocks.vector_sink_f()

        self.tb.connect(vso, mc, evm, vsi)
        self.tb.run()
        # check data

        output_data = vsi.data()
        self.assertNotEqual(expected_result, output_data)
Ejemplo n.º 45
0
    def setup_8psk0(self):
        self.tb = gr.top_block()

        # Build the constellation object
        arity = 8
        bps = 3
        constellation = digital.psk_constellation(8)

        # Create 8PSK data to pass to the demodulator
        src = blocks.vector_source_b(self.src_data_8psk)
        p2u = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        mod = digital.generic_mod(constellation, True, self.sps, True, self.eb)
        snk = blocks.vector_sink_c()

        tb = gr.top_block()
        tb.connect(src, p2u, mod, snk)
        tb.run()

        self.src = blocks.vector_source_c(snk.data())
        self.freq_recov = digital.fll_band_edge_cc(self.sps, self.eb,
                                                   self.fll_ntaps,
                                                   self.freq_bw)
        self.time_recov = digital.pfb_clock_sync_ccf(self.sps, self.timing_bw,
                                                     self.taps, self.nfilts,
                                                     self.nfilts // 2,
                                                     self.timing_max_dev)
        self.receiver = digital.constellation_receiver_cb(
            constellation.base(), self.phase_bw, self.fmin, self.fmax)
        self.diffdec = digital.diff_decoder_bb(arity)
        self.symbol_mapper = digital.map_bb(
            mod_codes.invert_code(constellation.pre_diff_code()))
        self.unpack = blocks.unpack_k_bits_bb(bps)
        self.snk = blocks.null_sink(gr.sizeof_char)

        self.tb.connect(self.src, self.freq_recov, self.time_recov,
                        self.receiver)
        self.tb.connect(self.receiver, self.diffdec, self.symbol_mapper,
                        self.unpack)
        self.tb.connect(self.unpack, self.snk)
Ejemplo n.º 46
0
    def test_02(self):
        tb = self.tb

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

        src = blocks.vector_source_c(data, False)
        op = blocks.moving_average_cc(100, 0.001)
        dst = blocks.vector_sink_c()

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

        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
Ejemplo n.º 47
0
    def __init__(self, args):
        gr.top_block.__init__(self, "Not titled yet", catch_exceptions=True)

        ##################################################
        # Variables
        ##################################################
        nsamples = args.samples
        veclen = args.veclen
        actual_samples = (veclen) * int(nsamples / veclen)
        num_blocks = args.nblocks
        mem_model = args.memmodel

        ##################################################
        # Blocks
        ##################################################
        ptblocks = []
        for i in range(num_blocks):
            ptblocks.append(trt.copy(veclen, mem_model))

        if (args.validate):
            rollover = 1234
            input_data = [complex(i, -i) for i in range(rollover + 1)]
            src = blocks.vector_source_c(input_data, True)
            self.snk = snk = bench.seqval_c(rollover)
        else:
            src = blocks.null_source(gr.sizeof_gr_complex * 1)
            snk = blocks.null_sink(gr.sizeof_gr_complex * 1)
        hd = blocks.head(gr.sizeof_gr_complex * 1, actual_samples)

        ##################################################
        # Connections
        ##################################################
        self.connect((hd, 0), (ptblocks[0], 0))
        self.connect((src, 0), (hd, 0))

        for i in range(1, num_blocks):
            self.connect((ptblocks[i - 1], 0), (ptblocks[i], 0))

        self.connect((ptblocks[num_blocks - 1], 0), (snk, 0))
Ejemplo n.º 48
0
    def test_iir_ccz_002(self):
        src_data = (1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j, 5 + 5j, 6 + 6j, 7 + 7j,
                    8 + 8j)
        expected_result = (4j, 12j, 24j, 40j, 60j, 84j, 112j, 144j)

        src = blocks.vector_source_c(src_data)
        op = filter.iir_filter_ccz([1], [1])
        dst = blocks.vector_sink_c()

        fftaps = (2 + 2j, )
        fbtaps = (0, 1)
        # FIXME: implement set_taps as generalized callback
        # op.set_taps(fftaps, fbtaps)
        op.set_fftaps(fftaps)
        op.set_fbtaps(fbtaps)

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

        result_data = dst.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
Ejemplo n.º 49
0
    def test_003_multiburst(self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.

        The channel is assumed AWGN for this test.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for _ in range(n_bursts):
            gap = [
                0,
            ] * random.randint(0, 2 * fft_len)
            tx_signal += \
                gap + \
                make_bpsk_burst(fft_len, cp_len, fft_len * random.randint(5, 23))
        # Very loose definition of SNR here
        snr = 20  # dB
        sigma = 10**(-snr / 10)
        # Add noise -- we don't use the channel model blocks, we want to keep
        # this test as self-contained as possible, and all randomness should
        # derive from random.seed() above
        complex_randn = \
            lambda N: (numpy.random.randn(N) + 1j * numpy.random.randn(N)) * sigma / numpy.sqrt(2)
        tx_signal += complex_randn(len(tx_signal))
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        self.tb.connect(blocks.vector_source_c(tx_signal), sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        self.assertEqual(n_bursts_detected,
                         n_bursts,
                         msg="Detection error (missed bursts): {}".format(
                             (numpy.sum(sink_detect.data()) - n_bursts)))
Ejemplo n.º 50
0
 def __init__(self,
         osmo_device,
         source,
         profile,
         name,
         tuning):
     gr.hier_block2.__init__(
         self, b'RX ' + str(name),
         gr.io_signature(0, 0, 0),
         gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
     )
     
     self.__osmo_device = osmo_device
     self.__source = source
     self.__profile = profile
     self.__name = name
     self.__tuning = tuning
     self.__antenna_type = EnumT({unicode(name): unicode(name) for name in self.__source.get_antennas()}, strict=True)
     
     self.connect(self.__source, self)
     
     self.__gains = Gains(source, self)
     
     # State of the source that there are no getters for, so we must keep our own copy of
     self.__track_dc_offset_mode = DCOffsetOff
     self.__track_iq_balance_mode = IQBalanceOff
     source.set_dc_offset_mode(self.__track_dc_offset_mode, ch)
     source.set_iq_balance_mode(self.__track_iq_balance_mode, ch)
     
     # Blocks
     self.__state_while_inactive = {}
     self.__placeholder = blocks.vector_source_c([])
     
     sample_rate = float(source.get_sample_rate())
     self.__signal_type = SignalType(
         kind='IQ',
         sample_rate=sample_rate)
     self.__usable_bandwidth = tuning.calc_usable_bandwidth(sample_rate)
Ejemplo n.º 51
0
    def test_002_t(self):
        print "test 2"
        # set up fg
        L = 2
        step_size = 1
        preamble = "IAM"
        threshold = 0.9
        num_frames = 1
        overlap = 4

        # very simple test data
        pil_symbol = (1, 2)
        payl_symbol = (3, 4)
        sof_noise = (0.3, 0.5, 0.2, 0.1)

        # this is basically the same as test 1 but with 2 subcarriers instead of one
        frame = concatenate(
            (sof_noise, pil_symbol, pil_symbol, sof_noise, payl_symbol))
        input_data = concatenate((sof_noise, frame, frame, sof_noise, frame,
                                  sof_noise, sof_noise, sof_noise))

        self.src = blocks.vector_source_c(input_data, vlen=1, repeat=False)
        self.framesync = fbmc.frame_sync_cc(L=L,
                                            frame_len=len(frame) / L,
                                            overlap=overlap,
                                            preamble=preamble,
                                            step_size=step_size,
                                            threshold=threshold)
        self.snk = blocks.vector_sink_c()

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

        self.tb.run()

        # check data
        data = self.snk.data()
        #print "data:", real(data)
        self.assertTrue(len(data) == len(frame) * 3)
Ejemplo n.º 52
0
    def test_000(self):
        N = 1000         # number of samples to use
        M = 5            # Number of channels
        fs = 1000        # baseband sampling rate
        ofs = M*fs       # output samp rate of interpolator

        taps = filter.firdes.low_pass_2(M, ofs, fs/4, fs/10,
                                        attenuation_dB=80,
                                        window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 123.456
        data = sig_source_c(fs, freq, 1, N)
        signal = blocks.vector_source_c(data)
        pfb = filter.pfb_interpolator_ccf(M, taps)
        snk = blocks.vector_sink_c()

        self.tb.connect(signal, pfb)
        self.tb.connect(pfb, snk)

        self.tb.run()

        Ntest = 50
        L = len(snk.data())

        # Phase rotation through the filters
        phase = 4.8870112969978994

        # Create a time scale
        t = map(lambda x: float(x)/ofs, xrange(0, L))

        # Create known data as complex sinusoids for the baseband freq
        # of the extracted channel is due to decimator output order.
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)
Ejemplo n.º 53
0
 def __init__(self, args):
     gr.top_block.__init__(self)
     if args.input_file is not None:
         src = blocks.file_source(gr.sizeof_gr_complex,
                                  args.filename,
                                  repeat=True)
     else:
         src = blocks.vector_source_c((.5, ) * int(1e6) * 2, repeat=True)
     # Setup USRP
     self.usrp = uhd.usrp_sink(args.args, uhd.stream_args('fc32'),
                               "packet_len")
     if args.spec:
         self.usrp.set_subdev_spec(args.spec, 0)
     if args.antenna:
         self.usrp.set_antenna(args.antenna, 0)
     self.usrp.set_samp_rate(args.rate)
     # Gain is set in the hopper block
     if not args.gain:
         gain_range = self.usrp.get_gain_range()
         args.gain = float(gain_range.start() + gain_range.stop()) / 2.0
     print("-- Setting gain to {} dB".format(args.gain))
     if not self.usrp.set_center_freq(args.freq):
         print('[ERROR] Failed to set base frequency.')
         exit(1)
     hopper_block = FrequencyHopperSrc(
         args.num_bursts,
         args.num_channels,
         args.freq_delta,
         args.freq,
         args.dsp,
         args.samp_per_burst,
         1.0,
         args.hop_time / 1000.,
         args.post_tuning,
         args.gain,
         args.verbose,
     )
     self.connect(src, hopper_block, self.usrp)
Ejemplo n.º 54
0
 def test_002_with_offset(self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = range(1, 16)
     tx_symbols = (0, 0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0,
                   7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13,
                   1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0)
     carr_offset = 1  # Compare this with tx_symbols from the previous test
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     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_symbols, False, fft_len,
                                  (tag, offsettag))
     sink = blocks.vector_sink_c()
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0,
                                              "ofdm_sync_carr_offset",
                                              False)
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 2)
     for tag in sink.tags():
         if pmt.symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.to_long(tag.value),
                              n_syms * len(occupied_carriers[0]))
Ejemplo n.º 55
0
 def __init__(self,
         osmo_device,
         source,
         profile,
         name,
         tuning):
     gr.hier_block2.__init__(
         self, 'RX ' + name,
         gr.io_signature(0, 0, 0),
         gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
     )
     
     self.__osmo_device = osmo_device
     self.__source = source
     self.__profile = profile
     self.__name = name
     self.__tuning = tuning
     self.__antenna_type = Enum({unicode(name): unicode(name) for name in self.__source.get_antennas()}, strict=True)
     
     self.connect(self.__source, self)
     
     self.__gains = Gains(source)
     
     # Misc state
     self.dc_state = DCOffsetOff
     self.iq_state = IQBalanceOff
     source.set_dc_offset_mode(self.dc_state, ch)  # no getter, set to known state
     source.set_iq_balance_mode(self.iq_state, ch)  # no getter, set to known state
     
     # Blocks
     self.__state_while_inactive = {}
     self.__placeholder = blocks.vector_source_c([])
     
     sample_rate = float(source.get_sample_rate())
     self.__signal_type = SignalType(
         kind='IQ',
         sample_rate=sample_rate)
     self.__usable_bandwidth = tuning.calc_usable_bandwidth(sample_rate)
Ejemplo n.º 56
0
    def test_002_cc(self):
        N = 10000        # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        freq = 10
        data = sig_source_c(fs, freq, 1, N)
        signal = blocks.vector_source_c(data)
        op = filter.mmse_resampler_cc(0.0, rrate)
        snk = blocks.vector_sink_c()

        self.tb.connect(signal, op, snk)
        self.tb.run()

        Ntest = 5000
        L = len(snk.data())
        t = [float(x) / (fs / rrate) for x in range(L)]

        phase = 0.1884
        expected_data = [
            math.cos(
                2. *
                math.pi *
                freq *
                x +
                phase) +
            1j *
            math.sin(
                2. *
                math.pi *
                freq *
                x +
                phase) for x in t]

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(
            expected_data[-Ntest:], dst_data[-Ntest:], 3)
Ejemplo n.º 57
0
    def test_ensure_empty_string_global_meta_setting(self):
        '''Ensure empty strings get propagated'''
        N = 1000
        samp_rate = 200000

        data = sig_source_c(samp_rate, 1000, 1, N)
        src = blocks.vector_source_c(data)

        description = ""
        author = ""
        file_license = ""
        hardware = ""
        data_file, json_file = self.temp_file_names()
        file_sink = sigmf.sink("cf32_le", data_file)

        file_sink.set_global_meta("core:sample_rate", samp_rate)
        file_sink.set_global_meta("core:description", description)
        file_sink.set_global_meta("core:author", author)
        file_sink.set_global_meta("core:sample_rate", author)
        file_sink.set_global_meta("core:license", file_license)
        file_sink.set_global_meta("core:hw", hardware)

        # build flowgraph here
        tb = gr.top_block()
        tb.connect(src, file_sink)
        tb.run()
        tb.wait()

        # check that the metadata matches up
        with open(json_file, "r") as f:
            meta_str = f.read()
            meta = json.loads(meta_str)

            # Check global meta
            assert meta["global"]["core:description"] == ""
            assert meta["global"]["core:author"] == ""
            assert meta["global"]["core:license"] == ""
            assert meta["global"]["core:hw"] == ""
    def test_mode3_length2(self):
        # set up fg

        total_segments = 1
        mode = 3
        length = 2
        total_carriers = total_segments * 96 * 2**(mode - 1)
        deinterleaver = isdbt.time_deinterleaver_1seg(mode, length)

        how_many = 1000
        # the input data are how_many vector (each entry with the same number ranging from 1 to how_many)
        # that increases by one with each new vector
        src_data = [[i + 1] * total_carriers for i in range(how_many)]
        src_data = [item for sublist in src_data for item in sublist]

        src = blocks.vector_source_c(src_data, False, total_carriers)
        dst = blocks.vector_sink_c(total_carriers)

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

        actual_result = dst.data()

        for carrier in range(total_carriers):
            # in each carrier, I should have an increasing number as an output, preceded by
            # as many zeros as the delay correponding to the particular carrier
            mi = (5 * carrier) % 96
            delay = length * (95 - mi)
            carrier_actual_result = []
            for i in range(how_many):
                carrier_actual_result.append(actual_result[i * total_carriers +
                                                           carrier])

            carrier_expected_result = [0] * min(how_many, delay)
            carrier_expected_result += range(1, how_many - delay + 1)
            self.assertFloatTuplesAlmostEqual(carrier_expected_result,
                                              carrier_actual_result)
Ejemplo n.º 59
0
    def test_003_legacy_small(self):
        multiple = 10
        L = 4
        taps = np.append(np.ones(L), 0.5 * np.ones(L))

        # test data!
        d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex)

        # initialize fg
        smt = fbmc.rx_polyphase_cvc(taps, L)
        self.src = blocks.vector_source_c(d, vlen=1)
        self.snk = blocks.vector_sink_c(vlen=L)

        # old chain
        self.com = fbmc.input_commutator_cvc(L)
        self.pfb = fbmc.polyphase_filterbank_vcvc(L, taps)
        self.fft = fft.fft_vcc(L, False, (), False, 1)
        self.snkold = blocks.vector_sink_c(vlen=L)

        self.tb.connect(self.src, self.com, self.pfb, self.fft, self.snkold)
        self.tb.connect(self.src, smt, self.snk)
        self.tb.run()

        # check data
        res = self.snk.data()
        resmatrix = np.array(res).reshape((-1, L)).T

        old = self.snkold.data()
        oldmatrix = np.array(old).reshape((-1, L)).T

        print np.array(smt.filterbank_taps())
        print "\nresult"
        print resmatrix
        print "\nold"
        print oldmatrix

        self.assertComplexTuplesAlmostEqual(oldmatrix.flatten(),
                                            resmatrix.flatten())
Ejemplo n.º 60
0
    def test_002(self):
        data = list(range(1, 9))

        self.src = blocks.vector_source_c(data)
        self.p1 = blocks.ctrlport_probe_c("aaa", "C++ exported variable")
        self.p2 = blocks.ctrlport_probe_c("bbb", "C++ exported variable")
        probe_name = self.p2.alias()

        self.tb.connect(self.src, self.p1)
        self.tb.connect(self.src, self.p2)
        self.tb.start()

        # Probes return complex values as list of floats with re, im
        # Imaginary parts of this data set are 0.
        expected_result = [1, 2, 3, 4, 5, 6, 7, 8]

        # Make sure we have time for flowgraph to run
        time.sleep(0.1)

        # Get available endpoint
        ep = gr.rpcmanager_get().endpoints()[0]
        hostname = re.search(r"-h (\S+|\d+\.\d+\.\d+\.\d+)", ep).group(1)
        portnum = re.search(r"-p (\d+)", ep).group(1)

        # Initialize a simple ControlPort client from endpoint
        from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient
        radiosys = GNURadioControlPortClient(hostname,
                                             portnum,
                                             rpcmethod='thrift')
        radio = radiosys.client

        # Get all exported knobs
        ret = radio.getKnobs([probe_name + "::bbb"])
        for name in list(ret.keys()):
            result = ret[name].value
            self.assertEqual(result, expected_result)

        self.tb.stop()