Exemplo n.º 1
0
    def setUp(self):
        self.tb = gr.top_block()

        self.pbch = lte.decode_pbch_vcvf()
        """
        This hierarchical block consists of the following blocks
        lte.pre_decoder_vcvc(1, style)
        lte.pre_decoder_vcvc(2, style)
        lte.layer_demapper_vcvc(1, style)
        lte.layer_demapper_vcvc(2, style)
        gr.interleave(240*gr.sizeof_gr_complex)
        lte.qpsk_soft_demod_vcvf()
        lte.descrambling_vfvf()
        """

        self.src0 = gr.vector_source_c([0] * 240, False, 240)
        self.src1 = gr.vector_source_c([0] * 240, False, 240)
        self.src2 = gr.vector_source_c([0] * 240, False, 240)

        self.snk = gr.vector_sink_f(120)

        self.tb.connect(self.src0, (self.pbch, 0))
        self.tb.connect(self.src1, (self.pbch, 1))
        self.tb.connect(self.src2, (self.pbch, 2))
        self.tb.connect(self.pbch, self.snk)
Exemplo n.º 2
0
 def test_add_fc32(self):
     tb = gr.top_block()
     src0 = gr.vector_source_c([1, 3j, 5, 7j, 9], False)
     src1 = gr.vector_source_c([0, 2j, 4, 6j, 8], False)
     adder = add_2_fc32_1_fc32()
     sink = gr.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))
Exemplo n.º 3
0
 def test_add_fc32(self):
     tb = gr.top_block()
     src0 = gr.vector_source_c([1, 3j, 5, 7j, 9], False)
     src1 = gr.vector_source_c([0, 2j, 4, 6j, 8], False)
     adder = add_2_fc32_1_fc32()
     sink = gr.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))
    def test_000(self):
        src_data0 = (-2 - 2j, -1 - 1j, -2 + 2j, -1 + 1j, 2 - 2j, 1 - 1j,
                     2 + 2j, 1 + 1j, 0 + 0j)
        src_data1 = (-3 - 3j, -4 - 4j, -3 + 3j, -4 + 4j, 3 - 3j, 4 - 4j,
                     3 + 3j, 4 + 4j, 0 + 0j)

        exp_data = (12 + 0j, 8 + 0j, 12 + 0j, 8 + 0j, 12 + 0j, 8 + 0j, 12 + 0j,
                    8 + 0j, 0 + 0j)
        src0 = gr.vector_source_c(src_data0)
        src1 = gr.vector_source_c(src_data1)
        op = gr.multiply_conjugate_cc()
        self.help_cc((src_data0, src_data1), exp_data, op)
Exemplo n.º 5
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 = gr.vector_source_c([10e6*(random.random() + 1j*random.random()) for i in range(0,100000)],True)
			self.ns_simulate = gr.vector_source_c([0.01]*dp.ns_length+[1]*dp.symbols_per_frame*dp.symbol_length,1)
			self.mult = gr.multiply_cc() # simulate null symbols ...
			self.src = gr.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 = gr.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 = gr.nop(gr.sizeof_char*dp.num_carriers/4)
		self.nop1 = gr.nop(gr.sizeof_char)
		self.connect((self.dab_demod,0),self.nop0)
		self.connect((self.dab_demod,1),self.nop1)
