def test_add_vcc_five(self): src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) expected_result = (33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j) op = blocks.add_cc(5) self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op)
def test_add_vcc_one(self): src1_data = (1.0 + 2.0j, ) src2_data = (3.0 + 4.0j, ) src3_data = (5.0 + 6.0j, ) expected_result = (9.0 + 12j, ) op = blocks.add_cc(1) self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op)
def __init__(self): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = Qt.QApplication(sys.argv) samp_rate = 1e6 fftsize = 2048 ampl = 10 self.src1 = analog.noise_source_c(analog.GR_GAUSSIAN, ampl, seed=0) self.src2 = analog.sig_source_c(samp_rate, analog.GR_SAW_WAVE, 400, ampl) self.add = blocks.add_cc() self.thr = blocks.throttle(gr.sizeof_gr_complex, samp_rate, True) self.snk = qtgui.sink_c( fftsize, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.connect(self.src1, (self.add, 0)) self.connect(self.src2, (self.add, 1)) self.connect(self.add, self.thr, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), Qt.QWidget) self.pyobj.show()
def test_add_vcc_one(self): src1_data = (1.0+2.0j,) src2_data = (3.0+4.0j,) src3_data = (5.0+6.0j,) expected_result = (9.0+12j,) op = blocks.add_cc(1) self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op)
def check_channelizer(self, channelizer_block): signals = list() add = blocks.add_cc() for i in range(len(self.freqs)): f = self.freqs[i] + i*self.fs data = sig_source_c(self.ifs, f, 1, self.N) signals.append(blocks.vector_source_c(data)) self.tb.connect(signals[i], (add,i)) #s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self.M) #self.tb.connect(add, s2ss) self.tb.connect(add, channelizer_block) snks = list() for i in range(self.M): snks.append(blocks.vector_sink_c()) #self.tb.connect((s2ss,i), (channelizer_block,i)) self.tb.connect((channelizer_block, i), snks[i]) self.tb.run() L = len(snks[0].data()) expected_data = self.get_expected_data(L) received_data = [snk.data() for snk in snks] for expected, received in zip(expected_data, received_data): self.compare_data(expected, received)
def test_003_t (self): # test cut frequency negative freq # set up fg test_len = 1000 samp_rate = 2000 freq1 = -200 freq2 = -205 ampl = 1 packet_len = test_len threshold = -100 samp_protect = 2 src1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq1, ampl*0.2) src2 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq2, ampl) add = blocks.add_cc(); head = blocks.head(8,test_len) s2ts = blocks.stream_to_tagged_stream(8,1,packet_len,"packet_len") fft = radar.ts_fft_cc(packet_len) peak = radar.find_max_peak_c(samp_rate, threshold, samp_protect, (-200,200), True) debug = blocks.message_debug() self.tb.connect((src1,0), (add,0)) self.tb.connect((src2,0), (add,1)) self.tb.connect(add,head,s2ts,fft,peak) self.tb.msg_connect(peak,"Msg out",debug,"store") #self.tb.msg_connect(peak,"Msg out",debug,"print") self.tb.start() sleep(0.5) self.tb.stop() self.tb.wait() # check frequency in os_cfar message with given one msg = debug.get_message(0) self.assertAlmostEqual(freq1,pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),0),8)
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 = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude) add = blocks.add_cc(fft_len) chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1) sink = blocks.vector_sink_c(fft_len) top_block.connect(src, chan, (add, 0), chanest, sink) top_block.connect(noise, blocks.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.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': carr_offset_hat = pmt.to_long(tag.value) self.assertEqual(carr_offset, carr_offset_hat) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': channel_est = shift_tuple(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 __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 1000 f2 = 2000 npts = 2048 self.qapp = QtGui.QApplication(sys.argv) self.filt_taps = [ 1, ] src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.01) self.filt = filter.fft_filter_ccc(1, self.filt_taps) thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts) self.snk1 = qtgui.freq_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS, 0, Rs, "Complex Freq Example", 1) self.connect(src1, (src, 0)) self.connect(src2, (src, 1)) self.connect(src, channel, thr, self.filt, (self.snk1, 0)) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) pyWin.show()
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) pspectrum_len = 1024 # build our flow graph input_rate = 2e6 #Generate some noise noise = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / 10) # Generate a complex sinusoid #source = gr.file_source(gr.sizeof_gr_complex, 'foobar2.dat', repeat=True) src1 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, -500e3, 1) src2 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 500e3, 1) src3 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, -250e3, 2) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate) sink1 = spectrum_sink_c(panel, title="Spectrum Sink", pspectrum_len=pspectrum_len, sample_rate=input_rate, baseband_freq=0, ref_level=0, y_per_div=20, y_divs=10, m=70, n=3, nsamples=1024) vbox.Add(sink1.win, 1, wx.EXPAND) combine1 = blocks.add_cc() self.connect(src1, (combine1, 0)) self.connect(src2, (combine1, 1)) self.connect(src3, (combine1, 2)) self.connect(noise, (combine1, 3)) self.connect(combine1, thr1, sink1)
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 1000 f2 = 2000 npts = 2048 self.qapp = QtGui.QApplication(sys.argv) self.filt_taps = [1,] src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.01) self.filt = filter.fft_filter_ccc(1, self.filt_taps) thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts) self.snk1 = qtgui.freq_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS, 0, Rs, "Complex Freq Example", 1) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, channel, thr, self.filt, (self.snk1, 0)) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) pyWin.show()
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 100 f2 = 200 npts = 2048 self.qapp = QtGui.QApplication(sys.argv) src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.5, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.5, 0) src = blocks.add_cc() channel = channels.channel_model(0.001) thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts) self.snk1 = qtgui.const_sink_c(npts, "Constellation Example", 1) self.connect(src1, (src, 0)) self.connect(src2, (src, 1)) self.connect(src, channel, thr, (self.snk1, 0)) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def check_channelizer(self, channelizer_block): signals = list() add = blocks.add_cc() for i in range(len(self.freqs)): f = self.freqs[i] + i * self.fs data = sig_source_c(self.ifs, f, 1, self.N) signals.append(blocks.vector_source_c(data)) self.tb.connect(signals[i], (add, i)) #s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self.M) #self.tb.connect(add, s2ss) self.tb.connect(add, channelizer_block) snks = list() for i in range(self.M): snks.append(blocks.vector_sink_c()) #self.tb.connect((s2ss,i), (channelizer_block,i)) self.tb.connect((channelizer_block, i), snks[i]) self.tb.run() L = len(snks[0].data()) expected_data = self.get_expected_data(L) received_data = [snk.data() for snk in snks] for expected, received in zip(expected_data, received_data): self.compare_data(expected, received)
def __init__(self): gr.top_block.__init__(self) self.qapp = Qt.QApplication(sys.argv) samp_rate = 1e6 fftsize = 2048 self.src = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, 0.1, 1, 0) self.nse = analog.noise_source_c(analog.GR_GAUSSIAN, 0.1) self.add = blocks.add_cc() self.thr = blocks.throttle(gr.sizeof_gr_complex, samp_rate, True) self.snk = qtgui.sink_c( fftsize, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.connect(self.src, (self.add, 0)) self.connect(self.nse, (self.add, 1)) self.connect(self.add, self.thr, self.snk) # Se establece como deseamos ver los resultados graficos self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), Qt.QWidget) self.pyobj.show()
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) pspectrum_len = 1024 # build our flow graph input_rate = 2e6 #Generate some noise noise = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0/10) # Generate a complex sinusoid #source = gr.file_source(gr.sizeof_gr_complex, 'foobar2.dat', repeat=True) src1 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, -500e3, 1) src2 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, 500e3, 1) src3 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, -250e3, 2) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate) sink1 = spectrum_sink_c (panel, title="Spectrum Sink", pspectrum_len=pspectrum_len, sample_rate=input_rate, baseband_freq=0, ref_level=0, y_per_div=20, y_divs=10, m = 70, n = 3, nsamples = 1024) vbox.Add (sink1.win, 1, wx.EXPAND) combine1 = blocks.add_cc() self.connect(src1, (combine1, 0)) self.connect(src2, (combine1, 1)) self.connect(src3, (combine1, 2)) self.connect(noise, (combine1, 3)) self.connect(combine1, thr1, sink1)
def __init__(self, n_sinusoids=1, SNR=10, samp_rate=32e3, nsamples=2048): gr.hier_block2.__init__(self, "ESPRIT/MUSIC signal generator", gr.io_signature(0, 0, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) sigampl = 10.0**(SNR / 10.0) # noise power is 1 self.srcs = list() self.n_sinusoids = n_sinusoids self.samp_rate = samp_rate # create our signals ... for s in range(n_sinusoids): self.srcs.append( analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, 1000 * s + 2000, numpy.sqrt(sigampl / n_sinusoids))) seed = ord(os.urandom(1)) self.noise = analog.noise_source_c(analog.GR_GAUSSIAN, 1, seed) self.add = blocks.add_cc() self.head = blocks.head(gr.sizeof_gr_complex, nsamples) self.sink = blocks.vector_sink_f(vlen=n_sinusoids) # wire it up ... for s in range(n_sinusoids): self.connect(self.srcs[s], (self.add, s)) # Additive noise self.connect(self.noise, (self.add, n_sinusoids)) self.connect(self.add, self.head, self)
def test_001_t (self): # set up fg src_data = (-3 + 1j , 4 + 2j, -5 + 5j, 2) for i in range(6000): src_data = src_data + (-3 + 1j , 4 + 2j, -5 + 5j, 2) #expected_result0 = (-3 + 1j, -4 + 2j, -5 + 5j, -2) #expected_result1 = (4 + 2j, -3 - 1j , 2 , -5 -5j) src = blocks.vector_source_c(src_data) mmtx = mimo.alamouti_encode_cc() add = blocks.add_cc() mmrx = mimo.alamouti_decode_cc() dst = blocks.vector_sink_c() self.tb.connect(src, mmtx) self.tb.connect((mmtx,0), (add,0)) self.tb.connect((mmtx,1), (add,1)) self.tb.connect(add, (mmrx,0)) self.tb.connect(add, (mmrx,1)) self.tb.connect(mmrx, dst) self.tb.run () # check data result_data = dst.data() print len(result_data) #for i in range(len(result_data)): # print result_data[i] # print src_data[i] self.assertComplexTuplesAlmostEqual(src_data , result_data, 1025)
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 = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() channel = channels.channel_model(0.005) self.tb.connect(blocks.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) )
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 = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude) add = blocks.add_cc(fft_len) chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1) sink = blocks.vector_sink_c(fft_len) top_block.connect(src, chan, (add, 0), chanest, sink) top_block.connect(noise, blocks.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.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': carr_offset_hat = pmt.to_long(tag.value) self.assertEqual(carr_offset, carr_offset_hat) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': channel_est = shift_tuple(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_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 tx_signal = [ 0, ] * n_zeros + make_bpsk_burst(fft_len, cp_len, sig_len) tx_signal = tx_signal * 2 add = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0)) self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (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)
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 = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0)) self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (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)
def test_001_t(self): sample_rate = 600e3 ampl = 0.1 file_src = blocks.file_source( 8, "/home/hzhua/gr_learn/gr-fch_detection/python/943.125_300kHz.cfile", False) #src0 = analog.sig_source_c(sample_rate, analog.GR_SIN_WAVE, 60e3, 1.0) #src1 = analog.noise_source_c(analog.GR_GAUSSIAN, 0.3) add = blocks.add_cc() taps = filter.firdes.low_pass(1, sample_rate, 70e3, 10e3) detect = fch_detection.detect2(taps) #dst = file.sink(sample_rate, "")fff dst = blocks.vector_sink_c() #dst= fftsink2.fft_sink_c(panel, title="FFT display", fft_size=512, sample_rate=sample_rate) #dst = qtgui.sink_c(512, gr.firdes.WIN_BLACKMAN_hARRIS) #self.tb.connect(src0, (add,0)); #self.tb.connect(src1, (add,1)); self.tb.connect(file_src, detect) #self.tb.connect(add, detect) self.tb.connect(detect, dst) self.tb.run()
def test_001_t(self): # set up fg src_data = (-3 + 1j, 4 + 2j, -5 + 5j, 2) for i in range(6000): src_data = src_data + (-3 + 1j, 4 + 2j, -5 + 5j, 2) #expected_result0 = (-3 + 1j, -4 + 2j, -5 + 5j, -2) #expected_result1 = (4 + 2j, -3 - 1j , 2 , -5 -5j) src = blocks.vector_source_c(src_data) mmtx = mimo.alamouti_encode_cc() add = blocks.add_cc() mmrx = mimo.alamouti_decode_cc() dst = blocks.vector_sink_c() self.tb.connect(src, mmtx) self.tb.connect((mmtx, 0), (add, 0)) self.tb.connect((mmtx, 1), (add, 1)) self.tb.connect(add, (mmrx, 0)) self.tb.connect(add, (mmrx, 1)) self.tb.connect(mmrx, dst) self.tb.run() # check data result_data = dst.data() print len(result_data) #for i in range(len(result_data)): # print result_data[i] # print src_data[i] self.assertComplexTuplesAlmostEqual(src_data, result_data, 1025)
def __init__(self): gr.top_block.__init__(self) # otra vez la herencia self.qapp = Qt.QApplication(sys.argv) sample_rate = 32000 fftsize = 2048 ampl = 0.5 self.src0 = analog.sig_source_c(sample_rate, analog.GR_SIN_WAVE, 1000, ampl) self.src1 = analog.sig_source_c(sample_rate, analog.GR_SIN_WAVE, 500, ampl) self.add = blocks.add_cc() self.thr = blocks.throttle(gr.sizeof_gr_complex, sample_rate, True) self.snk = qtgui.sink_c( fftsize, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc sample_rate, #bw "", #name True, #plotfreq False, #plotwaterfall True, #plottime False, #plotconst ) self.connect(self.src0, (self.add, 0)) self.connect(self.src1, (self.add, 1)) self.connect(self.add, self.thr, self.snk) # Se establece como deseamos ver los resultados graficos self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), Qt.QWidget) self.pyobj.show()
def run_test(tb, channel, fft_rotate, fft_filter): N = 1000 # number of samples to use M = 5 # Number of channels fs = 5000.0 # baseband sampling rate ifs = M * fs # input samp rate to decimator taps = filter.firdes.low_pass_2(1, ifs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() add = blocks.add_cc() freqs = [-230., 121., 110., -513., 203.] Mch = ((len(freqs) - 1) // 2 + channel) % len(freqs) for i in range(len(freqs)): f = freqs[i] + (M // 2 - M + i + 1) * fs data = sig_source_c(ifs, f, 1, N) signals.append(blocks.vector_source_c(data)) tb.connect(signals[i], (add, i)) s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M) pfb = filter.pfb_decimator_ccf(M, taps, channel, fft_rotate, fft_filter) snk = blocks.vector_sink_c() tb.connect(add, s2ss) for i in range(M): tb.connect((s2ss, i), (pfb, i)) tb.connect(pfb, snk) tb.run() L = len(snk.data()) # Adjusted phase rotations for data phase = [ 0.11058476216852586, 4.5108246571401693, 3.9739891674564594, 2.2820531095511924, 1.3782797467397869 ] phase = phase[channel] # Filter delay is the normal delay of each arm tpf = math.ceil(len(taps) / float(M)) delay = -(tpf - 1.0) / 2.0 delay = int(delay) # Create a time scale that's delayed to match the filter delay t = [float(x) / fs for x in range(delay, L + delay)] # Create known data as complex sinusoids for the baseband freq # of the extracted channel is due to decimator output order. expected_data = [ math.cos(2. * math.pi * freqs[Mch] * x + phase) + 1j * math.sin(2. * math.pi * freqs[Mch] * x + phase) for x in t ] dst_data = snk.data() return (dst_data, expected_data)
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 100 f2 = 200 npts = 2048 self.qapp = QtWidgets.QApplication(sys.argv) ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss') sstext = ss.read() ss.close() self.qapp.setStyleSheet(sstext) src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.01) thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts) self.snk1 = qtgui.time_sink_c(npts, Rs, "Complex Time Example", 1, None) self.connect(src1, (src, 0)) self.connect(src2, (src, 1)) self.connect(src, channel, thr, (self.snk1, 0)) #self.connect(src1, (self.snk1, 1)) #self.connect(src2, (self.snk1, 2)) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.qwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt5.QtWidgets.QWidget pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget) # Example of using signal/slot to set the title of a curve # FIXME: update for Qt5 # pyWin.setLineLabel.connect(pyWin.setLineLabel) #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}") self.snk1.set_line_label(0, "Re{Sum}") self.snk1.set_line_label(1, "Im{Sum}") #self.snk1.set_line_label(2, "Re{src1}") #self.snk1.set_line_label(3, "Im{src1}") #self.snk1.set_line_label(4, "Re{src2}") #self.snk1.set_line_label(5, "Im{src2}") # Can also set the color of a curve #self.snk1.set_color(5, "blue") self.snk1.set_update_time(0.5) # pyWin.show() self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def test_001_t (self): """AGC on random noisy QPSK symbols""" # Parameters snr_db = 0.0 const_mult = 1.5 agc_rate = 1e-4 agc_ref = 1.0 agc_gain = 1.0 N_last = 1000 # analyze the last symbols # Constants n_symbols = int(10*(1/agc_rate)) noise_v = 1/sqrt((10**(float(snr_db)/10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0,1) for i in range(0, n_symbols)]) # Flowgraph src = blocks.vector_source_b(in_vec) pack = blocks.repack_bits_bb(1, 2, "", False, gr.GR_MSB_FIRST) const = digital.constellation_qpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) mult = blocks.multiply_const_cc(const_mult) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) agc = blocksat.agc_cc(agc_rate, agc_ref, agc_gain) snk = blocks.vector_sink_c() snk2 = blocks.vector_sink_c() # Reference AGC approach rms_cf = blocks.rms_cf(0.0001) f2c = blocks.float_to_complex() div = blocks.divide_cc() snk3 = blocks.vector_sink_c() self.tb.connect(src, pack, cmap, mult) self.tb.connect(mult, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, agc, snk) self.tb.connect(nadder, snk2) self.tb.connect(nadder, (div, 0)) self.tb.connect(nadder, rms_cf, (f2c, 0), (div, 1)) self.tb.connect(div, snk3) self.tb.run() # Collect results agc_syms = snk.data() pre_agc_syms = snk2.data() ref_agc_syms = snk3.data() rms_agc = self.rms(agc_syms, N_last) rms_pre_agc = self.rms(pre_agc_syms, N_last) rms_agc_ref = self.rms(ref_agc_syms, N_last) print('RMS before AGC: %f' %(rms_pre_agc)) print('RMS after AGC: %f' %(rms_agc)) print('RMS after reference AGC: %f' %(rms_agc_ref)) # Check results self.assertAlmostEqual(rms_agc, 1.0, places=1)
def test_002_t(self): """Encoder to Decoder - noisy BPSK w/ soft constellation de-mapper""" # Parameters N = 18444 K = 6144 pct_en = False n_ite = 6 M = 2 snr_db = SNR_DB max_len = 10 * K flip_llrs = False sym_rate = 2 * 156250 # NOTE: The soft decoder block outputs positive LLR if bit "1" is more # likely, and negative LLR otherwise (bit = 0). That is, the soft # de-mapper's convention is the oposite of the one adopted in the Turbo # Decoder. To compensate that, we choose to flip the LLRs (multiply them # by "-1") inside the decoder wrapper. # Constants noise_v = 1 / math.sqrt((10**(float(snr_db) / 10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0, 1) for i in range(0, max_len)]) # Flowgraph src = blocks.vector_source_b(in_vec) enc = blocksattx.turbo_encoder(K, pct_en) const = digital.constellation_bpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) cdemap = blocksat.soft_decoder_cf(M, noise_v) dec = blocksat.turbo_decoder(K, pct_en, n_ite, flip_llrs) snk = blocks.vector_sink_b() snk_sym = blocks.vector_sink_c() snk_llr = blocks.vector_sink_f() self.tb.connect(src, enc, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, cdemap, dec, snk) self.tb.connect(cmap, snk_sym) self.tb.connect(cdemap, snk_llr) self.tb.run() # Collect results out_vec = snk.data() llrs = snk_llr.data() syms = snk_sym.data() diff = array(in_vec) - array(out_vec) err = [0 if i == 0 else 1 for i in diff] self.dump(const.points(), in_vec, syms, llrs, out_vec) print('Number of errors: %d' % (sum(err))) # Check results self.assertEqual(sum(err), 0)
def test_001_t(self): # We check if with a constant source, the SNR is measured correctly sample_rate = 1e6 frame_duration = 1.0e-3 test_duration = 1.5 * frame_duration snr = np.random.rand() * 1000 zc_seq_len = 71 samples_per_frame = int(round(frame_duration * sample_rate)) samples_per_test = int(round(test_duration * sample_rate)) snr_estim_sample_window = zc_seq_len #int(round(samples_per_frame/20)) random_samples_skip = np.random.randint( samples_per_frame / 2) + samples_per_frame / 2 preamble_seq = zadoffchu.generate_sequence(zc_seq_len, 1, 0) preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2) print "***** Start test 001 *****" framer = specmonitor.framer_c(sample_rate, frame_duration, preamble_seq) const_source = blocks.vector_source_c([1.0 / snr], True) add = blocks.add_cc() skiphead = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip) corr_est = specmonitor.corr_est_norm_cc( preamble_seq, 1, 0) #digital.corr_est_cc(preamble_seq, 1, 0) snr_est = specmonitor.framer_snr_est_cc(snr_estim_sample_window, preamble_seq.size) # tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger") head = blocks.head(gr.sizeof_gr_complex, samples_per_test) dst = blocks.vector_sink_c() self.tb.connect(framer, (add, 0)) self.tb.connect(const_source, (add, 1)) self.tb.connect(add, skiphead) self.tb.connect(skiphead, head) self.tb.connect(head, corr_est) self.tb.connect(corr_est, snr_est) # self.tb.connect(snr_est,tag_db) self.tb.connect(snr_est, dst) self.tb.run() x_data = dst.data() snrdB = snr_est.SNRdB() y_data = np.abs(x_data)**2 # print "Random Initial Skip: ", random_samples_skip # print "y_data size: ", len(y_data) start_preamble_idx = samples_per_frame - random_samples_skip + preamble_seq.size sig_range = np.arange(start_preamble_idx, start_preamble_idx + preamble_seq.size) floor_range = np.arange(sig_range[-1] + 1, sig_range[-1] + 1 + snr_estim_sample_window) y_pwr = np.mean(y_data[sig_range]) floor_pwr = np.mean(y_data[floor_range]) py_snrdB = 10 * np.log10(y_pwr / floor_pwr) self.assertAlmostEqual(py_snrdB, 20 * np.log10(snr), 1) self.assertAlmostEqual(snrdB, 20 * np.log10(snr), 1)
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 100 f2 = 200 npts = 2048 self.qapp = QtWidgets.QApplication(sys.argv) ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss') sstext = ss.read() ss.close() self.qapp.setStyleSheet(sstext) src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.01) thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts) self.snk1 = qtgui.time_sink_c(npts, Rs, "Complex Time Example", 1) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, channel, thr, (self.snk1, 0)) #self.connect(src1, (self.snk1, 1)) #self.connect(src2, (self.snk1, 2)) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt5.QtWidgets.QWidget pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget) # Example of using signal/slot to set the title of a curve # FIXME: update for Qt5 #pyWin.setLineLabel.connect(pyWin.setLineLabel) #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}") self.snk1.set_line_label(0, "Re{Sum}") self.snk1.set_line_label(1, "Im{Sum}") #self.snk1.set_line_label(2, "Re{src1}") #self.snk1.set_line_label(3, "Im{src1}") #self.snk1.set_line_label(4, "Re{src2}") #self.snk1.set_line_label(5, "Im{src2}") # Can also set the color of a curve #self.snk1.set_color(5, "blue") self.snk1.set_update_time(0.5) #pyWin.show() self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def test_002_t(self): # Generate frames with AWGN and test SNR estimation sample_rate = 10.0e6 frame_duration = 1.0e-3 test_duration = 0.1 * frame_duration snr = 10 scale_value = 15.0 samples_per_frame = int(round(frame_duration * sample_rate)) samples_per_test = int(round(test_duration * sample_rate)) random_samples_skip = 0 #np.random.randint(samples_per_frame) preamble_seq = zadoffchu(63, 1, 0) preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2) print "***** Start test 002 *****" framer = specmonitor.framer_c(sample_rate, frame_duration, preamble_seq) awgn = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / snr) add = blocks.add_cc() scaler = blocks.multiply_const_vcc([complex(scale_value)]) mag2 = blocks.complex_to_mag_squared() mavg = blocks.moving_average_ff( len(preamble_seq), 1.0 / len(preamble_seq) ) # i need to divide by the preamble size in case the preamble seq has amplitude 1 (sum of power is len) sqrtavg = blocks.transcendental("sqrt") # I have to compensate the amplitude of the input signal (scale) either through a feedback normalization loop that computes the scale, or manually (not practical) # additionally I have to scale down by the len(preamble)==sum(abs(preamble)^2) because the cross-corr does not divide by the preamble length #scaler2 = blocks.multiply_const_vcc([complex(1.0)/scale_value/len(preamble_seq)]) # if no feedback normalization loop, I have to scale the signal compensating additionally the scaling factor corr_est = specmonitor.corr_est_norm_cc( preamble_seq, 1, 0) #digital.corr_est_cc(preamble_seq, 1, 0) tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger") head = blocks.head(gr.sizeof_gr_complex, samples_per_test) dst = blocks.vector_sink_c() skiphead = blocks.skiphead(gr.sizeof_float, random_samples_skip) skiphead2 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip) skiphead3 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip) debug_vec = blocks.vector_sink_f() debug_vec2 = blocks.vector_sink_c() debug_vec3 = blocks.vector_sink_c() self.tb.connect(framer, (add, 0)) self.tb.connect(awgn, (add, 1)) self.tb.connect(add, scaler) self.tb.connect(scaler, mag2, mavg, sqrtavg) self.tb.connect(scaler, corr_est) self.tb.connect(corr_est, tag_db) self.tb.connect(corr_est, head, dst) self.tb.connect(sqrtavg, skiphead, debug_vec) self.tb.connect(scaler, skiphead2, debug_vec2) self.tb.run() result_data = dst.data() debug_vec_data = debug_vec.data() debug_vec_data2 = debug_vec2.data() debug_vec_data3 = debug_vec3.data()
def __init__(self, config, tb): self.name = config['name'] self.sample_rate = config['rate'] self.args = config['args'] self.frequency = config['frequency'] self.tb = tb self.sum = blocks.add_cc() self.sum_count = 0 self.output_throttle = None
def test_003_t(self): """Encoder to Decoder - noisy QPSK w/ soft constellation de-mapper""" # Parameters N = 18444 K = 6144 pct_en = False n_ite = 6 M = 4 snr_db = SNR_DB max_len = 10 * K flip_llrs = False sym_rate = 2 * 156250 # NOTE: just like in the previous example, flipping of the LLRs is # necessary here. # Constants noise_v = 1 / math.sqrt((10**(float(snr_db) / 10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0, 1) for i in range(0, max_len)]) # Flowgraph src = blocks.vector_source_b(in_vec) enc = blocksattx.turbo_encoder(K, pct_en) pack = blocks.repack_bits_bb(1, 2, "", False, gr.GR_MSB_FIRST) const = digital.constellation_qpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) cdemap = blocksat.soft_decoder_cf(M, noise_v) dec = blocksat.turbo_decoder(K, pct_en, n_ite, flip_llrs) snk = blocks.vector_sink_b() snk_sym = blocks.vector_sink_c() snk_llr = blocks.vector_sink_f() self.tb.connect(src, enc, pack, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, cdemap, dec, snk) self.tb.connect(cmap, snk_sym) self.tb.connect(cdemap, snk_llr) self.tb.run() # Collect results out_vec = snk.data() llrs = snk_llr.data() syms = snk_sym.data() diff = array(in_vec) - array(out_vec) err = [0 if i == 0 else 1 for i in diff] self.dump(const.points(), in_vec, syms, llrs, out_vec) print('Number of errors: %d' % (sum(err))) # Check results self.assertEqual(sum(err), 0)
def __init__(self, context, mode, angle=0.0): gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(1, 1, gr.sizeof_float * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__angle = 0.0 # dummy statically visible value will be overwritten # TODO: My signal level parameters are probably wrong because this signal doesn't look like a real VOR signal vor_30 = analog.sig_source_f(self.__audio_rate, analog.GR_COS_WAVE, self.__vor_sig_freq, 1, 0) vor_add = blocks.add_cc(1) vor_audio = blocks.add_ff(1) # Audio/AM signal self.connect( vor_30, blocks.multiply_const_ff(0.3), # M_n (vor_audio, 0)) self.connect( self, blocks.multiply_const_ff(audio_modulation_index), # M_i (vor_audio, 1)) # Carrier component self.connect(analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1), (vor_add, 0)) # AM component self.__delay = blocks.delay(gr.sizeof_gr_complex, 0) # configured by set_angle self.connect( vor_audio, make_resampler(self.__audio_rate, self.__rf_rate ), # TODO make a complex version and do this last blocks.float_to_complex(1), self.__delay, (vor_add, 1)) # FM component vor_fm_mult = blocks.multiply_cc(1) self.connect( # carrier generation analog.sig_source_f(self.__rf_rate, analog.GR_COS_WAVE, fm_subcarrier, 1, 0), blocks.float_to_complex(1), (vor_fm_mult, 1)) self.connect( # modulation vor_30, make_resampler(self.__audio_rate, self.__rf_rate), analog.frequency_modulator_fc(2 * math.pi * fm_deviation / self.__rf_rate), blocks.multiply_const_cc(0.3), # M_d vor_fm_mult, (vor_add, 2)) self.connect(vor_add, self) # calculate and initialize delay self.set_angle(angle)
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 = blocks.add_cc() for n in range(self._N): sig = analog.sig_source_f(self._audio_rate, analog.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 = blocks.head(gr.sizeof_gr_complex, self._nsamples) self.snk_tx = blocks.vector_sink_c() self.channel = channels.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 = filter.firdes.low_pass_2(1, self._if_rate, bw, t_bw, attenuation_dB=100, window=filter.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 = filter.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 range(self._M): self.fmdet.append(analog.nbfm_rx(self._audio_rate, self._chan_rate)) self.squelch.append(analog.standard_squelch(self._audio_rate*10)) self.snks.append(blocks.vector_sink_f()) self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
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 = blocks.add_cc() for n in xrange(self._N): sig = analog.sig_source_f(self._audio_rate, analog.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 = blocks.head(gr.sizeof_gr_complex, self._nsamples) self.snk_tx = blocks.vector_sink_c() self.channel = channels.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 = filter.firdes.low_pass_2(1, self._if_rate, bw, t_bw, attenuation_dB=100, window=filter.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 = filter.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(analog.nbfm_rx(self._audio_rate, self._chan_rate)) self.squelch.append(analog.standard_squelch(self._audio_rate*10)) self.snks.append(blocks.vector_sink_f()) self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
def test_add_cc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) add = blocks.add_cc() probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect((src, 0), (add, 0)) top.connect((src, 0), (add, 1)) top.connect(add, probe) return top, probe
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) fft_size = 256 # build our flow graph input_rate = 2048.0e3 #Generate some noise noise = analog.noise_source_c(analog.GR_UNIFORM, 1.0 / 10) # Generate a complex sinusoid #src1 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 2e3, 1) src1 = analog.sig_source_c(input_rate, analog.GR_CONST_WAVE, 57.50e3, 1) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate) sink1 = fft_sink_c(panel, title="Complex Data", fft_size=fft_size, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink1.win, 1, wx.EXPAND) combine1 = blocks.add_cc() self.connect(src1, (combine1, 0)) self.connect(noise, (combine1, 1)) self.connect(combine1, thr1, sink1) #src2 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 2e3, 1) src2 = analog.sig_source_f(input_rate, analog.GR_CONST_WAVE, 57.50e3, 1) thr2 = blocks.throttle(gr.sizeof_float, input_rate) sink2 = fft_sink_f(panel, title="Real Data", fft_size=fft_size * 2, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink2.win, 1, wx.EXPAND) combine2 = blocks.add_ff() c2f2 = blocks.complex_to_float() self.connect(src2, (combine2, 0)) self.connect(noise, c2f2, (combine2, 1)) self.connect(combine2, thr2, sink2)
def run_test(tb, channel, fft_rotate, fft_filter): N = 1000 # number of samples to use M = 5 # Number of channels fs = 5000.0 # baseband sampling rate ifs = M*fs # input samp rate to decimator taps = filter.firdes.low_pass_2(1, ifs, fs/2, fs/10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() add = blocks.add_cc() freqs = [-230., 121., 110., -513., 203.] Mch = ((len(freqs)-1)/2 + channel) % len(freqs) for i in xrange(len(freqs)): f = freqs[i] + (M/2-M+i+1)*fs data = sig_source_c(ifs, f, 1, N) signals.append(blocks.vector_source_c(data)) tb.connect(signals[i], (add,i)) s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M) pfb = filter.pfb_decimator_ccf(M, taps, channel, fft_rotate, fft_filter) snk = blocks.vector_sink_c() tb.connect(add, s2ss) for i in xrange(M): tb.connect((s2ss,i), (pfb,i)) tb.connect(pfb, snk) tb.run() L = len(snk.data()) # Adjusted phase rotations for data phase = [ 0.11058476216852586, 4.5108246571401693, 3.9739891674564594, 2.2820531095511924, 1.3782797467397869] phase = phase[channel] # Filter delay is the normal delay of each arm tpf = math.ceil(len(taps) / float(M)) delay = -(tpf - 1.0) / 2.0 delay = int(delay) # Create a time scale that's delayed to match the filter delay t = map(lambda x: float(x)/fs, xrange(delay, L+delay)) # Create known data as complex sinusoids for the baseband freq # of the extracted channel is due to decimator output order. expected_data = map(lambda x: math.cos(2.*math.pi*freqs[Mch]*x+phase) + \ 1j*math.sin(2.*math.pi*freqs[Mch]*x+phase), t) dst_data = snk.data() return (dst_data, expected_data)
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 = numpy.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 = blocks.add_cc() freqs = [-70, -50, -30, -10, 10, 20, 40, 60, 80] for i in range(len(freqs)): f = freqs[i] + (M / 2 - M + i + 1) * self._fs self.signals.append( analog.sig_source_c(self._ifs, analog.GR_SIN_WAVE, f, 1)) self.connect(self.signals[i], (self.add, i)) self.head = blocks.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 = blocks.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 range(self._M): self.snks.append(blocks.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def __init__(self, context, mode, angle=0.0): gr.hier_block2.__init__( self, 'SimulatedDevice VOR modulator', gr.io_signature(1, 1, gr.sizeof_float * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__angle = 0.0 # dummy statically visible value will be overwritten # TODO: My signal level parameters are probably wrong because this signal doesn't look like a real VOR signal vor_30 = analog.sig_source_f(self.__audio_rate, analog.GR_COS_WAVE, self.__vor_sig_freq, 1, 0) vor_add = blocks.add_cc(1) vor_audio = blocks.add_ff(1) # Audio/AM signal self.connect( vor_30, blocks.multiply_const_ff(0.3), # M_n (vor_audio, 0)) self.connect( self, blocks.multiply_const_ff(audio_modulation_index), # M_i (vor_audio, 1)) # Carrier component self.connect( analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1), (vor_add, 0)) # AM component self.__delay = blocks.delay(gr.sizeof_gr_complex, 0) # configured by set_angle self.connect( vor_audio, make_resampler(self.__audio_rate, self.__rf_rate), # TODO make a complex version and do this last blocks.float_to_complex(1), self.__delay, (vor_add, 1)) # FM component vor_fm_mult = blocks.multiply_cc(1) self.connect( # carrier generation analog.sig_source_f(self.__rf_rate, analog.GR_COS_WAVE, fm_subcarrier, 1, 0), blocks.float_to_complex(1), (vor_fm_mult, 1)) self.connect( # modulation vor_30, make_resampler(self.__audio_rate, self.__rf_rate), analog.frequency_modulator_fc(2 * math.pi * fm_deviation / self.__rf_rate), blocks.multiply_const_cc(0.3), # M_d vor_fm_mult, (vor_add, 2)) self.connect( vor_add, self) # calculate and initialize delay self.set_angle(angle)
def test_001_t(self): """MER of noisy QPSK symbols""" # Parameters snr_db = 10.0 alpha = 0.01 M = 2 frame_len = 10000 # Constants bits_per_sym = int(log(M, 2)) n_bits = int(bits_per_sym * frame_len) rndm = random.Random() # Iterate over SNR levels for snr_db in reversed(range(3, 15)): print("Trying SNR: %f dB" % (float(snr_db))) # Random input data in_vec = tuple([rndm.randint(0, 1) for i in range(0, n_bits)]) src = blocks.vector_source_b(in_vec) # Random noise noise_var = 1.0 / (10**(float(snr_db) / 10)) noise_std = sqrt(noise_var) print("Noise amplitude: %f" % (noise_std)) noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_std, 0) # Fixed flowgraph blocks pack = blocks.repack_bits_bb(1, bits_per_sym, "", False, gr.GR_MSB_FIRST) const = digital.constellation_bpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) nadder = blocks.add_cc() mer = blocksat.mer_measurement(alpha, M, frame_len) snk = blocks.vector_sink_f() snk_n = blocks.vector_sink_c() # Connect source into flowgraph self.tb.connect(src, pack, cmap) self.tb.connect(cmap, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, mer, snk) self.tb.connect(noise, snk_n) self.tb.run() # Collect results mer_measurements = snk.data() noise_samples = snk_n.data() print(mer_measurements) avg_mer = np.mean(mer_measurements) # Check results self.assertAlmostEqual(round(avg_mer), snr_db, places=1)
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 = blocks.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(analog.sig_source_c(self._ifs, analog.GR_SIN_WAVE, f, 1)) self.connect(self.signals[i], (self.add,i)) self.head = blocks.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 = blocks.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(blocks.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def add_vor(freq, angle): compensation = math.pi / 180 * -6.5 # empirical, calibrated against VOR receiver (and therefore probably wrong) angle = angle + compensation angle = angle % (2 * math.pi) vor_sig_freq = 30 phase_shift = int(rf_rate / vor_sig_freq * (angle / (2 * math.pi))) vor_dev = 480 vor_channel = make_channel(freq) vor_30 = analog.sig_source_f(audio_rate, analog.GR_COS_WAVE, vor_sig_freq, 1, 0) vor_add = blocks.add_cc(1) vor_audio = blocks.add_ff(1) # Audio/AM signal self.connect( vor_30, blocks.multiply_const_ff(0.3), # M_n (vor_audio, 0)) self.connect(audio_signal, blocks.multiply_const_ff(0.07), # M_i (vor_audio, 1)) # Carrier component self.connect( analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1), (vor_add, 0)) # AM component self.connect( vor_audio, blocks.float_to_complex(1), make_interpolator(), blocks.delay(gr.sizeof_gr_complex, phase_shift), (vor_add, 1)) # FM component vor_fm_mult = blocks.multiply_cc(1) self.connect( # carrier generation analog.sig_source_f(rf_rate, analog.GR_COS_WAVE, 9960, 1, 0), blocks.float_to_complex(1), (vor_fm_mult, 1)) self.connect( # modulation vor_30, filter.interp_fir_filter_fff(interp, interp_taps), # float not complex analog.frequency_modulator_fc(2 * math.pi * vor_dev / rf_rate), blocks.multiply_const_cc(0.3), # M_d vor_fm_mult, (vor_add, 2)) self.connect( vor_add, vor_channel) signals.append(vor_channel)
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 = blocks.add_cc() freqs = [10, 20, 2040] for i in xrange(len(freqs)): self.signals.append(analog.sig_source_c(self._fs, analog.GR_SIN_WAVE, freqs[i], 1)) self.connect(self.signals[i], (self.add,i)) self.head = blocks.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 = blocks.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 = blocks.vector_sink_c() self.connect(self.pfb, self.snk)
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 100 f2 = 2000 npts = 2048 taps = filter.firdes.complex_band_pass_2(1, Rs, 1500, 2500, 100, 60) self.qapp = QtGui.QApplication(sys.argv) ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss') sstext = ss.read() ss.close() self.qapp.setStyleSheet(sstext) src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.01) thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts) filt = filter.fft_filter_ccc(1, taps) self.snk1 = qtgui.waterfall_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS, 0, Rs, "Complex Waterfall Example", 2) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, channel, thr, (self.snk1, 0)) self.connect(thr, filt, (self.snk1, 1)) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) #pyWin.show() self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(usage="%prog: [options]") parser.add_option("-N", "--dpsslength", type="int", help="Length of the DPSS", default="512") parser.add_option("-B", "--timebandwidthproduct", type="float", help="Time Bandwidthproduct used to calculate the DPSS", default="3") parser.add_option("-K", "--tapers", type="int", help="Number of Tapers used to calculate the Spectrum", default="5") parser.add_option("-W", "--weighting", type="choice", choices=("unity", "eigenvalues" ,"adaptive" ), help="weighting-type to be used (unity, eigenvalues, adaptive) ", default="adaptive") (options, args) = parser.parse_args () self.options = options #setting up our signal self.samplingrate = 48000 self.source = analog.sig_source_c(self.samplingrate, analog.GR_SIN_WAVE, 3000, 1) self.noise = analog.noise_source_c(analog.GR_GAUSSIAN,0.5) self.add = blocks.add_cc() self.throttle = blocks.throttle(gr.sizeof_gr_complex, self.samplingrate) #the actual spectrum estimator self.v2s = blocks.vector_to_stream(gr.sizeof_float, self.options.dpsslength) self.mtm = specest.mtm( N = self.options.dpsslength, NW = self.options.timebandwidthproduct, K = self.options.tapers, weighting = self.options.weighting ) self.scope = specest.spectrum_sink_f( panel, title='Spectrum with %s weighting, Length %i and %i Tapers' % ( self.options.weighting, self.options.dpsslength, self.options.tapers ), spec_size=self.options.dpsslength, sample_rate=self.samplingrate, ref_level=80, avg_alpha=0.8, y_per_div=20 ) self.connect(self.source, (self.add, 0) ) self.connect(self.noise, (self.add, 1) ) self.connect(self.add, self.throttle, self.mtm) self.connect(self.mtm, self.v2s, self.scope) self._build_gui(vbox)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) default_input_rate = 1e6 if len(argv) > 1: input_rate = int(argv[1]) else: input_rate = default_input_rate if len(argv) > 2: v_scale = float(argv[2]) # start up at this v_scale value else: v_scale = None # start up in autorange mode, default if len(argv) > 3: t_scale = float(argv[3]) # start up at this t_scale value else: t_scale = .00003*default_input_rate/input_rate # old behavior print "input rate %s v_scale %s t_scale %s" % (input_rate,v_scale,t_scale) # Generate a complex sinusoid ampl=1.0e3 self.src0 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 25.1e3*input_rate/default_input_rate, ampl) self.noise = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 11.1*25.1e3*input_rate/default_input_rate, ampl/10) #self.noise = analog.noise_source_c(analog.GR_GAUSSIAN, ampl/10) self.combine = blocks.add_cc() # We add this throttle block so that this demo doesn't suck down # all the CPU available. You normally wouldn't use it... self.thr = blocks.throttle(gr.sizeof_gr_complex, input_rate) scope = scope_sink_c(panel,"Secret Data",sample_rate=input_rate, v_scale=v_scale, t_scale=t_scale) vbox.Add(scope.win, 1, wx.EXPAND) # Ultimately this will be # self.connect("src0 throttle scope") self.connect(self.src0,(self.combine,0)) self.connect(self.noise,(self.combine,1)) self.connect(self.combine, self.thr, scope)
def test_000(self): N = 1000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate ifs = M*fs # input samp rate to decimator channel = 0 # Extract channel 0 taps = filter.firdes.low_pass_2(1, ifs, fs/2, fs/10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() add = blocks.add_cc() freqs = [-200, -100, 0, 100, 200] for i in xrange(len(freqs)): f = freqs[i] + (M/2-M+i+1)*fs data = sig_source_c(ifs, f, 1, N) signals.append(blocks.vector_source_c(data)) self.tb.connect(signals[i], (add,i)) head = blocks.head(gr.sizeof_gr_complex, N) s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M) pfb = filter.pfb_decimator_ccf(M, taps, channel) snk = blocks.vector_sink_c() self.tb.connect(add, head, s2ss) for i in xrange(M): self.tb.connect((s2ss,i), (pfb,i)) self.tb.connect(pfb, snk) self.tb.run() Ntest = 50 L = len(snk.data()) t = map(lambda x: float(x)/fs, xrange(L)) # Create known data as complex sinusoids for the baseband freq # of the extracted channel is due to decimator output order. phase = 0 expected_data = map(lambda x: math.cos(2.*math.pi*freqs[2]*x+phase) + \ 1j*math.sin(2.*math.pi*freqs[2]*x+phase), t) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)
def get_input_data(self): """ Get the raw data generated by addition of sinusoids. Useful for debugging. """ tb = gr.top_block() signals = [] add = blocks.add_cc() for i in range(len(self.freqs)): f = self.freqs[i] + i*self.fs signals.append(analog.sig_source_c(self.ifs, analog.GR_SIN_WAVE, f, 1)) tb.connect(signals[i], (add,i)) head = blocks.head(gr.sizeof_gr_complex, self.N) snk = blocks.vector_sink_c() tb.connect(add, head, snk) tb.run() input_data = snk.data() return input_data
def sim ( self, arity, snr_db, N ): vlen = 1 N = int( N ) snr = 10.0**(snr_db/10.0) sigpow = 1.0 noise_pow = sigpow / snr demapper = ofdm.generic_demapper_vcb( vlen ) const = demapper.get_constellation( arity ) assert( len( const ) == 2**arity ) symsrc = ofdm.symbol_random_src( const, vlen ) noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) ) channel = blocks.add_cc() bitmap_src = blocks.vector_source_b( [arity] * vlen, True, vlen ) bm_trig_src = blocks.vector_source_b( [1], True ) ref_bitstream = blocks.unpack_k_bits_bb( arity ) bitstream_xor = blocks.xor_bb() bitstream_c2f = blocks.char_to_float() acc_biterr = ofdm.accumulator_ff() skiphead = blocks.skiphead( gr.sizeof_float, N-1 ) limit = blocks.head( gr.sizeof_float, 1 ) dst = blocks.vector_sink_f() tb = gr.top_block ( "test_block" ) tb.connect( (symsrc,0), (channel,0) ) tb.connect( noise_src, (channel,1) ) tb.connect( channel, (demapper,0), (bitstream_xor,0) ) tb.connect( bitmap_src, (demapper,1) ) tb.connect( bm_trig_src, (demapper,2) ) tb.connect( (symsrc,1), ref_bitstream, (bitstream_xor,1) ) tb.connect( bitstream_xor, bitstream_c2f, acc_biterr ) tb.connect( acc_biterr, skiphead, limit, dst ) tb.run() bit_errors = numpy.array( dst.data() ) assert( len( bit_errors ) == 1 ) bit_errors = bit_errors[0] return bit_errors / N
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) fft_size = 256 # build our flow graph input_rate = 2048.0e3 #Generate some noise noise = analog.noise_source_c(analog.GR_UNIFORM, 1.0/10) # Generate a complex sinusoid #src1 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 2e3, 1) src1 = analog.sig_source_c(input_rate, analog.GR_CONST_WAVE, 57.50e3, 1) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate) sink1 = fft_sink_c(panel, title="Complex Data", fft_size=fft_size, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink1.win, 1, wx.EXPAND) combine1 = blocks.add_cc() self.connect(src1, (combine1,0)) self.connect(noise,(combine1,1)) self.connect(combine1,thr1, sink1) #src2 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 2e3, 1) src2 = analog.sig_source_f (input_rate, analog.GR_CONST_WAVE, 57.50e3, 1) thr2 = blocks.throttle(gr.sizeof_float, input_rate) sink2 = fft_sink_f(panel, title="Real Data", fft_size=fft_size*2, sample_rate=input_rate, baseband_freq=100e3, ref_level=0, y_per_div=20, y_divs=10) vbox.Add(sink2.win, 1, wx.EXPAND) combine2 = blocks.add_ff() c2f2 = blocks.complex_to_float() self.connect(src2, (combine2,0)) self.connect(noise,c2f2,(combine2,1)) self.connect(combine2, thr2,sink2)
def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024*16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size/bitspersymbol # TX src = blocks.lfsr_32k_source_s() # packet size in shorts src_head = blocks.head(gr.sizeof_short, packet_size/16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = digital.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf(constellation.base(), digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = blocks.check_lfsr_32k_s() self.connect (src, src_head, s2fsmi, enc, mod) self.connect (mod, (add, 0)) self.connect (noise, (add, 1)) self.connect (add, metrics, va, fsmi2s, self.dst)
def __init__(self): gr.top_block.__init__(self) Rs = 8000 f1 = 1000 f2 = 2000 fftsize = 2048 self.qapp = QtGui.QApplication(sys.argv) ss = open('dark.qss') sstext = ss.read() ss.close() self.qapp.setStyleSheet(sstext) src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) src = blocks.add_cc() channel = channels.channel_model(0.001) thr = blocks.throttle(gr.sizeof_gr_complex, 100*fftsize) self.snk1 = qtgui.sink_c(fftsize, filter.firdes.WIN_BLACKMAN_hARRIS, 0, Rs, "Complex Signal Example", True, True, True, False) self.connect(src1, (src,0)) self.connect(src2, (src,1)) self.connect(src, channel, thr, self.snk1) self.ctrl_win = control_box() self.ctrl_win.attach_signal1(src1) self.ctrl_win.attach_signal2(src2) # Get the reference pointer to the SpectrumDisplayForm QWidget pyQt = self.snk1.pyqwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) self.main_box = dialog_box(pyWin, self.ctrl_win) self.main_box.show()
def __init__(self, noise_voltage, freq, timing): gr.hier_block2.__init__(self, "channel_model", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) timing_offset = filter.mmse_resampler_cc(0, timing) noise_adder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_voltage, 0) freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE, freq, 1.0, 0.0) mixer_offset = blocks.multiply_cc(); self.connect(self, timing_offset) self.connect(timing_offset, (mixer_offset,0)) self.connect(freq_offset, (mixer_offset,1)) self.connect(mixer_offset, (noise_adder,1)) self.connect(noise, (noise_adder,0)) self.connect(noise_adder, self)
def __init__(self, sample_rate): gr.hier_block2.__init__(self, "example_signal_1", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature src0 = analog.sig_source_c(sample_rate, # sample rate analog.GR_SIN_WAVE, # waveform type 350, # frequency 1.0, # amplitude 0) # DC Offset src1 = analog.sig_source_c(sample_rate, # sample rate analog.GR_SIN_WAVE, # waveform type 440, # frequency 1.0, # amplitude 0) # DC Offset sum = blocks.add_cc() self.connect(src0, (sum, 0)) self.connect(src1, (sum, 1)) self.connect(sum, self)