def __init__(self, fs_in, fs_out, fc, N=10000): gr.top_block.__init__(self) rerate = float(fs_out) / float(fs_in) print "Resampling from %f to %f by %f " %(fs_in, fs_out, rerate) # Creating our own taps taps = gr.firdes.low_pass_2(32, 32, 0.25, 0.1, 80) self.src = gr.sig_source_c(fs_in, gr.GR_SIN_WAVE, fc, 1) #self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) self.head = gr.head(gr.sizeof_gr_complex, N) # A resampler with our taps self.resamp_0 = blks2.pfb_arb_resampler_ccf(rerate, taps, flt_size=32) # A resampler that just needs a resampling rate. # Filter is created for us and designed to cover # entire bandwidth of the input signal. # An optional atten=XX rate can be used here to # specify the out-of-band rejection (default=80). self.resamp_1 = blks2.pfb_arb_resampler_ccf(rerate) self.snk_in = gr.vector_sink_c() self.snk_0 = gr.vector_sink_c() self.snk_1 = gr.vector_sink_c() self.connect(self.src, self.head, self.snk_in) self.connect(self.head, self.resamp_0, self.snk_0) self.connect(self.head, self.resamp_1, self.snk_1)
def __init__(self, N, fs, bw0, bw1, tw, atten, D): gr.top_block.__init__(self) self._nsamps = N self._fs = fs self._bw0 = bw0 self._bw1 = bw1 self._tw = tw self._at = atten self._decim = D taps = filter.firdes.complex_band_pass_2(1, self._fs, self._bw0, self._bw1, self._tw, self._at) print "Num. Taps: ", len(taps) self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) self.head = gr.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fft_filter_ccc(self._decim, taps) self.vsnk_src = gr.vector_sink_c() self.vsnk_out = gr.vector_sink_c() self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out)
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)
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)
def test_deint_001 (self): lenx = 64 src0 = gr.vector_source_c (range (lenx)) op = gr.deinterleave (gr.sizeof_gr_complex,4) dst0 = gr.vector_sink_c () dst1 = gr.vector_sink_c () dst2 = gr.vector_sink_c () dst3 = gr.vector_sink_c () self.tb.connect (src0, op) op.connect(dst0,usesPortName="complex_out_0") op.connect(dst1,usesPortName="complex_out_1") op.connect(dst2,usesPortName="complex_out_2") op.connect(dst3,usesPortName="complex_out_3") self.tb.run () expected_result0 = tuple (range (0, lenx, 4)) expected_result1 = tuple (range (1, lenx, 4)) expected_result2 = tuple (range (2, lenx, 4)) expected_result3 = tuple (range (3, lenx, 4)) self.assertComplexTuplesAlmostEqual (expected_result0, dst0.data()) self.assertComplexTuplesAlmostEqual (expected_result1, dst1.data()) self.assertComplexTuplesAlmostEqual (expected_result2, dst2.data ()) self.assertComplexTuplesAlmostEqual (expected_result3, dst3.data ())
def test_004_de_diff_mod_vcc (self): ################################# # Testsequenz generieren src_data = (1+0j, 0+2j, 0-0j, 0+1j, 2+0j, 0+0j,-1+0j,2+0j,-0+0j) ################################# # Ergebnis generieren expected_result_0 = (0+0j, 0+0j, 0-0j, 0+1j, 0-4j, 0-0j, 0+1j, 4+0j, 0+0j) expected_result_1 = (0+0j, 0-4j, 4+0j) ################################# # Objekte erzeugen src = gr.vector_source_c (src_data) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, 3) diff = howto_swig.de_diff_mod_vcc(3,1) v2s = gr.vector_to_stream(gr.sizeof_gr_complex, 3) dst0 = gr.vector_sink_c() dst1 = gr.vector_sink_c() # Objekte verbinden self.tb.connect(src, s2v, (diff,0), v2s, dst0) self.tb.connect((diff,1), dst1) # Simulationsstart self.tb.run () # Ergebnis auswerten result_data0 = dst0.data () result_data1 = dst1.data () self.assertComplexTuplesAlmostEqual (expected_result_0, result_data0, 6) self.assertComplexTuplesAlmostEqual (expected_result_1, result_data1, 6)
def main(): tb = gr.top_block() # noise source n = mlse.randint_b(2) reshape_n = gr.stream_to_vector(1, 58*2) tb.connect(n,reshape_n) # limit experiment length head=gr.head(58*2,1) tb.connect(reshape_n, head) # modulate gsm_burstmod = gsm.gsm_modulate_burst() tb.connect(head, gsm_burstmod) random_tsc_index = mlse.randint_b(8); tb.connect(random_tsc_index, (gsm_burstmod,1)) # apply channel channel = gsm.my_channel(-100,[0.2,1,0.2]) channel_apply = gsm.apply_channel_to_vect(148, channel, 1) tb.connect(gsm_burstmod, channel_apply) # derotate derot = mlse.derotate_cc(148,4,-1) #FIXME: why -1? (not as if it matters) tb.connect(channel_apply, derot) modsink = gr.vector_sink_c(148) datasink = gr.vector_sink_b(58*2) tb.connect(derot, modsink) tb.connect(head, datasink) # mlse-decode decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm()) tb.connect(derot,decode) tb.connect(random_tsc_index, (decode,1)) # ber ber = mlse.ber_vbi(58*2) tb.connect(decode, ber) tb.connect(head, (ber,1)) result_sink = gr.vector_sink_b(58*2) tb.connect(decode, result_sink) chanest_sink = gr.vector_sink_c(7) tb.connect((decode,1), chanest_sink) tb.run() tb.run() d=modsink.data() # printvect_c(d) print ber.bit_error_rate() print_bitvect( datasink.data()) print_bitvect( result_sink.data()) import operator print_bitvect( map(operator.xor, datasink.data(), result_sink.data())) printvect_c( chanest_sink.data())
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 __init__(self): gr.top_block.__init__(self) self._N = 2000000 # number of samples to use self._fs = 1000 # initial sampling rate self._M = M = 9 # Number of channels to channelize self._ifs = M*self._fs # initial sampling rate # Create a set of taps for the PFB channelizer self._taps = filter.firdes.low_pass_2(1, self._ifs, 475.50, 50, attenuation_dB=100, window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc # Create a set of signals at different frequencies # freqs lists the frequencies of the signals that get stored # in the list "signals", which then get summed together self.signals = list() self.add = gr.add_cc() freqs = [-70, -50, -30, -10, 10, 20, 40, 60, 80] for i in xrange(len(freqs)): f = freqs[i] + (M/2-M+i+1)*self._fs self.signals.append(gr.sig_source_c(self._ifs, gr.GR_SIN_WAVE, f, 1)) self.connect(self.signals[i], (self.add,i)) self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = filter.pfb.channelizer_ccf(self._M, self._taps, 1) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.add, self.head, self.pfb) self.connect(self.add, self.snk_i) # Use this to play with the channel mapping #self.pfb.set_channel_map([5,6,7,8,0,1,2,3,4]) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def test_002_square2_ff (self): src_data0 = ( 0.01+0.11j, 0.02+0.22j, 0.03+0.33j, 0.04+0.44j, 0.05+0.55j, 0.06+0.66j, 0.07+0.77j, 0.08+0.88j, 0.09+0.99j ) src_coeff = (0.101, 0.102, 0.103, 0.104, 0.105) scale = 15 expected_result = (245, 320, 395, 470, 445, 400, 334, 246, 135) src0 = gr.vector_source_c (src_data0) dsp.init() # dsp.fir_ccf ( # coefficients, # Q formatted can be between Q0 -> Q14 # scaling factor = [0, 15] # interpolation factor # currently not implemented "properly" a.k.a don't use just yet # input signature # 0 = normalized input # 1 = scaled by a factor equal "scale" # output signature # 0 = normalized input # 1 = scaled by a factor equal "scale" # initialize DSP (set to 0 use dsp.init() instead # 1 = yes # 0 = no # block ID # 1 or 0 to uniquly identify block instance for now there's support for only two blocks ccf_filt = dsp.fir_ccf (src_coeff, scale, 1, 0, 0, 0, 0) # gccf = gr.interp_fir_filter_ccf (1, src_coeff) dst0 = gr.vector_sink_c () dst1 = gr.vector_sink_c () self.tb.connect ((src0, 0), ccf_filt) self.tb.connect (ccf_filt, dst0) self.tb.run () result_data0 = dst0.data () result_data1 = dst1.data () print "Result DSP " dsp.clean()
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 __init__(self): gr.top_block.__init__(self) self._N = 200000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = filter.firdes.low_pass_2(1, self._fs, 500, 20, attenuation_dB=10, window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc repeated = True if(repeated): self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = scipy.arange(0, amp, amp/float(self._N)) self.vco_input = gr.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone # Then convert this to a complex signal self.vco = gr.vco_f(self._fs, 225, 1) self.f2c = gr.float_to_complex() self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = filter.pfb.channelizer_ccf(self._M, self._taps) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.vco_input, self.vco, self.f2c) self.connect(self.f2c, self.head, self.pfb) self.connect(self.f2c, self.snk_i) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def test_003(self): # Need to add padding padding = tuple([0 for i in range(29)]) scale = 2 vlen = 3 src_data = (0.0, 1.1, 2.2,) + padding + \ (3.2, 4.2, 5.5,) + padding + \ (-1.1, -2.2, -3.2,) + padding expected_result = [0, 2, 4] expected_result.extend(padding) expected_result.extend([6, 8, 11]) expected_result.extend(padding) expected_result.extend([-2, -4, -6]) expected_result.extend(padding) src = gr.vector_source_f(src_data) s2v = gr.stream_to_vector(gr.sizeof_float, vlen) op = gr.float_to_char(vlen, scale) v2s = gr.vector_to_stream(gr.sizeof_char, vlen) dst = gr.vector_sink_c() self.tb.connect(src, s2v, op, v2s, dst) self.tb.run() result_data = list(dst.data()) self.assertEqual(expected_result, result_data)
def __init__(self): grc_wxgui.top_block_gui.__init__( self, title="Zadoff Chu Sequence Correlator") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.length = length = 63 self.init_val = init_val = 29 ################################################## # Blocks ################################################## self.lte_zadoff_chu_seq_generator_vc_0 = lte.zadoff_chu_seq_generator_vc( length, init_val) self.gr_vector_sink_x_0 = gr.vector_sink_c(length) self.gr_head_0 = gr.head(gr.sizeof_gr_complex * length, 1) ################################################## # Connections ################################################## self.connect((self.lte_zadoff_chu_seq_generator_vc_0, 0), (self.gr_head_0, 0)) self.connect((self.gr_head_0, 0), (self.gr_vector_sink_x_0, 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
def setUp(self): self.tb = gr.top_block() offset = 43223 # sample15 = 21839 # sample20 = 43223 fftl = 512 cell_id = 124 N_rb_dl = 6 # get test input from matlab 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) self.myintu = intu #for i in range(20): # print intu[i+100000] self.src = gr.vector_source_c(intu, False, 1) self.tag = lte_swig.tag_symbol_cc(offset, fftl) self.est = lte.hier_freq_estimate_cc(fftl) self.head = gr.head(gr.sizeof_gr_complex, len(intu) - 100000) self.snk = gr.vector_sink_c(1) self.tb.connect(self.src, self.tag, self.head, self.est, self.snk)
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
def test_001_interpolation_cc (self): ################################# # Testsequenz generieren src_data_0 = ( 3+0j, 6+0j, 6+6j, 6+6j, 0+0j, 3+3j) ################################ # Ergebnis generieren exp_resu_0 = ( 0+0j, 2+0j, 4+0j, 6+0j, 6+4j, 6+6j, 6+6j, 2+2j, 1+1j, 3+3j,1+1j) ################################# # Objekte erzeugen src_0 = gr.vector_source_c (src_data_0) throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, 320000) interpol = howto_swig.interpolation_cc(3,2) dst_0 = gr.vector_sink_c() # Objekte verbinden self.tb.connect(src_0, throttle_0) self.tb.connect(throttle_0, interpol) self.tb.connect(interpol, dst_0) # Simulationsstart self.tb.run () # Ergebnis auswerten result_data0 = dst_0.data () self.assertComplexTuplesAlmostEqual (exp_resu_0, result_data0, 6)
def test_ccf_000(self): N = 1000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate nfilts = 32 freq = 100 signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1) head = gr.head(gr.sizeof_gr_complex, N) pfb = filter.pfb_arb_resampler_ccf(rrate, taps) snk = gr.vector_sink_c() self.tb.connect(signal, head, pfb, snk) self.tb.run() Ntest = 50 L = len(snk.data()) t = map(lambda x: float(x)/(fs*rrate), xrange(L)) phase = 0.53013 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 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_001(self): vlen = 128 syms = 4 freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen) fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2 ifft = gr.fft_vcc(vlen, False, [], True) fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen) vec = numpy.array(numpy.zeros(vlen), numpy.complex) vec[vlen / 2 - vlen / 4] = 1.0 vec = concatenate([vec] * syms) src = gr.vector_source_c(vec) dst = gr.vector_sink_c() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen) v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) eps = gr.vector_source_f([0.0] * syms) trig = gr.vector_source_b([1] * syms) self.fg.connect(src, s2v, ifft, (freq_shift, 0)) self.fg.connect(eps, (freq_shift, 1)) self.fg.connect(trig, (freq_shift, 2)) self.fg.connect(freq_shift, fft, fft_scale, v2s, dst) self.fg.run() self.assertComplexTuplesAlmostEqual(vec, numpy.array(dst.data()))
def test_007(self): vlen = 128 syms = 4 bin1 = vlen / 2 + 2 bin1_val = 1.0 expec = numpy.array(numpy.zeros(vlen), numpy.complex) expec[bin1] = bin1_val expec = concatenate([expec] * syms) epsilon = [0.5] frame_trigger = numpy.concatenate([[1], [0] * (syms - 1)]) freq_shift = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen) fft = gr.fft_vcc(vlen, True, [], True) # natural order, dc = vlen / 2 fft_scale = gr.multiply_const_vcc([1.0 / vlen] * vlen) src = gr.sig_source_c(vlen, gr.GR_COS_WAVE, 1.5, 1.0, 0.0) # bin vlen/2 + 1.5 dst = gr.vector_sink_c() s2v = gr.stream_to_vector(gr.sizeof_gr_complex, vlen) v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) eps = gr.vector_source_f(epsilon) trig = gr.vector_source_b(frame_trigger.tolist()) self.fg.connect(src, s2v, (freq_shift, 0)) self.fg.connect(eps, (freq_shift, 1)) self.fg.connect(trig, (freq_shift, 2)) self.fg.connect(freq_shift, fft, fft_scale, v2s, dst) self.fg.run() self.assertComplexTuplesAlmostEqual2(expec, dst.data(), 1e-5, 1e-5)
def transform(self, src_data, rate, freq): src = gr.vector_source_f(src_data, False) dft = gr.goertzel_fc(rate, rate, freq) dst = gr.vector_sink_c() self.tb.connect(src, dft, dst) self.tb.run() return dst.data()
def setUp(self): self.tb = gr.top_block() offset = 584 #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:offset + 100 * slotl]) self.src = gr.vector_source_c(intu, False, 1) self.tag = lte.tag_symbol_cc(offset, fftl) self.pss = lte.hier_pss_sync_cc(fftl) self.snk = gr.vector_sink_c(1) self.tb.connect(self.src, self.tag, self.pss, self.snk)
def transform(self, src_data): SRC = gr.vector_source_c(src_data, False) EQU = digital_swig.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 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)
def __init__(self,N_id_2, N_re=128, N_cp_ts=144, freq_corr=0): top = gr.top_block("foo"); pss_src_td = pss_source_td(N_id_2, N_re, N_cp_ts, freq_corr) sink = gr.vector_sink_c(1) top.connect(pss_src_td, sink) top.run() self.data = sink.data()
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 = gr.vector_source_c(data) op = filter.fractional_resampler_cc(0.0, rrate) snk = gr.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_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]))
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
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)
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]))
def __init__(self, N_id_1, N_id_2, slot0=True, N_re=128, N_cp_ts=144, freq_corr=0): top = gr.top_block("foo") source = gr.vector_source_c(range(0, N_re), False, N_re) source.set_data(gen_sss_fd(N_id_1, N_id_2, N_re).get_sss(slot0)) fft = gr.fft_vcc(N_re, False, window.blackmanharris(1024), True) cp = digital.ofdm_cyclic_prefixer(N_re, N_re + N_cp_ts * N_re / 2048) if freq_corr != 0: freq_corr = gr.freq_xlating_fir_filter_ccf(1, 1, freq_corr, 15000 * N_re) sink = gr.vector_sink_c(1) top.connect(source, fft, cp) if freq_corr != 0: top.connect(cp, freq_corr, sink) else: top.connect(cp, sink) top.run() self.data = sink.data()
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)))
def test_ccf_000(self): N = 1000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate nfilts = 32 freq = 100 signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1) head = gr.head(gr.sizeof_gr_complex, N) pfb = filter.pfb_arb_resampler_ccf(rrate, taps) snk = gr.vector_sink_c() self.tb.connect(signal, head, pfb, snk) self.tb.run() Ntest = 50 L = len(snk.data()) t = map(lambda x: float(x) / (fs * rrate), xrange(L)) phase = 0.53013 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): """ 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)
def transform(self, src_data, gain, const): SRC = gr.vector_source_c(src_data, False) EQU = digital_swig.lms_dd_equalizer_cc(4, gain, 1, const.base()) DST = gr.vector_sink_c() self.tb.connect(SRC, EQU, DST) self.tb.run() return DST.data()
def test04(self): # QPSK Convergence test with static rotation natfreq = 0.25 order = 4 self.test = digital_swig.costas_loop_cc(natfreq, order) rot = cmath.exp(0.2j) # some small rotation data = [ complex(2 * random.randint(0, 1) - 1, 2 * random.randint(0, 1) - 1) for i in xrange(100) ] N = 40 # settling time expected_result = data[N:] data = [rot * d for d in data] 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() dst_data = self.snk.data()[N:] # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
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()))
def setUp (self): print "qa_remove_cp2_cvc SetUp!" self.fftl = fftl = 2048 cpl = 144*fftl/2048 cpl0 = 160*fftl/2048 self.slotl = slotl = 7*fftl+6*cpl+cpl0 self.tb = gr.top_block () #provide test data self.src = gr.noise_source_c(gr.GR_GAUSSIAN,1) self.head = gr.head( gr.sizeof_gr_complex, 10*slotl ) self.tag = lte.pss_tagging_cc(fftl) # set up tagging block self.tag.set_half_frame_start(0) self.tag.set_N_id_2(1) self.tag.lock() # UUT self.rcp = lte.remove_cp2_cvc(fftl) # sinks self.snk = gr.vector_sink_c(fftl) self.tagsnc = gr.tag_debug(gr.sizeof_gr_complex*fftl, "remove_cp2_cvc") # connect blocks self.tb.connect(self.src, self.head, self.tag, self.rcp, self.snk )
def setUp(self): #print os.getpid() #raw_input("Press Enter to continue") print "begin test!" 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:30 * slotl]) self.src = gr.vector_source_c(intu, False, 1) self.tag = lte_swig.tag_symbol_cc(offset, fftl) #self.head = gr.head(gr.sizeof_gr_complex,300000) self.sss = lte.hier_sss_sync_cc(fftl) self.snk = gr.vector_sink_c(1) self.tb.connect(self.src, self.tag, self.sss, self.snk) #,self.head print "setup done!"
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)
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_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)
def setUp(self): self.tb = gr.top_block() # Case 1 antenna port assumed mod = scipy.io.loadmat( '/home/demel/exchange/matlab_pbch_layer_demap1.mat') mat_u1 = range(240) mat_u1 = tuple(mod['pbch_layer_demap1'].flatten()) # Case 2 antenna ports assumed mod = scipy.io.loadmat( '/home/demel/exchange/matlab_pbch_layer_demap2.mat') mat_u2 = range(240) mat_u2 = tuple(mod['pbch_layer_demap1'].flatten()) # pack input into one tuple mat_d = range(480) for idx, val in enumerate(mat_u1): mat_d[idx] = (mat_u1[idx]) mat_d[idx + 240] = mat_u2[idx] intu = tuple(mat_d) #print len(intu) #print type(intu) #print type(intu[8]) #print intu[0:3] self.src = gr.vector_source_c(intu, False, 240) self.ldm = lte_swig.layer_demapper_vcvc(1, 'tx_diversity') self.snk = gr.vector_sink_c(240) self.tb.connect(self.src, self.ldm, self.snk)
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 = digital_swig.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_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)))
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)
def test_deint_001(self): lenx = 64 src0 = gr.vector_source_c(range(lenx)) op = gr.deinterleave(gr.sizeof_gr_complex, 2) dst0 = gr.vector_sink_c() dst1 = gr.vector_sink_c() self.tb.connect(src0, op) op.connect(dst0, usesPortName="complex_out_0") op.connect(dst1, usesPortName="complex_out_1") self.tb.run() expected_result0 = tuple(range(0, lenx, 2)) expected_result1 = tuple(range(1, lenx, 2)) self.assertComplexTuplesAlmostEqual(expected_result0, dst0.data()) self.assertComplexTuplesAlmostEqual(expected_result1, dst1.data())
def __init__(self): gr.top_block.__init__(self) self._N = 10000000 # number of samples to use self._fs = 10000 # initial sampling rate self._decim = 20 # Decimation rate # Generate the prototype filter taps for the decimators with a 200 Hz bandwidth self._taps = filter.firdes.low_pass_2(1, self._fs, 200, 150, attenuation_dB=120, window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._decim)) print "Number of taps: ", len(self._taps) print "Number of filters: ", self._decim print "Taps per channel: ", tpc # Build the input signal source # We create a list of freqs, and a sine wave is generated and added to the source # for each one of these frequencies. self.signals = list() self.add = gr.add_cc() freqs = [10, 20, 2040] for i in xrange(len(freqs)): self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1)) self.connect(self.signals[i], (self.add,i)) self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct a PFB decimator filter self.pfb = filter.pfb.decimator_ccf(self._decim, self._taps, 0) # Construct a standard FIR decimating filter self.dec = filter.fir_filter_ccf(self._decim, self._taps) self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.add, self.head, self.pfb) self.connect(self.add, self.snk_i) # Create the sink for the decimated siganl self.snk = gr.vector_sink_c() self.connect(self.pfb, self.snk)
def setUp (self): self.tb = gr.top_block () mylen = 63 self.zc = lte_swig.zadoff_chu_seq_generator_vc(mylen,29) self.head = gr.head(gr.sizeof_gr_complex*mylen,1) self.snk = gr.vector_sink_c(63) self.tb.connect(self.zc, self.head, self.snk )
def test_float_to_complex_1(self): src_data = (1.0, 3.0, 5.0, 7.0, 9.0) expected_data = (1 + 0j, 3 + 0j, 5 + 0j, 7 + 0j, 9 + 0j) src = gr.vector_source_f(src_data) op = blocks_swig.float_to_complex() dst = gr.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
def help_cc(self, src_data, exp_data, op): for s in zip(range(len(src_data)), src_data): src = gr.vector_source_c(s[1]) self.tb.connect(src, (op, s[0])) dst = gr.vector_sink_c() self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertEqual(exp_data, result_data)
def test_interleaved_short_to_complex(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) expected_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) src = gr.vector_source_s(src_data) op = blocks_swig.interleaved_short_to_complex() dst = gr.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_data, dst.data())
def test_000(self): N = 10000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate ofs = M * fs # input samp rate to decimator taps = filter.firdes.low_pass_2( M, ofs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() freqs = [0, 100, 200, -200, -100] for i in xrange(len(freqs)): signals.append(gr.sig_source_c(fs, gr.GR_SIN_WAVE, freqs[i], 1)) head = gr.head(gr.sizeof_gr_complex, N) pfb = filter.pfb_synthesizer_ccf(M, taps) snk = gr.vector_sink_c() for i in xrange(M): self.tb.connect(signals[i], (pfb, i)) self.tb.connect(pfb, head, snk) self.tb.run() Ntest = 1000 L = len(snk.data()) t = map(lambda x: float(x) / ofs, xrange(L)) # Create known data as sum of complex sinusoids at freqs # of the output channels. freqs = [-2200, -1100, 0, 1100, 2200] expected_data = len(t) * [ 0, ] for i in xrange(len(t)): expected_data[i] = math.cos(2.*math.pi*freqs[0]*t[i]) + \ 1j*math.sin(2.*math.pi*freqs[0]*t[i]) + \ math.cos(2.*math.pi*freqs[1]*t[i]) + \ 1j*math.sin(2.*math.pi*freqs[1]*t[i]) + \ math.cos(2.*math.pi*freqs[2]*t[i]) + \ 1j*math.sin(2.*math.pi*freqs[2]*t[i]) + \ math.cos(2.*math.pi*freqs[3]*t[i]) + \ 1j*math.sin(2.*math.pi*freqs[3]*t[i]) + \ math.cos(2.*math.pi*freqs[4]*t[i]) + \ 1j*math.sin(2.*math.pi*freqs[4]*t[i]) dst_data = snk.data() offset = 25 self.assertComplexTuplesAlmostEqual( expected_data[2000 - offset:2000 - offset + Ntest], dst_data[2000:2000 + Ntest], 4)
def help_const_cc(self, src_data, exp_data, op): src = gr.vector_source_c(src_data) srcv = gr.stream_to_vector(gr.sizeof_gr_complex, len(src_data)) rhs = gr.vector_to_stream(gr.sizeof_gr_complex, len(src_data)) dst = gr.vector_sink_c() self.tb.connect(src, srcv, op, rhs, dst) self.tb.run() result_data = dst.data() self.assertEqual(exp_data, result_data)
def __init__(self): gr.top_block.__init__(self) self._nsamples = 1000000 self._audio_rate = 8000 # Set up N channels with their own baseband and IF frequencies self._N = 5 chspacing = 16000 freq = [10, 20, 30, 40, 50] f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing] self._if_rate = 4*self._N*self._audio_rate # Create a signal source and frequency modulate it self.sum = gr.add_cc () for n in xrange(self._N): sig = gr.sig_source_f(self._audio_rate, gr.GR_SIN_WAVE, freq[n], 0.5) fm = fmtx(f_lo[n], self._audio_rate, self._if_rate) self.connect(sig, fm) self.connect(fm, (self.sum, n)) self.head = gr.head(gr.sizeof_gr_complex, self._nsamples) self.snk_tx = gr.vector_sink_c() self.channel = blks2.channel_model(0.1) self.connect(self.sum, self.head, self.channel, self.snk_tx) # Design the channlizer self._M = 10 bw = chspacing/2.0 t_bw = chspacing/10.0 self._chan_rate = self._if_rate / self._M self._taps = gr.firdes.low_pass_2(1, self._if_rate, bw, t_bw, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS) tpc = math.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps) self.connect(self.channel, self.pfb) # Create a file sink for each of M output channels of the filter and connect it self.fmdet = list() self.squelch = list() self.snks = list() for i in xrange(self._M): self.fmdet.append(blks2.nbfm_rx(self._audio_rate, self._chan_rate)) self.squelch.append(blks2.standard_squelch(self._audio_rate*10)) self.snks.append(gr.vector_sink_f()) self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
def test_skip_all(self): skip_cnt = len(self.src_data) expected_result = tuple(self.src_data[skip_cnt:]) src1 = gr.vector_source_c(self.src_data) op = gr.skiphead(gr.sizeof_gr_complex, skip_cnt) dst1 = gr.vector_sink_c() self.tb.connect(src1, op, dst1) self.tb.run() dst_data = dst1.data() self.assertEqual(expected_result, dst_data)
def test_cc_001(self): src_data = (0+0j, 1000+1000j, 2000+2000j, 3000+3000j, 4000+4000j, 5000+5000j) expected_result = src_data src = gr.vector_source_c(src_data) op = filter.single_pole_iir_filter_cc(1.0) dst = gr.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data)
def test_channel_model(): tb = gr.top_block() src = gr.vector_source_c([0, 0, 1, 0, 0, 0, 0, 0]) # mod = gr.channel_model() mod = gsm.my_channel(-20, [1, 1]) sink = gr.vector_sink_c() tb.connect(src, mod, sink) tb.run() printvect_c(sink.data()) print mod.firtabsum