Exemplo n.º 6
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        print "qa_pbch_demux_vcvc START"
        
        # Input 1, PBCH frame
        mod=scipy.io.loadmat('/home/demel/exchange/matlab_frame.mat') 
        mat_u1=tuple(mod['frame_mat'].flatten())
        mat_d=range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx]=val
        intu1=tuple(mat_d)
        
        # Input 2, CE values for antenna port 1
        mod=scipy.io.loadmat('/home/demel/exchange/matlab_ce_frame_mat1.mat')
        mat_u2=tuple(mod['ce_frame_mat1'].flatten())
        mat_d=range(len(mat_u2))
        for idx, val in enumerate(mat_u2):
            mat_d[idx]=val
        intu2=tuple(mat_d)

        # Input 2, CE values for antenna port 1
        mod=scipy.io.loadmat('/home/demel/exchange/matlab_ce_frame_mat2.mat')
        mat_u2=tuple(mod['ce_frame_mat2'].flatten())
        mat_d=range(len(mat_u2))
        for idx, val in enumerate(mat_u2):
            mat_d[idx]=val
        intu3=tuple(mat_d)

        
        self.src1 = gr.vector_source_c( intu1, False, 72)
        self.src2 = gr.vector_source_c( intu2, False, 72)
        self.src3 = gr.vector_source_c( intu3, False, 72)
        
        cell_id = 124
        N_rb_dl = 6
        self.demux = lte_swig.pbch_demux_vcvc(N_rb_dl) # cell_id,
        self.demux.set_cell_id(cell_id)
        
        self.snk1 = gr.vector_sink_c(240)
        self.snk2 = gr.vector_sink_c(240)
        self.snk3 = gr.vector_sink_c(240)
        
        self.tb.connect(self.src1,(self.demux,0) )
        self.tb.connect( (self.demux,0),self.snk1)
        self.tb.connect(self.src2,(self.demux,1) )
        self.tb.connect( (self.demux,1),self.snk2)
        self.tb.connect(self.src3,(self.demux,2) )
        self.tb.connect( (self.demux,2),self.snk3)
    def setUp(self):
        self.tb = gr.top_block()

        print "qa_pbch_demux_vcvc START"

        # Input 1, PBCH frame
        mod = scipy.io.loadmat('/home/demel/exchange/matlab_frame.mat')
        mat_u1 = tuple(mod['frame_mat'].flatten())
        mat_d = range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx] = val
        intu1 = tuple(mat_d)

        # Input 2, CE values for antenna port 1
        mod = scipy.io.loadmat('/home/demel/exchange/matlab_ce_frame_mat1.mat')
        mat_u2 = tuple(mod['ce_frame_mat1'].flatten())
        mat_d = range(len(mat_u2))
        for idx, val in enumerate(mat_u2):
            mat_d[idx] = val
        intu2 = tuple(mat_d)

        # Input 2, CE values for antenna port 1
        mod = scipy.io.loadmat('/home/demel/exchange/matlab_ce_frame_mat2.mat')
        mat_u2 = tuple(mod['ce_frame_mat2'].flatten())
        mat_d = range(len(mat_u2))
        for idx, val in enumerate(mat_u2):
            mat_d[idx] = val
        intu3 = tuple(mat_d)

        self.src1 = gr.vector_source_c(intu1, False, 72)
        self.src2 = gr.vector_source_c(intu2, False, 72)
        self.src3 = gr.vector_source_c(intu3, False, 72)

        cell_id = 124
        N_rb_dl = 6
        self.demux = lte_swig.pbch_demux_vcvc(N_rb_dl)  # cell_id,
        self.demux.set_cell_id(cell_id)

        self.snk1 = gr.vector_sink_c(240)
        self.snk2 = gr.vector_sink_c(240)
        self.snk3 = gr.vector_sink_c(240)

        self.tb.connect(self.src1, (self.demux, 0))
        self.tb.connect((self.demux, 0), self.snk1)
        self.tb.connect(self.src2, (self.demux, 1))
        self.tb.connect((self.demux, 1), self.snk2)
        self.tb.connect(self.src3, (self.demux, 2))
        self.tb.connect((self.demux, 2), self.snk3)
Exemplo n.º 8
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_swig.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 = gr.vector_source_c(data, False)
        self.snk = gr.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_fir_filter_ccf_001(self):
     self.generate_ccf_source()
     expected_data = ((0.001697700354270637 + 0.004312471952289343j),
                      (0.003520616563037038 - 0.003014103975147009j),
                      (0.004252811893820763 - 0.008337559178471565j),
                      (0.0030743128154426813 - 0.010262271389365196j),
                      (0.0007344777695834637 - 0.007861139252781868j),
                      (-0.0011067686136811972 - 0.0028924935031682253j),
                      (-0.002371778478845954 + 0.0019914964213967323j),
                      (-0.003023319412022829 + 0.005717850290238857j),
                      (-0.0021738125942647457 + 0.007211698684841394j),
                      (-0.0004628606839105487 + 0.005501383915543556j),
                      (0.0007428556564264 + 0.0019867848604917526j),
                      (0.001634795218706131 - 0.0013514887541532516j),
                      (0.002205110155045986 - 0.00402155052870512j),
                      (0.0015480631263926625 - 0.005179159343242645j),
                      (0.00026722141774371266 - 0.003887997241690755j),
                      (-0.0004911854630336165 - 0.0013578246580436826j),
                      (-0.0011226939968764782 + 0.0009080552263185382j),
                      (-0.0016229727771133184 + 0.0028335191309452057j),
                      (-0.0010890064295381308 +
                       0.0037298379465937614j), (-0.00012392725329846144 +
                                                 0.0027196139562875032j))
     src = gr.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 10
0
 def transform(self, src_data):
     SRC = gr.vector_source_c(src_data, False)
     EQU = gr.cma_equalizer_cc(4, 1.0, .001)
     DST = gr.vector_sink_c()
     self.tb.connect(SRC, EQU, DST)
     self.tb.run()
     return DST.data()
Exemplo n.º 11
0
 def setUp (self):
 
     #print os.getpid()
     #raw_input("press the any key")
     
     self.tb = gr.top_block ()
     
     offset = 43223  #sample15 = 21839 #sample20 = 43223
     fftl = 512
     cpl = 144*fftl/2048
     cpl0 = 160*fftl/2048
     slotl = 7*fftl+6*cpl+cpl0
     cell_id = 124
     N_rb_dl = 6
     
     mod=scipy.io.loadmat('/home/demel/exchange/matlab_test_first_freq.mat') 
     mat_u1=tuple(mod['test'].flatten())
     mat_d=range(len(mat_u1))
     for idx, val in enumerate(mat_u1):
         mat_d[idx]=val
     intu=tuple(mat_d[0:slotl*60])
     
     self.src  = gr.vector_source_c(intu,False,1)
     self.tag  = lte.tag_symbol_cc(offset,fftl)
     #self.head = gr.head(gr.sizeof_gr_complex,70000)
     self.sel = lte.sss_selector_cvc(fftl)
     self.vtos = gr.vector_to_stream(gr.sizeof_gr_complex,512)
     self.snk = gr.vector_sink_c(1)
     
     self.tb.connect(self.src,self.tag,self.sel,self.vtos,self.snk)#,self.head
Exemplo n.º 12
0
 def test_001b_simple_skip_nothing(self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1, ) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1, ) * fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.data())
Exemplo n.º 13
0
    def test_003_multiburst(self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1) * 2) - 1
                           for x in range(fft_len / 2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = gr.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq = gr.vector_sink_f()
        sink_detect = gr.vector_sink_b()
        channel = gr.channel_model(0.005)
        self.tb.connect(gr.vector_source_c(tx_signal), channel, 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())
        # We allow for one false alarm or missed burst
        self.assertTrue(
            abs(n_bursts_detected - n_bursts) <= 1,
            msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts))
Exemplo n.º 14
0
   def __init__(self, dbW, pfa, pfd):
      gr.top_block.__init__(self)

      # Parameters
      samp_rate               = 2e6
      fft_size                = 4096
      samples_per_band        = 16
      tcme                    = 1.9528
      output_pfa              = True
      debug_stats             = False
      primary_user_location   = 0
      useless_bw              = 0.0    # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used.
      histogram               = False
      nframes_to_check        = 1
      nframes_to_average      = 1
      downconverter           = 1
      nsegs_to_check          = 6

      # Create AWGN noise
      noise = awgn(fft_size, dbW)

		# Blocks
      src = gr.vector_source_c(noise)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, fftb, self.ss, self.sink)
Exemplo n.º 15
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = gr.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 = gr.vector_source_c(data.tolist(), False)
        self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = gr.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = gr.vector_sink_c()
        self.vsnk_fll = gr.vector_sink_c()
        self.vsnk_frq = gr.vector_sink_f()
        self.vsnk_phs = gr.vector_sink_f()
        self.vsnk_err = gr.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_fir_filter_ccf_001(self):
     self.generate_ccf_source()
     expected_data = ((0.001697700354270637+0.004312471952289343j),
                      (0.003520616563037038-0.003014103975147009j),
                      (0.004252811893820763-0.008337559178471565j),
                      (0.0030743128154426813-0.010262271389365196j),
                      (0.0007344777695834637-0.007861139252781868j),
                      (-0.0011067686136811972-0.0028924935031682253j),
                      (-0.002371778478845954+0.0019914964213967323j),
                      (-0.003023319412022829+0.005717850290238857j),
                      (-0.0021738125942647457+0.007211698684841394j),
                      (-0.0004628606839105487+0.005501383915543556j),
                      (0.0007428556564264+0.0019867848604917526j),
                      (0.001634795218706131-0.0013514887541532516j),
                      (0.002205110155045986-0.00402155052870512j),
                      (0.0015480631263926625-0.005179159343242645j),
                      (0.00026722141774371266-0.003887997241690755j),
                      (-0.0004911854630336165-0.0013578246580436826j),
                      (-0.0011226939968764782+0.0009080552263185382j),
                      (-0.0016229727771133184+0.0028335191309452057j),
                      (-0.0010890064295381308+0.0037298379465937614j),
                      (-0.00012392725329846144+0.0027196139562875032j))
     src = gr.vector_source_c(self.src_data)
     op  = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
Exemplo n.º 17
0
    def __init__(self, vlen, channel_block, delay):
        gr.hier_block2.__init__(
            self, 'apply_channel_to_vect',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * vlen))

        self.vlen = vlen
        self.channel_block = channel_block
        self.delay = delay

        pad_len = self.vlen + self.delay * 2

        if (delay > 0):
            self.padding = gr.vector_source_c((0, ) * (delay * 2), True,
                                              delay * 2)
            self.pad_cat = mlse.vector_concat_vv(
                vlen * gr.sizeof_gr_complex, gr.sizeof_gr_complex * 2 * delay)
            self.connect(self, self.pad_cat)
            self.connect(self.padding, (self.pad_cat, 1))
        else:
            self.pad_cat = self

        self.tostream = gr.vector_to_stream(gr.sizeof_gr_complex, pad_len)
        self.connect(self.pad_cat, self.tostream)

        # connect channel
        self.connect(self.tostream, self.channel_block)

        self.tovector = gr.stream_to_vector(gr.sizeof_gr_complex, pad_len)
        self.connect(self.channel_block, self.tovector)

        # cut out the proper part
        self.trim = mlse.vector_slice_vv(gr.sizeof_gr_complex, pad_len, delay,
                                         vlen)
        self.connect(self.tovector, self.trim, self)
Exemplo n.º 18
0
    def setUp(self):
        self.tb = gr.top_block()

        offset = 43223  #sample15 = 21839 #sample20 = 43223
        fftl = 512
        cpl = 144 * fftl / 2048
        cpl0 = 160 * fftl / 2048
        slotl = 7 * fftl + 6 + cpl + cpl0
        cell_id = 124
        N_rb_dl = 6

        mod = scipy.io.loadmat(
            '/home/demel/exchange/matlab_test_first_freq.mat')
        mat_u1 = tuple(mod['test'].flatten())
        mat_d = range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx] = val
        intu = tuple(mat_d[0:100 * slotl])

        self.src = gr.vector_source_c(intu, False, 1)
        self.tag = lte_swig.tag_symbol_cc(offset, fftl)

        self.stag = lte_swig.sss_tagging_cc(fftl)

        self.snk = gr.vector_sink_c(1)

        self.tb.connect(self.src, self.tag, self.stag, self.snk)
Exemplo n.º 19
0
 def test_006_channel_and_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.pmt_c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(
         sink.data(),
         tuple(
             numpy.multiply(shift_tuple(data_symbol, carr_offset),
                            channel)))
Exemplo n.º 20
0
 def test_003_channel_no_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     sink_chanest = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset),
                      tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value),
                              channel)
     self.assertEqual(sink_chanest.data(), channel)
Exemplo n.º 21
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
        ma_len = 1
        window = hamming(fft_len)

        src_data = (1,) * ((ma_len + 1) * fft_len)
        src = gr.vector_source_c(src_data, False)
        welch = specest.welch(fft_len, overlap, ma_len, False, window)
        sink = gr.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

        self.assertAlmostEqual(power_est, 1, 5)
Exemplo n.º 22
0
 def test_003_channel_no_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j,  1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     sink_chanest = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
     self.assertEqual(sink_chanest.data(), channel)
Exemplo n.º 23
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     ############################
     # define variables for test purposes
     self.fftl = fftl = 2048
     N_rb_dl = 6
     self.N_id = N_id = 124
     N_id_1 = N_id/3
     N_id_2 = N_id%3
     
     # This blocks are needed as "dummy" references
     self.tag = lte_swig.sss_tagging2_vcvc(fftl)
     self.eq = lte_swig.linear_OFDM_estimator_vcvc(N_rb_dl)
     self.demux = lte_swig.pbch_demux_vcvc(N_rb_dl)
     self.descr = lte_swig.descrambling_vfvf()
     self.daemon = lte_swig.cell_id_daemon(self.eq, self.demux, self.descr)
     
     #Source
     data = range(2*fftl)
     self.src = gr.vector_source_c(data, False, fftl)        
     # UUT
     self.calc = lte_swig.sss_calc2_vc(self.tag, self.daemon, fftl)
     
     self.tb.connect(self.src, self.calc)
Exemplo n.º 24
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan= gr.multiply_const_vcc(channel)
     noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude)
     add = gr.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = gr.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.pmt_c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
Exemplo n.º 25
0
    def setUp(self):
        self.tb = gr.top_block()

        #print os.getpid()
        #raw_input("Press the ANY key!")

        offset = 43223  #sample15 = 21839 #sample20 = 43223
        fftl = 512
        cell_id = 124
        N_rb_dl = 6

        mod = scipy.io.loadmat(
            '/home/demel/exchange/matlab_test_first_freq.mat')
        mat_u1 = tuple(mod['test'].flatten())
        mat_d = range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx] = val
        intu = tuple(mat_d[0:100000])

        self.src = gr.vector_source_c(intu, False, 1)
        #self.tag  = lte_swig.tag_symbol_cc(offset,fftl)

        self.tagp = lte_swig.pss_tagging_cc(fftl)
        self.snk = gr.vector_sink_c(1)

        self.tb.connect(self.src, self.tagp, self.snk)  #self.tag,
Exemplo n.º 26
0
 def test_002_freq(self):
     """ Add a fine frequency offset and see if that get's detected properly """
     fft_len = 32
     cp_len = 4
     # This frequency offset is normalized to rads, i.e. \pi == f_s/2
     max_freq_offset = 2 * numpy.pi / fft_len  # Otherwise, it's coarse
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1) * 2) - 1
                    for x in range(fft_len / 2)] * 2
     tx_signal = sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     mult = gr.multiply_cc()
     add = gr.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     channel = gr.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     sink_freq = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     self.tb.connect(gr.vector_source_c(tx_signal), channel, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     phi_hat = sink_freq.data()[sink_detect.data().index(1)]
     est_freq_offset = 2 * phi_hat / fft_len
     self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)
Exemplo n.º 27
0
    def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram):
        gr.top_block.__init__(self)

        # Constants
        samp_rate = 2.4e6
        samples_per_band = 16
        tcme = 1.9528
        output_pfa = True
        debug_stats = False
        self.histogram = plot_histogram
        primary_user_location = 5
        mu = 0
        fft_size = 4096
        nframes_to_check = 1
        nframes_to_average = 1
        downconverter = 1

        src_data = self.generateRandomSignalSource(
            dBm, fft_size, mu, nframes_to_check * nframes_to_average)

        # Blocks
        src = gr.vector_source_c(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)),
                           False, 1)
        self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size,
                                            samples_per_band, pfd, pfa, tcme,
                                            output_pfa, debug_stats,
                                            primary_user_location, useless_bw,
                                            self.histogram, nframes_to_check,
                                            nframes_to_average, downconverter)
        self.sink = gr.vector_sink_f()

        # Connections
        self.connect(src, s2v, fftb, self.ss, self.sink)
 def test_001_simple (self):
     """ Very simple functionality testing """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1,) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
     for tag in sink.tags():
         self.assertEqual(pmt.pmt_symbol_to_string(tag.key), len_tag_key)
         self.assertEqual(pmt.pmt_to_long(tag.value), n_syms)
Exemplo n.º 29
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = gr.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 = gr.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = filter.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = gr.vector_sink_c()
        self.vsnk_fll = gr.vector_sink_c()
        self.vsnk_frq = gr.vector_sink_f()
        self.vsnk_phs = gr.vector_sink_f()
        self.vsnk_err = gr.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)
Exemplo n.º 30
0
    def test_complex_to_arg(self):
        pi = math.pi
        input_data = (0, pi / 6, pi / 4, pi / 2, 3 * pi / 4, 7 * pi / 8,
                      -pi / 6, -pi / 4, -pi / 2, -3 * pi / 4, -7 * pi / 8)

        expected_result = (
            0.0,  # 0
            0.52382522821426392,  # pi/6
            0.78539806604385376,  # pi/4
            1.5707963705062866,  # pi/2
            2.3561947345733643,  # 3pi/4
            2.7491819858551025,  # 7pi/8
            -0.52382522821426392,  # -pi/6
            -0.78539806604385376,  # -pi/4
            -1.5707963705062866,  # -pi/2
            -2.3561947345733643,  # -3pi/4
            -2.7491819858551025)  # -7pi/8

        src_data = tuple([math.cos(x) + math.sin(x) * 1j for x in input_data])
        src = gr.vector_source_c(src_data)
        op = gr.complex_to_arg()
        dst = gr.vector_sink_f()
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()
        actual_result = dst.data()

        self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 3)
Exemplo n.º 31
0
    def __init__(self,
                 N,
                 sps,
                 rolloff,
                 ntaps,
                 bw,
                 noise,
                 foffset,
                 toffset,
                 poffset,
                 mode=0):
        gr.top_block.__init__(self)

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

        gain = 2 * scipy.pi / 100.0
        nfilts = 32
        rrc_taps_rx = gr.firdes.root_raised_cosine(nfilts, sps * nfilts, 1.0,
                                                   rolloff, ntaps * nfilts)

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

        self.src = gr.vector_source_c(data.tolist(), False)
        self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = gr.channel_model(noise, foffset, toffset)
        self.off = gr.fractional_interpolator_cc(0.20, 1.0)

        if mode == 0:
            self.clk = gr.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts,
                                             nfilts // 2, 3.5)
            self.taps = self.clk.get_taps()
            self.dtaps = self.clk.get_diff_taps()

            self.vsnk_err = gr.vector_sink_f()
            self.vsnk_rat = gr.vector_sink_f()
            self.vsnk_phs = gr.vector_sink_f()

            self.connect((self.clk, 1), self.vsnk_err)
            self.connect((self.clk, 2), self.vsnk_rat)
            self.connect((self.clk, 3), self.vsnk_phs)

        else:  # mode == 1
            mu = 0.5
            gain_mu = 0.1
            gain_omega = 0.25 * gain_mu * gain_mu
            omega_rel_lim = 0.02
            self.clk = digital.clock_recovery_mm_cc(sps, gain_omega, mu,
                                                    gain_mu, omega_rel_lim)

            self.vsnk_err = gr.vector_sink_f()

            self.connect((self.clk, 1), self.vsnk_err)

        self.vsnk_src = gr.vector_sink_c()
        self.vsnk_clk = gr.vector_sink_c()

        self.connect(self.src, self.rrc, self.chn, self.off, self.clk,
                     self.vsnk_clk)
        self.connect(self.off, self.vsnk_src)
 def test_fir_filter_ccc_002(self):
     self.generate_ccc_source()
     expected_data = (
         (-0.000650451984257 + 0.00120697380044j),
         (-9.59713361226e-05 + 0.00102412770502j),
         (0.000958710326813 - 0.00145424995571j), (0.000901343999431 -
                                                   0.00290832063183j),
         (-0.000822560978122 + 0.000296717538731j), (-0.00211223773658 +
                                                     0.00519825471565j),
         (-0.00037001183955 + 0.00358242215589j), (0.00327983591706 -
                                                   0.00616005761549j),
         (0.00356886954978 - 0.0117237549275j), (-0.00328874029219 +
                                                 0.00182871113066j),
         (-0.0139285130426 + 0.0320657044649j), (-0.0198133718222 +
                                                 0.0562113076448j),
         (-0.0157803222537 + 0.0530290603638j), (-0.00550725404173 +
                                                 0.0255754813552j),
         (0.00252919178456 - 0.00232240976766j), (0.00368427345529 -
                                                  0.0114002330229j),
         (0.000506620621309 - 0.00402843113989j), (-0.00180401885882 +
                                                   0.00427213776857j),
         (-0.00122803344857 + 0.00427243299782j), (0.000414476031438 -
                                                   0.000383919978049j))
     src = gr.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccc(4, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 33
0
    def transform(self, src_data):
	SRC = gr.vector_source_c(src_data, False)
	EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1)
	DST = gr.vector_sink_c()
	self.tb.connect(SRC, EQU, DST)
	self.tb.run()
	return DST.data()
   def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      self.histogram = plot_histogram
      primary_user_location = 5
      mu = 0
      fft_size = 4096
      nframes_to_check = 1
      nframes_to_average = 1
      downconverter = 1

      src_data = self.generateRandomSignalSource(dBm, fft_size, mu, nframes_to_check*nframes_to_average)

		# Blocks
      src = gr.vector_source_c(src_data)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,self.histogram,nframes_to_check,nframes_to_average,downconverter)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, fftb, self.ss, self.sink)
Exemplo n.º 35
0
  def test_007_vector_sampler(self):
    data = range(1,577,1) # 1..576
    trigger = numpy.concatenate([[0]*575,[1]])
    blocks = 10000
    expected = data[64:577]
    assert(len(expected)==512)
    expected = numpy.concatenate([expected*blocks])
    assert(len(expected) == 512*blocks)

    src = gr.vector_source_c(data,True)
    src2 = gr.vector_source_b(trigger.tolist(),True)
    dst = gr.vector_sink_c()
    sampler = ofdm.vector_sampler(gr.sizeof_gr_complex,512)
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex,512)

    self.fg.connect(src, (sampler,0))
    self.fg.connect(src2,gr.head(gr.sizeof_char,blocks*576), (sampler,1))
    self.fg.connect(sampler, v2s, dst)

    self.fg.run()
    #self.assertEqual(numpy.array(expected,numpy.Complex), numpy.array(dst.data(), numpy.Complex))
    if numpy.array(expected).all() != numpy.array(dst.data()).all():
      print "up"
      print len(expected),len(dst.data())
      vec = dst.data()
      for i in range(min(len(expected),len(dst.data()))):
        if vec[i] != expected[i]:
          print "e at ",i
Exemplo n.º 36
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_swig.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_rel_lim)

        data = 100 * [complex(1, 1)]
        self.src = gr.vector_source_c(data, False)
        self.snk = gr.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)
Exemplo n.º 37
0
    def test_001_t (self):
        """
        pretty simple
        """
        fft_len = 6
        tx_symbols = (1, 2, 3)
        pilot_symbols = ((1j,),)
        occupied_carriers = ((0, 1, 2),)
        pilot_carriers = ((3,),)
        expected_result = (1, 2, 3, 1j, 0, 0)
        mtu = 128
        tag_name = "len"
        tag = gr.gr_tag_t()
        tag.offset = 0
        tag.key = pmt.pmt_string_to_symbol(tag_name)
        tag.value = pmt.pmt_from_long(len(tx_symbols))
        src = gr.vector_source_c(tx_symbols, (tag,), False, 1)
        alloc = ofdm.carrier_allocator_cvc(fft_len,
                       occupied_carriers,
                       pilot_carriers,
                       pilot_symbols,
                       tag_name)
        sink = gr.vector_sink_c(fft_len)

        self.tb.connect(src, alloc, sink)
        self.tb.run ()
        self.assertEqual(sink.data(), expected_result)
Exemplo n.º 38
0
   def __init__(self, dBm, pfa, pfd, nTrials):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      fft_size = 4096
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      histogram = False
      primary_user_location = 0
      useless_bw = 200000.0
      src_data = [0+0j]*fft_size*nTrials
      voltage = self.powerToAmplitude(dBm);

		# Blocks
      src = gr.vector_source_c(src_data)
      noise = gr.noise_source_c(gr.GR_GAUSSIAN, voltage, 42)
      add = gr.add_vcc()
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, add, s2v, fftb, ss, self.sink)
      self.connect(noise, (add, 1))
Exemplo n.º 39
0
    def test_001_t (self):
        """
        more advanced:
        - 6 symbols per carrier
        - 2 pilots per carrier
        - have enough data for nearly 3 OFDM symbols
        """
        tx_symbols = range(1, 16);
        pilot_symbols = ((1j, 2j), (3j, 4j))
        occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
        pilot_carriers = ((2, 13), (3, 12))
        expected_result = (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,  0)
        fft_len = 16
        mtu = 4096
        tag_name = "len"
        tag = gr.gr_tag_t()
        tag.offset = 0
        tag.key = pmt.pmt_string_to_symbol(tag_name)
        tag.value = pmt.pmt_from_long(len(tx_symbols))
        src = gr.vector_source_c(tx_symbols, (tag,), False, 1)
        alloc = ofdm.carrier_allocator_cvc(fft_len,
                       occupied_carriers,
                       pilot_carriers,
                       pilot_symbols,
                       tag_name)
        sink = gr.vector_sink_c(fft_len)

        self.tb.connect(src, alloc, sink)
        self.tb.run ()
        self.assertEqual(sink.data(), expected_result)
Exemplo n.º 40
0
 def test_006_channel_and_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0,  1,  0, 1,  0,  -1, 0, 1,   0, -1,   0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0,  1, -1, 1,  -1,  1, 0, 1,  -1, -1,  -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp  = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.pmt_c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(sink.data(), tuple(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
Exemplo n.º 41
0
    def ofdmtest (self):
        options = Options()

        enc = raw.ofdm_mod(options)
        dec = raw.ofdm_demod(options, noutputs=2)

        NN = 4
        qpsk = lambda : cmath.exp(1j * (math.pi/NN * (2*random.randint(0, NN-1)+1)))

        n = enc.params.data_tones * options.size * 1000
        data = tuple([qpsk() for i in range(n)])

        signal = [0] * options.size
        signal[0] = 1
        signal = tuple(signal)

        msg = gr.vector_source_b(signal, True, 1)
        src = gr.vector_source_c(data, False, enc.params.data_tones)
        dst = gr.vector_sink_c(enc.params.data_tones)

        self.tb.connect(src,
                        enc,
                        dec,
                        dst)
        self.tb.connect(msg, (enc,1))
        self.tb.run()
        rxdata = numpy.array(dst.data())
        txdata = numpy.array(data[:len(rxdata)])
        power = numpy.average(numpy.square(numpy.abs(txdata)))
        print len(txdata), len(rxdata), power
        mse = numpy.average(numpy.square(numpy.abs(numpy.subtract(txdata,rxdata))))
        self.assertAlmostEquals(1.0, power, 7)
        snr = 10 * math.log10(power / mse)
        self.assertTrue(snr > 40) # that's a pretty low estimate for noiseless
Exemplo n.º 42
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 = gr.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = gr.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)
   def __init__(self, dBm, pfa, pfd, useless_bw):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      histogram = True
      primary_user_location = 0
      mu = 0
      fft_size = 16
      history = 3

      src_data = [1+1j]*fft_size*history

		# Blocks
      src = gr.vector_source_c(src_data)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,history)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, self.ss, self.sink)
Exemplo n.º 44
0
 def test_001_detect(self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1) * 2) - 1
                    for x in range(fft_len / 2)] * 2
     tx_signal = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     add = gr.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     self.tb.connect(gr.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(gr.noise_source_c(gr.GR_GAUSSIAN, .005), (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal) / 2]
     sig2_detect = sink_detect.data()[len(tx_signal) / 2:]
     self.assertTrue(
         abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(
         abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
Exemplo n.º 45
0
 def test_001_simple(self):
     """ Standard test """
     fft_len = 16
     tx_symbols = (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, 0)
     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.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, ))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0, "", False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value),
                      n_syms * len(occupied_carriers[0]))
  def test_001(self):
    frames = 5
    config = station_configuration()
    config.subcarriers = 12
    config.data_subcarriers = 8

    config.training_data = dummy()
    config.training_data.shifted_pilot_tones = [1,4,8,11]

    data =  [1.0] * config.subcarriers
    for x in config.training_data.shifted_pilot_tones:
      data[x] = 2.0
    data = concatenate([data]*frames)

    ref = [1.0]*(config.data_subcarriers*frames)

    src = gr.vector_source_c(data)
    s2v = gr.stream_to_vector(gr.sizeof_gr_complex,config.subcarriers)
    dst = gr.vector_sink_c()
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex,config.data_subcarriers)

    uut = preambles.pilot_subcarrier_filter()
    self.fg.connect(src,s2v,uut,v2s,dst)

    self.fg.run()
    self.assertEqual(ref,list(dst.data()))
Exemplo n.º 47
0
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = gr.vector_source_c(v0)
        src1 = gr.vector_source_b(v1)

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

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

        op = gr.ofdm_insert_preamble(fft_length, preamble)

        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = gr.vector_sink_c()
        dst1 = gr.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_002_static_wo_tags (self):
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0
                -1, -1, 0, 2, -1, 2, 0, -1, # 8
                -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols)
                -1, -1, 1, 1, -1, 0, 2, -1] # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data]
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = (
             [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], []
     )
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly...
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0  # ...and again here.
     ]
     for idx in range(fft_len, 2*fft_len):
         channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5))
         idx2 = idx+2*fft_len
         channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5))
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), "", False, 4)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()]
     self.assertEqual(tx_data, rx_data)
Exemplo n.º 49
0
 def test_003_connect (self):
     """ Connect carrier_allocator to ofdm_serializer,
         make sure output==input """
     fft_len = 8
     n_syms = 10
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     src = gr.vector_source_c(tx_data, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     serializer = digital.ofdm_serializer_vcc(alloc)
     sink = gr.vector_sink_c()
     self.tb.connect(src, alloc, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), tx_data)
Exemplo n.º 50
0
 def test_001(self):
     src_data = (1, 2, 3, 4, 5)
     src_gauss_ch1 = (2, 2, 1, 1, 2)
     expected_result = (2, 4, 3, 4, 10)
     src0 = gr.vector_source_c(src_data)
     src1 = gr.vector_source_c(src_gauss_ch1)
     mpc_channel = winelo_swig.mpc_channel_cc((0,), (1,))
     sink = gr.vector_sink_c()
     # set up fg
     self.tb.connect(src0, (mpc_channel, 0))
     self.tb.connect(src1, (mpc_channel, 1))
     self.tb.connect(mpc_channel, sink)
     self.tb.run()
     # check data
     result_data = sink.data()
     self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
 def test_fir_filter_ccf_002(self):
     self.generate_ccf_source()
     expected_data = ((6.419439159799367e-05 - 0.0006292851758189499j),
                      (-0.00037074743886478245 + 0.0013245552545413375j),
                      (0.0006853155209682882 - 0.0023769831750541925j),
                      (-0.001427714480087161 + 0.002608160488307476j),
                      (0.0015907397028058767 - 0.000811046629678458j),
                      (-0.0004226673918310553 - 0.0024389736354351044j),
                      (-0.0013841050677001476 + 0.006231029983609915j),
                      (0.0035029184073209763 - 0.009738259017467499j),
                      (-0.005924836732447147 + 0.010320881381630898j),
                      (0.006831614300608635 - 0.003950652200728655j),
                      (-0.0021247887052595615 - 0.015604906715452671j),
                      (-0.04283163696527481 + 0.09995654970407486j),
                      (-0.01391829177737236 + 0.07924056798219681j),
                      (0.010886997915804386 - 0.02463012933731079j),
                      (-0.0056075905449688435 + 0.004998659715056419j),
                      (0.0016976913902908564 + 0.004312459379434586j),
                      (0.0007344821933656931 - 0.007861112244427204j),
                      (-0.002173811662942171 + 0.007211671676486731j),
                      (0.0022051059640944004 -
                       0.00402153329923749j), (-0.0011226903880015016 +
                                               0.0009080505697056651j))
     src = gr.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccf(4, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 52
0
 def setUp (self):
     print "setUp"
     self.tb = gr.top_block ()
     self.src = gr.vector_source_c([0]*240,False,240)
     self.demapper = lte_swig.layer_demapper_vcvc(0, "tx_diversity")
     self.snk = gr.vector_sink_c(240)
     self.tb.connect(self.src, self.demapper, self.snk)
 def test_fir_filter_ccc_001(self):
     self.generate_ccc_source()
     expected_data = (
         (0.0036842757836 - 0.0114002721384j),
         (0.00324621866457 - 0.0108166672289j),
         (0.00206564785913 - 0.00923090614378j), (0.00109899020754 -
                                                  0.00656201224774j),
         (0.000506619049702 - 0.00402844604105j), (-0.000523390364833 -
                                                   0.00166808743961j),
         (-0.00140534969978 + 0.00103991874494j), (-0.00154365820345 +
                                                   0.00315759982914j),
         (-0.00180402118713 + 0.00427215453237j), (-0.00216706306674 +
                                                   0.00524478312582j),
         (-0.00178848754149 + 0.0057489364408j), (-0.00129876169376 +
                                                  0.00512680830434j),
         (-0.00122803379782 + 0.00427244976163j), (-0.000722666736692 +
                                                   0.00351428100839j),
         (5.53092104383e-05 + 0.00207865727134j), (0.000227351076319 +
                                                   0.000517217209563j),
         (0.000414477253798 - 0.000383921898901j), (0.000998671515845 -
                                                    0.00135387131013j),
         (0.00104933069088 - 0.00243046949618j), (0.000765930046327 -
                                                  0.0026717747096j))
     src = gr.vector_source_c(self.src_data)
     op = filter.freq_xlating_fir_filter_ccc(1, self.taps, self.fc, self.fs)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:],
                                         5)
Exemplo n.º 54
0
 def test_001_simple (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (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,  0)
     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.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "", 0, False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Exemplo n.º 55
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        mod=scipy.io.loadmat('/home/demel/exchange/matlab_sss.mat') 
        mat_u1=tuple(mod['sss'].flatten())
        mat_d=range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx]=val
        intu=tuple(mat_d)
        
        fftl = 512
        
        self.daemon = lte_swig.cell_id_daemon()
        
        # This is not yet a complete test! It's just for the purpose of testing the decoding and correlating.
        # Tag handling is not tested.
        self.src  = gr.vector_source_c(intu,False,72)
        
        self.tag = lte_swig.sss_tagging_cc(fftl)
        # calc sink block, which sets some attributes of other blocks.
        self.calc = lte_swig.sss_calc_vc(self.tag, fftl)
        

        
        self.tb.connect(self.src,self.calc)
    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 = gr.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = gr.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)
Exemplo n.º 57
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.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, offsettag))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "", 0, False)
     sink = gr.vector_sink_c()
     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.pmt_symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.pmt_to_long(tag.value), n_syms * len(occupied_carriers[0]))