def test_deint_001(self): lenx = 64 src0 = gr.vector_source_i(range(lenx)) op = gr.deinterleave(gr.sizeof_int, 4) dst0 = gr.vector_sink_i() dst1 = gr.vector_sink_i() dst2 = gr.vector_sink_i() dst3 = gr.vector_sink_i() self.tb.connect(src0, op) op.connect(dst0, usesPortName="long_out_0") op.connect(dst1, usesPortName="long_out_1") op.connect(dst2, usesPortName="long_out_2") op.connect(dst3, usesPortName="long_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.assertFloatTuplesAlmostEqual(expected_result0, dst0.data()) self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data()) self.assertFloatTuplesAlmostEqual(expected_result2, dst2.data()) self.assertFloatTuplesAlmostEqual(expected_result3, dst3.data())
def test_deint_001(self): lenx = 64 src = gr.vector_source_f(range(lenx)) op = gr.deinterleave(gr.sizeof_float) dst0 = gr.vector_sink_f() dst1 = gr.vector_sink_f() dst2 = gr.vector_sink_f() dst3 = gr.vector_sink_f() self.tb.connect(src, op) self.tb.connect((op, 0), dst0) self.tb.connect((op, 1), dst1) self.tb.connect((op, 2), dst2) self.tb.connect((op, 3), dst3) 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.assertFloatTuplesAlmostEqual(expected_result0, dst0.data()) self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data()) self.assertFloatTuplesAlmostEqual(expected_result2, dst2.data()) self.assertFloatTuplesAlmostEqual(expected_result3, dst3.data())
def test_deint_001 (self): lenx = 64 src0 = gr.vector_source_i (range (lenx)) op = gr.deinterleave (gr.sizeof_int,4) dst0 = gr.vector_sink_i () dst1 = gr.vector_sink_i () dst2 = gr.vector_sink_i () dst3 = gr.vector_sink_i () self.tb.connect (src0, op) op.connect(dst0,usesPortName="long_out_0") op.connect(dst1,usesPortName="long_out_1") op.connect(dst2,usesPortName="long_out_2") op.connect(dst3,usesPortName="long_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.assertFloatTuplesAlmostEqual (expected_result0, dst0.data()) self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data()) self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
def test_deint_001 (self): lenx = 64 src = gr.vector_source_f (range (lenx)) op = gr.deinterleave (gr.sizeof_float) dst0 = gr.vector_sink_f () dst1 = gr.vector_sink_f () dst2 = gr.vector_sink_f () dst3 = gr.vector_sink_f () self.tb.connect (src, op) self.tb.connect ((op, 0), dst0) self.tb.connect ((op, 1), dst1) self.tb.connect ((op, 2), dst2) self.tb.connect ((op, 3), dst3) 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.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ()) self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ()) self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
def __init__(self, which, rx_ant_a='RXA', rx_ant_b='RXA', rx_source_a='A', rx_source_b='B'): """ USRP dual source contructor. @param which the unit number @param rx_ant_a the antenna choice @param rx_ant_b the antenna choice """ #initialize hier2 block gr.hier_block2.__init__( self, 'usrp_dual_source', gr.io_signature(0, 0, 0), gr.io_signature(2, 2, self._get_io_size()), ) #create usrp object self._make_usrp(which=which, nchan=2) subdev_spec_a = common.to_spec(rx_source_a, rx_ant_a) subdev_spec_b = common.to_spec(rx_source_b, rx_ant_b) self._get_u().set_mux(self._get_u().determine_rx_mux_value( subdev_spec_a, subdev_spec_b)) self._subdev_a = self._get_u().selected_subdev(subdev_spec_a) self._subdev_b = self._get_u().selected_subdev(subdev_spec_b) #connect deinter = gr.deinterleave(self._get_io_size()) self.connect(self._get_u(), deinter) for i in range(2): self.connect((deinter, i), (self, i))
def __init__(self, tx, zc, reader, rx, matched_filter, reader_monitor_cmd_gate, cr, tag_monitor, amplitude): gr.top_block.__init__(self) # ASK/PSK demodulators to_mag_L = gr.complex_to_mag() to_mag_R = gr.complex_to_mag() # Others blocks for Buettner's reader samp_freq = (64 / dec_rate) * 1e6 num_taps = int(64000 / (dec_rate * up_link_freq * 4)) taps = [complex(1, 1)] * num_taps filt = gr.fir_filter_ccc(sw_dec, taps) # Matched filter amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) # Null sink for terminating the Listener graph null_sink = gr.null_sink(gr.sizeof_float * 1) # Deinterleaver to separate FPGA channels di = gr.deinterleave(gr.sizeof_gr_complex) # Enable real-time scheduling r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" # Create flow-graph self.connect(rx, di) self.connect((di, 0), filt, to_mag_R, c_gate, zc, reader, amp, tx) self.connect((di, 1), matched_filter, to_mag_L, reader_monitor_cmd_gate, cr, tag_monitor, null_sink)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.remove_head = remove_head = 0 ################################################## # Blocks ################################################## self._remove_head_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.remove_head, callback=self.set_remove_head, label="Remove Head", choices=[0,1], labels=[], style=wx.RA_HORIZONTAL, ) self.Add(self._remove_head_chooser) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_udp_source_0 = gr.udp_source(gr.sizeof_short*1, "192.168.2.200", 9997, 590, False, True) self.gr_short_to_float_0_0 = gr.short_to_float(1, 1) self.gr_short_to_float_0 = gr.short_to_float(1, 1) self.gr_file_sink_0_1_0 = gr.file_sink(gr.sizeof_short*1, "/home/cgardner/sandbox/gr-csg/gr-fp/grc_testfp/test_fp_odd.bin") self.gr_file_sink_0_1_0.set_unbuffered(True) self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short*1, "/home/cgardner/sandbox/gr-csg/gr-fp/grc_testfp/test_raw_even.bin") self.gr_file_sink_0_1.set_unbuffered(True) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_short*1) self.fpgnu_fpdata_sink_0 = fpgnu_swig.fpdata_sink(remove_head) ################################################## # Connections ################################################## self.connect((self.gr_udp_source_0, 0), (self.fpgnu_fpdata_sink_0, 0)) self.connect((self.gr_short_to_float_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_file_sink_0_1_0, 0)) self.connect((self.fpgnu_fpdata_sink_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_file_sink_0_1, 0)) self.connect((self.gr_short_to_float_0_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.gr_deinterleave_0, 1), (self.gr_short_to_float_0_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_short_to_float_0, 0))
def __init__(self, N_id_2, decim=16, avg_halfframes=2 * 8, freq_corr=0, dump=None): gr.hier_block2.__init__( self, "PSS correlator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float), ) vec_half_frame = 30720 * 5 / decim self.taps = [] for i in range(0, 3): self.taps.append( gen_pss_td(i, N_re=2048 / decim, freq_corr=freq_corr).get_data_conj_rev()) self.corr = filter.fir_filter_ccc(1, self.taps[N_id_2]) self.mag = gr.complex_to_mag_squared() self.vec = gr.stream_to_vector(gr.sizeof_float * 1, vec_half_frame) self.deint = gr.deinterleave(gr.sizeof_float * vec_half_frame) self.add = gr.add_vff(vec_half_frame) self.argmax = gr.argmax_fs(vec_half_frame) self.null = gr.null_sink(gr.sizeof_short * 1) self.max = gr.max_ff(vec_half_frame) self.to_float = gr.short_to_float(1, 1. / decim) self.interleave = gr.interleave(gr.sizeof_float) #self.framestart = gr.add_const_ii(-160-144*5-2048*6+30720*5) self.connect(self, self.corr, self.mag, self.vec) self.connect((self.argmax, 1), self.null) #self.connect(self.argmax, self.to_float, self.to_int, self.framestart, self) self.connect(self.argmax, self.to_float, self.interleave, self) self.connect(self.max, (self.interleave, 1)) if avg_halfframes == 1: self.connect(self.vec, self.argmax) self.connect(self.vec, self.max) else: self.connect(self.vec, self.deint) self.connect(self.add, self.argmax) self.connect(self.add, self.max) for i in range(0, avg_halfframes): self.connect((self.deint, i), (self.add, i)) if dump != None: self.connect( self.mag, gr.file_sink(gr.sizeof_float, dump + "_pss_corr_f.cfile")) self.connect( self.add, gr.file_sink(gr.sizeof_float * vec_half_frame, dump + "_pss_corr_add_f.cfile"))
def test_deint_001(self): lenx = 64 src = gr.vector_source_c(range(lenx)) op = gr.deinterleave(gr.sizeof_gr_complex, 1) dst0 = gr.vector_sink_c() self.tb.connect(src, op) self.tb.connect((op, 0), dst0) self.tb.run() expected_result0 = tuple(range(0, lenx, 1)) self.assertComplexTuplesAlmostEqual(expected_result0, dst0.data())
def test_deint_001 (self): lenx = 64 src = gr.vector_source_c (range (lenx)) op = gr.deinterleave (gr.sizeof_gr_complex, 1) dst0 = gr.vector_sink_c () self.tb.connect (src, op) self.tb.connect ((op, 0), dst0) self.tb.run () expected_result0 = tuple (range (0, lenx, 1)) self.assertComplexTuplesAlmostEqual (expected_result0, dst0.data ())
def test_001_detect (self): src_file = gr.file_source(gr.sizeof_gr_complex, test_data) #src_file = gr.file_source(gr.sizeof_gr_complex, "data_backup20070423/20070208164806.tdat") #src_file = gr.file_source(gr.sizeof_gr_complex, "20080911161545.tdat") di = gr.deinterleave(gr.sizeof_gr_complex) self.fg.connect(src_file, di) pd = rmg.detect(4,8000,160,480,1.1,"results", tx_name, 1.1,1.5) pd.enable() self.fg.connect((di,0),(pd,0)) self.fg.connect((di,1),(pd,1)) self.fg.connect((di,2),(pd,2)) self.fg.connect((di,3),(pd,3)) self.fg.run();
def __init__(self, filename="usrp.dat", output="frames.dat", decim=16, pll_alpha=0.05, sync_alpha=0.05): gr.top_block.__init__(self, "USRP HRPT Receiver") ################################################## # Parameters ################################################## self.filename = filename self.output = output self.decim = decim self.pll_alpha = pll_alpha self.sync_alpha = sync_alpha ################################################## # Variables ################################################## self.sym_rate = sym_rate = 600*1109 self.sample_rate = sample_rate = 64e6/decim self.sps = sps = sample_rate/sym_rate self.hs = hs = int(sps/2.0) self.mf_taps = mf_taps = [-0.5/hs,]*hs+[0.5/hs,]*hs self.max_sync_offset = max_sync_offset = 0.01 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate ################################################## # Blocks ################################################## self.decoder = noaa.hrpt_decoder() self.deframer = noaa.hrpt_deframer() self.deinterleave = gr.deinterleave(gr.sizeof_float*1) self.f2c = gr.float_to_complex(1) self.file_sink = gr.file_sink(gr.sizeof_short*1, output) self.file_source = gr.file_source(gr.sizeof_short*1, filename, False) self.gr_fir_filter_xxx_0 = gr.fir_filter_ccc(1, (mf_taps)) self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) self.s2f = gr.short_to_float() self.sync = noaa.hrpt_sync_fb(sync_alpha, sync_alpha**2/4.0, sps, max_sync_offset) ################################################## # Connections ################################################## self.connect((self.deframer, 0), (self.file_sink, 0)) self.connect((self.sync, 0), (self.deframer, 0)) self.connect((self.pll, 0), (self.sync, 0)) self.connect((self.deinterleave, 1), (self.f2c, 1)) self.connect((self.deinterleave, 0), (self.f2c, 0)) self.connect((self.deframer, 0), (self.decoder, 0)) self.connect((self.gr_fir_filter_xxx_0, 0), (self.pll, 0)) self.connect((self.f2c, 0), (self.gr_fir_filter_xxx_0, 0)) self.connect((self.s2f, 0), (self.deinterleave, 0)) self.connect((self.file_source, 0), (self.s2f, 0))
def test_deint_001(self): lenx = 64 src0 = gr.vector_source_f(range(lenx)) op = gr.deinterleave(gr.sizeof_float, 2) dst0 = gr.vector_sink_f() dst1 = gr.vector_sink_f() self.tb.connect(src0, op) op.connect(dst0, usesPortName="float_out_1") op.connect(dst1, usesPortName="float_out_2") self.tb.run() expected_result0 = tuple(range(0, lenx, 2)) expected_result1 = tuple(range(1, lenx, 2)) self.assertFloatTuplesAlmostEqual(expected_result0, dst0.data()) self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data())
def test_deint_001 (self): lenx = 64 src0 = gr.vector_source_f (range (lenx)) op = gr.deinterleave (gr.sizeof_float,2) dst0 = gr.vector_sink_f () dst1 = gr.vector_sink_f () self.tb.connect (src0, op) op.connect(dst0,usesPortName="float_out_1") op.connect(dst1,usesPortName="float_out_2") self.tb.run () expected_result0 = tuple (range (0, lenx, 2)) expected_result1 = tuple (range (1, lenx, 2)) self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data()) self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data())
def __init__(self, N_id_2, decim=16, avg_halfframes=2*8, freq_corr=0, dump=None): gr.hier_block2.__init__( self, "PSS correlator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float), ) vec_half_frame = 30720*5/decim self.taps = [] for i in range(0,3): self.taps.append(gen_pss_td(i, N_re=2048/decim, freq_corr=freq_corr).get_data_conj_rev()) self.corr = filter.fir_filter_ccc(1, self.taps[N_id_2]) self.mag = gr.complex_to_mag_squared() self.vec = gr.stream_to_vector(gr.sizeof_float*1, vec_half_frame) self.deint = gr.deinterleave(gr.sizeof_float*vec_half_frame) self.add = gr.add_vff(vec_half_frame) self.argmax = gr.argmax_fs(vec_half_frame) self.null = gr.null_sink(gr.sizeof_short*1) self.max = gr.max_ff(vec_half_frame) self.to_float = gr.short_to_float(1, 1./decim) self.interleave = gr.interleave(gr.sizeof_float) #self.framestart = gr.add_const_ii(-160-144*5-2048*6+30720*5) self.connect(self, self.corr, self.mag, self.vec) self.connect((self.argmax,1), self.null) #self.connect(self.argmax, self.to_float, self.to_int, self.framestart, self) self.connect(self.argmax, self.to_float, self.interleave, self) self.connect(self.max, (self.interleave,1)) if avg_halfframes == 1: self.connect(self.vec, self.argmax) self.connect(self.vec, self.max) else: self.connect(self.vec, self.deint) self.connect(self.add, self.argmax) self.connect(self.add, self.max) for i in range(0, avg_halfframes): self.connect((self.deint, i), (self.add, i)) if dump != None: self.connect(self.mag, gr.file_sink(gr.sizeof_float, dump + "_pss_corr_f.cfile")) self.connect(self.add, gr.file_sink(gr.sizeof_float*vec_half_frame, dump + "_pss_corr_add_f.cfile"))
def test_deint_001 (self): lenx = 63 src0 = gr.vector_source_c (range (lenx)) op = gr.deinterleave (gr.sizeof_gr_complex,3) dst0 = gr.vector_sink_c () dst1 = gr.vector_sink_c () dst2 = 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") self.tb.run () expected_result0 = tuple (range (0, lenx, 3)) expected_result1 = tuple (range (1, lenx, 3)) expected_result2 = tuple (range (2, lenx, 3)) self.assertComplexTuplesAlmostEqual (expected_result0, dst0.data()) self.assertComplexTuplesAlmostEqual (expected_result1, dst1.data()) self.assertComplexTuplesAlmostEqual (expected_result2, dst2.data ())
def test_deint_001(self): lenx = 63 src0 = gr.vector_source_c(range(lenx)) op = gr.deinterleave(gr.sizeof_gr_complex, 3) dst0 = gr.vector_sink_c() dst1 = gr.vector_sink_c() dst2 = 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") self.tb.run() expected_result0 = tuple(range(0, lenx, 3)) expected_result1 = tuple(range(1, lenx, 3)) expected_result2 = tuple(range(2, lenx, 3)) self.assertComplexTuplesAlmostEqual(expected_result0, dst0.data()) self.assertComplexTuplesAlmostEqual(expected_result1, dst1.data()) self.assertComplexTuplesAlmostEqual(expected_result2, dst2.data())
def __init__(self, Source): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 750e3 ################################################## # Blocks ################################################## self.frame_source = FrameS.FrameSource(Source, N=6*1024, complete_buffs_only = False) self.frame_sink = FrameTFS.FrameToFileSink() self.threshold = Threshold.CustomTwoChannelThreshold() self.gr_deinterleave = gr.deinterleave(gr.sizeof_short*1) self.gr_interleave = gr.interleave(gr.sizeof_short*1) self.sink_queue = gr.msg_queue() self.msg_sink = gr.message_sink(gr.sizeof_short, self.sink_queue, True) self.testblock = custom_block(None) ################################################## # Connections ################################################## self.connect((self.frame_source, 0), (self.gr_deinterleave, 0)) self.connect((self.gr_deinterleave, 0), (self.threshold, 0)) self.connect((self.gr_deinterleave, 1), (self.threshold, 1)) self.connect((self.threshold, 0), (self.gr_interleave, 0)) self.connect((self.threshold, 1), (self.gr_interleave, 1)) self.connect((self.gr_interleave, 0), (self.frame_sink, 0)) self.connect((self.frame_source, 0), (self.testblock, 0)) self.connect((self.testblock, 0), (self.msg_sink, 0))
def __init__(self, which, rx_ant_a="RXA", rx_ant_b="RXA"): """ USRP dual source contructor. @param which the unit number @param rx_ant_a the antenna choice @param rx_ant_b the antenna choice """ # initialize hier2 block gr.hier_block2.__init__( self, "usrp_dual_source", gr.io_signature(0, 0, 0), gr.io_signature(2, 2, self._get_io_size()) ) # create usrp object self._make_usrp(which=which, nchan=2) subdev_spec_a = common.to_spec("A", rx_ant_a) subdev_spec_b = common.to_spec("B", rx_ant_b) self._get_u().set_mux(self._get_u().determine_rx_mux_value(subdev_spec_a, subdev_spec_b)) self._subdev_a = self._get_u().selected_subdev(subdev_spec_a) self._subdev_b = self._get_u().selected_subdev(subdev_spec_b) # connect deinter = gr.deinterleave(self._get_io_size()) self.connect(self._get_u(), deinter) for i in range(2): self.connect((deinter, i), (self, i))
def setup_interferometer(self, setimode): self.setup_radiometer_common(2) self.di = gr.deinterleave(gr.sizeof_gr_complex) self.connect (self.u, self.di) self.corr = gr.multiply_cc() self.c2f = gr.complex_to_float() self.shead = (self.di, 0) # Channel 0 to multiply port 0 # Channel 1 to multiply port 1 if (self.use_notches == False): self.connect((self.di, 0), (self.corr, 0)) self.connect((self.di, 1), (self.corr, 1)) else: self.connect((self.di, 0), self.notch_filt1, (self.corr, 0)) self.connect((self.di, 1), self.notch_filt2, (self.corr, 0)) # # Multiplier (correlator) to complex-to-float, followed by integrator, etc # self.connect(self.corr, self.c2f, self.integrator, self.keepn, self.cal_mult, self.cal_offs, self.chart) # # FFT scope gets only 1 channel # FIX THIS, by cross-correlating the *outputs* of two different FFTs, then display # Funky! # self.connect(self.shead, self.scope) # # Output of correlator/integrator chain to probe # self.connect(self.cal_offs, self.probe) return
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(option_class=eng_option) #parser.add_option("-S", "--subdev", type="subdev", default=(0, None), # help="select USRP Rx side A or B (default=A)") parser.add_option( "-d", "--decim", type="int", default=128, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=146.585e6, help="set frequency to FREQ [default=%default])", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=20, help="set gain in dB [default=%default]") parser.add_option("-F", "--filter", action="store_true", default=True, help="Enable channel filter") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit nchan = 4 if options.filter: sw_decim = 4 else: sw_decim = 1 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf") if self.u.nddcs() < nchan: sys.stderr.write( 'This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % (nchan, self.u.nddcs())) raise SystemExit if not self.u.set_nchannels(nchan): sys.stderr.write('set_nchannels(%d) failed\n' % (nchan, )) raise SystemExit input_rate = self.u.adc_freq() / self.u.decim_rate() print "USB data rate = %s" % (eng_notation.num_to_str(input_rate), ) print "Scope data rate = %s" % (eng_notation.num_to_str( input_rate / sw_decim), ) self.subdev = self.u.db(0) + self.u.db(1) if (len(self.subdev) < 4 or self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX or self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX): sys.stderr.write( 'This code requires a Basic Rx board on Sides A & B\n') sys.exit(1) self.u.set_mux(gru.hexint(0xf3f2f1f0)) # deinterleave four channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, di) # our destination (8 float inputs) self.scope = scopesink2.scope_sink_f(panel, sample_rate=input_rate / sw_decim, num_inputs=2 * nchan) # taps for channel filter chan_filt_coeffs = optfir.low_pass( 1, # gain input_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) # bust the deinterleaved complex channels into floats for i in range(nchan): if options.filter: chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs) c2f = gr.complex_to_float() self.connect((di, i), chan_filt, c2f) else: c2f = gr.complex_to_float() self.connect((di, i), c2f) self.connect((c2f, 0), (self.scope, 2 * i + 0)) self.connect((c2f, 1), (self.scope, 2 * i + 1)) self._build_gui(vbox) self.set_gain(options.gain) self.set_freq(options.freq)
def __init__(self, freq_corr=0, avg_frames=1, decim=16, N_id_2=0, N_id_1=134): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.avg_frames = avg_frames self.decim = decim self.N_id_2 = N_id_2 self.N_id_1 = N_id_1 ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720 * 5 / decim self.symbol_start = symbol_start = 144 / decim self.slot_0_10 = slot_0_10 = 1 self.samp_rate = samp_rate = 30720e3 / decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048 / decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo") self.Add(self.notebook_0) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c( self.notebook_0.GetPage(3).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win) self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win) self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win) self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f( self.notebook_0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=100 / avg_frames, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win) _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL) self._symbol_start_text_box = forms.text_box( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, label='symbol_start', converter=forms.int_converter(), proportion=0, ) self._symbol_start_slider = forms.slider( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, minimum=0, maximum=144 / decim, num_steps=144 / decim, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_symbol_start_sizer) self.sss_ml_fd_0 = sss_ml_fd( decim=decim, avg_frames=avg_frames, N_id_1=N_id_1, N_id_2=N_id_2, slot_0_10=slot_0_10, ) self.pss_chan_est2_0 = pss_chan_est2(N_id_2=N_id_2, ) self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.gr_stream_to_vector_0_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, N_re) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex * 1, (N_re / 2, N_re / 2)) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re) self.gr_multiply_xx_1 = gr.multiply_vcc(N_re) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (0.005 * exp(rot * 2 * numpy.pi * 1j), )) self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size - N_re) / 2 - 1) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size) / 2) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * N_re) self.gr_channel_model_0 = gr.channel_model( noise_voltage=0.005 * noise_level, frequency_offset=0.0, epsilon=1, taps=(0.005 * exp(rot * 2 * numpy.pi * 1j), ), noise_seed=0, ) self.gr_add_xx_0 = gr.add_vcc(1) self.blks2_selector_0_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=2, num_outputs=1, input_index=0, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=3, num_outputs=2, input_index=0, output_index=0, ) ################################################## # Connections ################################################## self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0)) self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0)) self.connect((self.gr_channel_model_0, 0), (self.blks2_selector_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_selector_0_0, 1)) self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0)) self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_vector_to_stream_0_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0_0, 0), (self.wxgui_scopesink2_0_1_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.wxgui_scopesink2_0_1_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_0_1, 0), (self.wxgui_scopesink2_0_1_0_1, 0)) self.connect((self.gr_vector_to_stream_0_0_1_0, 0), (self.wxgui_scopesink2_0_1_0_1, 1)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_0_1_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1)) self.connect((self.gr_multiply_xx_1_0, 0), (self.gr_vector_to_stream_0_0_1, 0)) self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0_0, 0)) self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1)) self.connect((self.gr_stream_mux_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2)) self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
def __init__( self, decim=16, fft_size=2048 / 16, N_re=62, avg_frames=8, dump=None, N_id_1s=range(0, 168), slot_0_10s=range(0, 2), ): self.logger = logging.getLogger("sss_corr2") # store parameters self.decim = decim self.fft_size = fft_size self.N_re = N_re self.avg_frames = avg_frames self.dump = dump self.N_id_1s = N_id_1s self.slot_0_10s = slot_0_10s # calculate statics self.symbol_mask = numpy.zeros(20 * 7) self.symbol_mask[5:7] = 1 self.symbol_mask[75:77] = 1 # generate PSS sequences self.pss_fd_vec = [] for N_id_2 in range(0, 3): self.pss_fd_vec.append(gen_pss_fd(N_id_2, self.N_re, False).get_data()) # generate SSS sequences self.sss_fd_vec = [] for N_id_2 in range(0, 3): self.sss_fd_vec.append([]) for N_id_1 in range(0, 168): self.sss_fd_vec[N_id_2].append([]) for slot_0_10 in range(0, 2): self.sss_fd_vec[N_id_2][N_id_1].append( gen_sss_fd(N_id_1, N_id_2, N_re).get_sss_conj(slot_0_10 != 0) ) self.pss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re) self.sss_ref_src = gr.vector_source_c(zeros(0), True, self.N_re) # SSS equalization flow graph self.equ_source = symbol_source(decim=self.decim, vlen=self.fft_size) fft = gr.fft_vcc(self.fft_size, True, (window.blackmanharris(1024)), True, 1) vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex * 1, self.fft_size) keep_m_in_n_0 = gr.keep_m_in_n( gr.sizeof_gr_complex, self.N_re / 2, self.fft_size, (self.fft_size - self.N_re) / 2 - 1 ) keep_m_in_n_1 = gr.keep_m_in_n(gr.sizeof_gr_complex, self.N_re / 2, self.fft_size, (self.fft_size) / 2) stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex, 2 * [self.N_re / 2]) stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex * 1, self.N_re) deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * self.N_re) self.equ = sss_equ2() self.equ_sink = gr.vector_sink_c(self.N_re) self.equ_top = gr.top_block("sss equ graph") self.equ_top.connect(self.equ_source, fft, vector_to_stream_0) self.equ_top.connect(vector_to_stream_0, keep_m_in_n_0, (stream_mux_0, 0)) self.equ_top.connect(vector_to_stream_0, keep_m_in_n_1, (stream_mux_0, 1)) self.equ_top.connect(stream_mux_0, stream_to_vector_0_0, deinterleave_0) self.equ_top.connect((deinterleave_0, 0), (self.equ, 0)) self.equ_top.connect((deinterleave_0, 1), (self.equ, 1)) self.equ_top.connect(self.pss_ref_src, (self.equ, 2)) self.equ_top.connect((self.equ, 0), self.equ_sink) self.equ_top.connect((self.equ, 1), gr.null_sink(self.N_re * gr.sizeof_gr_complex)) if self.dump != None: self.equ_top.connect( self.equ_source, gr.file_sink(gr.sizeof_gr_complex * self.fft_size, self.dump + "_sss_td_in.cfile") ) self.equ_top.connect( (deinterleave_0, 0), gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_in.cfile") ) self.equ_top.connect( (deinterleave_0, 1), gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_pss_fd_in.cfile") ) self.equ_top.connect( self.equ, gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_equ.cfile") ) # SSS maximum likelihood estimation self.ml_src = gr.vector_source_c(zeros(0), False, self.N_re) self.ml_derot = sss_derot() self.ml_sss = sss_ml_fd2(avg_frames=self.avg_frames) self.ml_sink = gr.vector_sink_f() self.ml_top = gr.top_block("sss ml graph") self.ml_top.connect(self.ml_src, self.ml_derot, self.ml_sss, self.ml_sink) self.ml_top.connect(self.sss_ref_src, (self.ml_derot, 1)) self.ml_top.connect(self.sss_ref_src, (self.ml_sss, 1)) if self.dump != None: self.ml_top.connect( self.ml_derot, gr.file_sink(gr.sizeof_gr_complex * self.N_re, self.dump + "_sss_fd_derot.cfile") ) self.ml_top.connect(self.ml_sss, gr.file_sink(gr.sizeof_float, self.dump + "_sss_corr.cfile"))
def __init__(self, freq_corr=0, N_id_1=134, avg_frames=1, N_id_2=0, decim=16): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr2 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.N_id_1 = N_id_1 self.avg_frames = avg_frames self.N_id_2 = N_id_2 self.decim = decim ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720*5/decim self.samp_rate = samp_rate = 30720e3/decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048/decim ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_vector_to_stream_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_2 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_float*1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0 = gr.vector_source_c((gen_sss_fd( N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size) self.gr_stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_repeat_0 = gr.repeat(gr.sizeof_float*1, fft_size) self.gr_null_sink_0_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1 = gr.multiply_vcc(1) self.gr_multiply_xx_0 = gr.multiply_vcc(fft_size) self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((1/1500., )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((exp(rot*2*numpy.pi*1j), )) self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex*fft_size) self.gr_integrate_xx_0 = gr.integrate_ff(fft_size) self.gr_float_to_complex_0_0 = gr.float_to_complex(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_divide_xx_0_1 = gr.divide_cc(1) self.gr_divide_xx_0_0 = gr.divide_ff(1) self.gr_divide_xx_0 = gr.divide_cc(1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex*fft_size) self.gr_conjugate_cc_1 = gr.conjugate_cc() self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(fft_size) self.gr_add_xx_0 = gr.add_vcc(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1, )) self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0)) self.connect((self.gr_integrate_xx_0, 0), (self.gr_repeat_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_divide_xx_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_conjugate_cc_1, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_vector_to_stream_0_1, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_conjugate_cc_1, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_complex_to_mag_squared_0_0, 0)) self.connect((self.gr_complex_to_mag_squared_0_0, 0), (self.gr_divide_xx_0_0, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_divide_xx_0_0, 1)) self.connect((self.gr_divide_xx_0_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_complex_0_0, 0)) self.connect((self.const_source_x_0_0, 0), (self.gr_float_to_complex_0_0, 1)) self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_divide_xx_0_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_divide_xx_0_1, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_vector_to_stream_0_2, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.gr_divide_xx_0_1, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1)) self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0)) self.connect((self.gr_fft_vxx_1, 0), (self.gr_vector_to_stream_1, 0)) self.connect((self.gr_vector_source_x_0_0, 0), (self.gr_interleave_0, 0)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_2, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_vector_to_stream_1, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.gr_divide_xx_0_1, 0), (self.wxgui_scopesink2_0, 0))
def __init__(self, ntxchans, nrxchans, fft_length, cp_length, occupied_tones, snr, ks, logging=False): """ Hierarchical block for receiving OFDM symbols. The input is the complex modulated signal at baseband. Synchronized packets are sent back to the demodulator. @param ntxchans: Number of transmitter MIMO channels (antennas) @type ntxchans: int @param nrxchans: Number of reciever MIMO channels (antennas) @type nrxchans: int @param fft_length: total number of subcarriers @type fft_length: int @param cp_length: length of cyclic prefix as specified in subcarriers (<= fft_length) @type cp_length: int @param occupied_tones: number of subcarriers used for data @type occupied_tones: int @param snr: estimated signal to noise ratio used to guide cyclic prefix synchronizer @type snr: float @param ks: known symbols used as preambles to each packet @type ks: list of lists @param logging: turn file logging on or off @type logging: bool """ gr.hier_block2.__init__(self, "ofdm_mimo_receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_gr_complex*occupied_tones, gr.sizeof_char)) # Output signature bw = (float(occupied_tones) / float(fft_length)) / 2.0 tb = bw*0.08 chan_coeffs = gr.firdes.low_pass (1.0, # gain 1.0, # sampling rate bw+tb, # midpoint of trans. band tb, # width of trans. band gr.firdes.WIN_HAMMING) # filter type # For starters, run Sync on channel 0 and use it to clock and retime all channels win = [1 for i in range(fft_length)] zeros_on_left = int(math.ceil((fft_length - occupied_tones)/2.0)) ks0 = fft_length*[0,] ks0[zeros_on_left : zeros_on_left + occupied_tones] = ks[0][0:] ks0 = fft.ifftshift(ks0) ks0time = fft.ifft(ks0) # ADD SCALING FACTOR ks0time = ks0time.tolist() SYNC = "pn" if SYNC == "ml": nco_sensitivity = -1.0/fft_length # correct for fine frequency self.ofdm_sync = ofdm_sync_ml(fft_length, cp_length, snr, ks0time, logging) elif SYNC == "pn": nco_sensitivity = -2.0/fft_length # correct for fine frequency self.ofdm_sync = ofdm_sync_pn(fft_length, cp_length, logging) elif SYNC == "pnac": nco_sensitivity = -2.0/fft_length # correct for fine frequency self.ofdm_sync = ofdm_sync_pnac(fft_length, cp_length, ks0time, logging) elif SYNC == "fixed": # for testing only; do not user over the air self.chan_filt = gr.multiply_const_cc(1.0) # remove filter and filter delay for this nsymbols = 18 # enter the number of symbols per packet freq_offset = 0.0 # if you use a frequency offset, enter it here nco_sensitivity = -2.0/fft_length # correct for fine frequency self.ofdm_sync = ofdm_sync_fixed(fft_length, cp_length, nsymbols, freq_offset, logging) # Set up blocks self.chan_filt = list() self.sigmix = list() self.sampler = list() self.fft_demod = list() # Deinterleave the incoming stream into separate channels self.deint = gr.deinterleave(gr.sizeof_gr_complex) # generate a signal proportional to frequency error of sync block self.nco = gr.frequency_modulator_fc(nco_sensitivity) # Manage and combine all channels if 0: self.ofdm_frame_acq = gr.ofdm_mrc_frame_acquisition(nrxchans, occupied_tones, fft_length, cp_length, ks[0]) else: print "Transmitter using ", ntxchans print "Receiver using ", nrxchans if(ntxchans == 1): self.ofdm_frame_acq = gr.ofdm_alamouti_frame_acquisition(ntxchans, occupied_tones, fft_length, cp_length, ks[0], occupied_tones*[0,]) else: self.ofdm_frame_acq = gr.ofdm_alamouti_frame_acquisition(ntxchans, occupied_tones, fft_length, cp_length, ks[0], ks[1]) self.connect(self, self.deint) # deinterleave channels self.connect((self.ofdm_sync,0), self.nco) # use sync freq. offset to derotate signal for i in xrange(nrxchans): self.chan_filt.append(gr.fft_filter_ccc(1, chan_coeffs)) self.sigmix.append(gr.multiply_cc()) self.sampler.append(gr.ofdm_sampler(fft_length, fft_length+cp_length)) self.fft_demod.append(gr.fft_vcc(fft_length, True, win, True)) self.connect((self.deint, i), self.chan_filt[i]) # filter the input channel self.connect(self.nco, (self.sigmix[i],1)) # use sync freq. offset to derotate signal self.connect(self.chan_filt[i], (self.sigmix[i],0)) # signal to be derotated self.connect(self.sigmix[i], (self.sampler[i],0)) # sample off timing signal detected in sync alg self.connect((self.ofdm_sync,1), (self.sampler[i],1)) # timing signal to sample at self.connect((self.sampler[i],0), self.fft_demod[i]) # send derotated sampled signal to FFT self.connect(self.fft_demod[i], (self.ofdm_frame_acq,1+i)) # find frame start and equalize signal if logging: self.connect(self.chan_filt[i], gr.file_sink(gr.sizeof_gr_complex, ("ofdm_mimo-receiver-chan%02d-chan_filt_c.dat" % i))) self.connect(self.fft_demod[i], gr.file_sink(gr.sizeof_gr_complex*fft_length, ("ofdm_mimo-receiver-chan%02d-fft_out_c.dat" % i))) self.connect(self.sampler[i], gr.file_sink(gr.sizeof_gr_complex*fft_length, ("ofdm_mimo-receiver-chan%02d-sampler_c.dat" % i))) self.connect(self.sigmix[i], gr.file_sink(gr.sizeof_gr_complex, ("ofdm_mimo-receiver-chan%02d-sigmix_c.dat" % i))) if logging: self.connect((self.ofdm_frame_acq,0), gr.file_sink(gr.sizeof_gr_complex*occupied_tones, "ofdm_mimo-receiver-frame_acq_c.dat")) self.connect((self.ofdm_frame_acq,1), gr.file_sink(1, "ofdm_mimo-receiver-found_corr_b.dat")) self.connect(self.nco, gr.file_sink(gr.sizeof_gr_complex, "ofdm_mimo-receiver-nco_c.dat")) self.connect(self.chan_filt[0], self.ofdm_sync) # into the synchronization alg. self.connect((self.sampler[0],1), (self.ofdm_frame_acq,0)) # send timing signal to signal frame start self.connect((self.sampler[i],1), gr.null_sink(fft_length*gr.sizeof_char)) self.connect((self.ofdm_frame_acq,0), (self,0)) # finished with fine/coarse freq correction, self.connect((self.ofdm_frame_acq,1), (self,1)) # frame and symbol timing, and equalization
def __init__(self, rx_callback_cc2420, rx_callback_cc1k): gr.flow_graph.__init__(self) cc2420_cordic_freq = 2475000000 cc2420_data_rate = 2000000 cc1k_cordic_freq = 434845200 cc1k_data_rate = 38400 cc1k_sps = 8 payload_size = 128 print "cc2420_cordic_freq = %s" % (eng_notation.num_to_str (cc2420_cordic_freq)) print "cc1k_cordic_freq = %s" % (eng_notation.num_to_str (cc1k_cordic_freq)) # ---------------------------------------------------------------- self.data_rate = cc2420_data_rate self.samples_per_symbol = 2 self.usrp_decim = int (64e6 / self.samples_per_symbol / self.data_rate) self.fs = self.data_rate * self.samples_per_symbol payload_size = 128 # bytes print "usrp_decim = ", self.usrp_decim print "fs = ", eng_notation.num_to_str(self.fs) u = usrp.source_c (0, nchan=2) u.set_decim_rate(self.usrp_decim) self.subdev = (u.db[0][0], u.db[1][0]) print "Using RX d'board %s" % (self.subdev[0].side_and_name(),) print "Using RX d'board %s" % (self.subdev[1].side_and_name(),) u.set_mux(0x2301) width = 8 shift = 8 format = u.make_format(width, shift) r = u.set_format(format) #this is the cc2420 code u.tune(self.subdev[0]._which, self.subdev[0], cc2420_cordic_freq) u.tune(self.subdev[1]._which, self.subdev[1], cc1k_cordic_freq) u.set_pga(0, 0) u.set_pga(1, 0) self.u = u # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) #self.u = gr.file_source(gr.sizeof_gr_complex, 'rx_test.dat') # CC2420 receiver self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(self, callback=rx_callback_cc2420, sps=self.samples_per_symbol, symbol_rate=self.data_rate, threshold=-1) self.squelch = gr.pwr_squelch_cc(50, 1, 0, True) self.connect((di,0), self.squelch, self.packet_receiver) # CC1K receiver gain_mu = 0.002*self.samples_per_symbol self.packet_receiver_cc1k = cc1k_sos_pkt.cc1k_demod_pkts(self, callback=rx_callback_cc1k, sps=cc1k_sps, symbol_rate=cc1k_data_rate, p_size=payload_size, threshold=-1) #self.squelch2 = gr.pwr_squelch_cc(50, 1, 0, True) keep = gr.keep_one_in_n(gr.sizeof_gr_complex, 13) #self.connect((di, 1), keep, self.squelch2, self.packet_receiver_cc1k) self.connect((di, 1), keep, self.packet_receiver_cc1k)
def __init__(self, pkt_size=32032): gr.hier_block2.__init__( self, "Sync Watcher", gr.io_signature(1, 1, gr.sizeof_char * 1), gr.io_signature(0, 0, 0), ) ################################################## # Variables ################################################## crc_size = 32 # size of crc, in bits preamble_size = 16 access_code_size = 64 # size of packet, including crc, but not including preamble or access_code # This is (probably) the number of bits left in the packet once an access_code flag is seen # TODO: verify timing of access_code flag with respect to the rest of the packet self.pkt_size = pkt_size #use to be: 4000*8 + crc_size # number of bits we're interested in from the input byte stream self.significant_bits = 2 ################################################## # Blocks ################################################## # unpack bits takes one byte in and splits it into k bytes out. # bit 0 from input is placed in bit 0 of output byte 0 # bit 1 from input is placed in bit 0 of output byte 1 # ... and so on up to k self.unpack_bits = gr.unpack_k_bits_bb(self.significant_bits) # deinterleave splits single stream of bytes at rate of N bytes/sec into two separate # streams of bytes, each at a rate of N/2 bytes/sec self.deinterleave = gr.deinterleave(gr.sizeof_char * 1) self.char_to_float = gr.char_to_float(1) # Setup the downcounter that will raise the flag for max iterations upon high input self.downcounter = digital_ll.downcounter(self.pkt_size) # Null sinks 1 and 2 for tieing off lose ends self.null_sink_1 = gr.null_sink(gr.sizeof_char * 1) self.null_sink_2 = gr.null_sink(gr.sizeof_float * 1) #self.file_sink = gr.file_sink(gr.sizeof_short * 1, "/home/interlaken/a/cr22845/SDR/generalized-sdr-comms/demos/csma_month2/flag_out.dat") ################################################## # Connections ################################################## # unpack byte with bit 0 = data bit and bit 1 = flag bit into two bytes, byte 0 has bit # 0 = data bit and byte 1 has bit 0 = flag bit self.connect((self, 0), (self.unpack_bits, 0)) # deinterleave to get two streams. One byte stream has only data bits, on stream has only # flag bits self.connect((self.unpack_bits, 0), (self.deinterleave, 0)) # send data bytes to null self.connect((self.deinterleave, 1), (self.null_sink_1, 0)) # convert flag bytes to floats for use with downcounter self.connect((self.deinterleave, 0), (self.char_to_float, 0)) # connect the float output to the downcounter block self.connect((self.char_to_float, 0), (self.downcounter, 0)) # finally tie it off with a null sink self.connect((self.downcounter, 0), (self.null_sink_2, 0))
def __init__(self, frame, panel, vbox, argv): stdgui.gui_flow_graph.__init__(self) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=first one with a daughterboard)", ) parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]" ) parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option( "-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display" ) parser.add_option("-F", "--filename", default=None, help="Name of file with filter coefficients") parser.add_option("-C", "--cfilename", default=None, help="Name of file with compensator coefficients") parser.add_option("-B", "--bitstream", default="mrfm.rbf", help="Name of FPGA Bitstream file (.rbf)") parser.add_option( "-n", "--frame-decim", type="int", default=20, help="set oscope frame decimation factor to n [default=12]" ) (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True # default filter coefs b00 = b01 = 16384 b10 = b20 = a10 = a20 = b11 = b21 = a11 = a21 = 0 ba = read_ints(options.filename) if len(ba) >= 6: b00 = ba[0] b10 = ba[1] b20 = ba[2] a10 = ba[4] a20 = ba[5] if len(ba) >= 12: b01 = ba[6] b11 = ba[7] b21 = ba[8] a11 = ba[10] a21 = ba[11] print b00, b10, b20, a10, a20, b01, b11, b21, a11, a21 # default compensator coefficients c11 = c22 = 1 c12 = c21 = cscale = 0 cs = read_ints(options.cfilename) if len(cs) >= 5: c11 = cs[0] c12 = cs[1] c21 = cs[2] c22 = cs[3] cscale = cs[4] print c11, c12, c21, c22, cscale # build the graph self.u = mrfm.source_c(options.bitstream) self.u.set_decim_rate(options.decim) self.u.set_center_freq(options.freq) frac_bits = 14 self.u.set_coeffs(frac_bits, b20, b10, b00, a20, a10, b21, b11, b01, a21, a11) self.u.set_compensator(c11, c12, c21, c22, cscale) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) print "format =", hex(format) r = self.u.set_format(format) print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) # input_rate = self.u.adc_freq() / self.u.decim_rate() input_rate = self.u.adc_freq() / options.decim # fft_rate = 15 fft_rate = 5 self.deint = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, self.deint) if options.waterfall: self.scope1 = waterfallsink.waterfall_sink_c( self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate ) self.scope2 = waterfallsink.waterfall_sink_c( self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate ) elif options.oscilloscope: self.scope1 = scopesink.scope_sink_c( self, panel, sample_rate=input_rate, frame_decim=options.frame_decim ) # added option JPJ 4/21/2006 self.scope2 = scopesink.scope_sink_c(self, panel, sample_rate=input_rate, frame_decim=options.frame_decim) else: self.scope1 = fftsink.fft_sink_c(self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) self.scope2 = fftsink.fft_sink_c(self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) # Show I, I' on top scope panel, Q, Q' on bottom # self.fin = gr.complex_to_float() # self.fout = gr.complex_to_float() # self.connect((self.deint,0), self.fin) # self.connect((self.deint,1), self.fout) # self.ii = gr.float_to_complex() # self.qq = gr.float_to_complex() # self.connect((self.fin,0), (self.ii,0)) # self.connect((self.fout,0), (self.ii,1)) # self.connect((self.fin,1), (self.qq,0)) # self.connect((self.fout,1), (self.qq,1)) # self.connect(self.ii, self.scope1) # self.connect(self.qq, self.scope2) self.connect((self.deint, 0), self.scope1) self.connect((self.deint, 1), self.scope2) self._build_gui(vbox) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") if self.show_debug_info: self.myform["decim"].set_value(self.u.decim_rate()) self.myform["fs@usb"].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform["dbname"].set_value(self.subdev.name())
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(option_class=eng_option) parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help= "select USRP Rx side A or B (default=first one with a daughterboard)" ) parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option( "-C", "--basic-complex", action="store_true", default=False, help= "Use both inputs of a basicRX or LFRX as a single Complex input channel" ) parser.add_option( "-D", "--basic-dualchan", action="store_true", default=False, help= "Use both inputs of a basicRX or LFRX as seperate Real input channels" ) parser.add_option( "-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option( "-v", "--v-scale", type="eng_float", default=1000, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option( "-t", "--t-scale", type="eng_float", default=49e-6, help="set oscope initial s/div to SCALE [default=50us]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True # build the graph if options.basic_dualchan: self.num_inputs = 2 else: self.num_inputs = 1 if options.no_hb or (options.decim < 8): #Min decimation of this firmware is 4. #contains 4 Rx paths without halfbands and 0 tx paths. self.fpga_filename = "std_4rx_0tx.rbf" self.u = usrp.source_c(nchan=self.num_inputs, decim_rate=options.decim, fpga_filename=self.fpga_filename) else: #Min decimation of standard firmware is 8. #standard fpga firmware "std_2rxhb_2tx.rbf" #contains 2 Rx paths with halfband filters and 2 tx paths (the default) self.u = usrp.source_c(nchan=self.num_inputs, decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) #print "format =", hex(format) r = self.u.set_format(format) #print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) if (options.basic_complex or options.basic_dualchan): if ((self.subdev.dbid() == usrp_dbid.BASIC_RX) or (self.subdev.dbid() == usrp_dbid.LF_RX)): side = options.rx_subdev_spec[0] # side A = 0, side B = 1 if options.basic_complex: #force Basic_RX and LF_RX in complex mode (use both I and Q channel) print "Receiver daughterboard forced in complex mode. Both inputs will combined to form a single complex channel." self.dualchan = False if side == 0: self.u.set_mux( 0x00000010 ) #enable adc 0 and 1 to form a single complex input on side A else: #side ==1 self.u.set_mux( 0x00000032 ) #enable adc 3 and 2 to form a single complex input on side B elif options.basic_dualchan: #force Basic_RX and LF_RX in dualchan mode (use input A for channel 0 and input B for channel 1) print "Receiver daughterboard forced in dualchannel mode. Each input will be used to form a seperate channel." self.dualchan = True if side == 0: self.u.set_mux( gru.hexint(0xf0f0f1f0) ) #enable adc 0, side A to form a real input on channel 0 and adc1,side A to form a real input on channel 1 else: #side ==1 self.u.set_mux( 0xf0f0f3f2 ) #enable adc 2, side B to form a real input on channel 0 and adc3,side B to form a real input on channel 1 else: sys.stderr.write( 'options basic_dualchan or basic_complex is only supported for Basic Rx or LFRX at the moment\n' ) sys.exit(1) else: self.dualchan = False self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) input_rate = self.u.adc_freq() / self.u.decim_rate() self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) if self.dualchan: # deinterleave two channels from FPGA self.di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, self.di) self.connect((self.di, 0), (self.scope, 0)) self.connect((self.di, 1), (self.scope, 1)) else: self.connect(self.u, self.scope) self._build_gui(vbox) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: if ((self.subdev.dbid() == usrp_dbid.BASIC_RX) or (self.subdev.dbid() == usrp_dbid.LF_RX)): #for Basic RX and LFRX if no freq is specified you probably want 0.0 Hz and not 45 GHz options.freq = 0.0 else: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if self.num_inputs == 2: self.myform['baseband2'].set_value(0) self.myform['ddc2'].set_value(0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") if self.num_inputs == 2: if not (self.set_freq2(options.freq)): self._set_status_msg( "Failed to set initial frequency for channel 2")
def __init__(self, center_freq, offset_freq, decimate_am=1, play_audio=False, filename=None): """Configure the RTL-SDR and GNU Radio""" super(rtlsdr_am_stream, self).__init__() audio_rate = 44100 device_rate = audio_rate * 25 output_rate = audio_rate / float(decimate_am) self.rate = output_rate filename = filename or "/home/martin/src/rtl/hydrometer/rawrrr" self.gr_file_source_0 = gr.file_source( gr.sizeof_char * 1, filename, False) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_char * 1) # self.gr_uchar_to_float_1 = gr.uchar_to_float() self.gr_uchar_to_float_0 = gr.uchar_to_float() # self.gr_add_const_vxx_1 = gr.add_const_vff((-127, )) # self.gr_add_const_vxx_0 = gr.add_const_vff((-127, )) # self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0.065, )) # self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((0.065, )) # self.gr_float_to_complex_0 = gr.float_to_complex(1) # self.osmosdr_source = osmosdr.source_c("") # self.osmosdr_source.set_center_freq(freq) # self.osmosdr_source.set_sample_rate(device_rate) # taps = firdes.low_pass( # 1, device_rate, 40000, 5000, firdes.WIN_HAMMING, 6.76) # self.freq_filter = gr.freq_xlating_fir_filter_ccc( # 25, taps, -freq_offs, device_rate) # self.am_demod = blks2.am_demod_cf( # channel_rate=audio_rate, # audio_decim=1, # audio_pass=5000, # audio_stop=5500, # ) # self.resampler = blks2.rational_resampler_fff( # interpolation=1, # decimation=decimate_am, # ) self.sink = gr_queue.queue_sink_c() # self.connect(self.osmosdr_source, self.freq_filter, self.am_demod) self.connect((self.gr_file_source_0, 0), (self.gr_deinterleave_0, 0)) # self.connect((self.gr_deinterleave_0, 0), # (self.gr_uchar_to_float_0, 0)) # self.connect((self.gr_uchar_to_float_0, 0), # (self.gr_add_const_vxx_0, 0)) # self.connect((self.gr_add_const_vxx_0, 0), # (self.gr_multiply_const_vxx_0, 0)) # self.connect((self.gr_multiply_const_vxx_0, 0), # (self.gr_float_to_complex_0, 0)) # self.connect((self.gr_deinterleave_0, 1), # (self.gr_uchar_to_float_1, 0)) # self.connect((self.gr_uchar_to_float_1, 0), # (self.gr_add_const_vxx_1, 0)) # self.connect((self.gr_add_const_vxx_1, 0), # (self.gr_multiply_const_vxx_1, 0)) # self.connect((self.gr_multiply_const_vxx_1, 0), # (self.gr_float_to_complex_0, 1)) # self.connect( # self.gr_float_to_complex_0, self.freq_filter, self.am_demod) # self.connect(self.am_demod, self.resampler, self.sink) self.processed_source = (self.gr_deinterleave_0, 0) self.connect(self.processed_source, self.sink)
def __init__(self): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1) < 1e6: options.f1 *= 1e6 if abs(options.f2) < 1e6: options.f2 *= 1e6 if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" # build graph self.u = usrp.source_c(0, nchan=2) # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) mv = usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec) mv |= (mv << 8) & 0xff00 # both DDC inputs setup same way self.u.set_mux(mv) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) mid_freq = (f[0] + f[1]) / 2 # set front end PLL to middle frequency ok, baseband_freq = self.subdev.set_freq(mid_freq) for n in range(2): chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) guts = blks2.wfm_rcv (demod_rate, audio_decimation) volume_control = gr.multiply_const_ff(self.vol) self.connect((di, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (audio_sink, n)) dxc_freq, inverted = usrp.calc_dxc_freq(f[n], baseband_freq, self.u.converter_rate()) self.u.set_rx_freq(n, dxc_freq) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 # set initial values self.set_gain(options.gain)
def __init__(self, freq_corr=0, avg_frames=1, decim=16, N_id_2=0, N_id_1=134): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.avg_frames = avg_frames self.decim = decim self.N_id_2 = N_id_2 self.N_id_1 = N_id_1 ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720*5/decim self.symbol_start = symbol_start = 144/decim self.slot_0_10 = slot_0_10 = 1 self.samp_rate = samp_rate = 30720e3/decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048/decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo") self.Add(self.notebook_0) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c( self.notebook_0.GetPage(3).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win) self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win) self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win) self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f( self.notebook_0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=100/avg_frames, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win) _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL) self._symbol_start_text_box = forms.text_box( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, label='symbol_start', converter=forms.int_converter(), proportion=0, ) self._symbol_start_slider = forms.slider( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, minimum=0, maximum=144/decim, num_steps=144/decim, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_symbol_start_sizer) self.sss_ml_fd_0 = sss_ml_fd( decim=decim, avg_frames=avg_frames, N_id_1=N_id_1, N_id_2=N_id_2, slot_0_10=slot_0_10, ) self.pss_chan_est2_0 = pss_chan_est2( N_id_2=N_id_2, ) self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re) self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re) self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re) self.gr_vector_to_stream_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re) self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate) self.gr_stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, N_re) self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex*1, (N_re/2, N_re/2)) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re) self.gr_multiply_xx_1 = gr.multiply_vcc(N_re) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.005*exp(rot*2*numpy.pi*1j), )) self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re/2, fft_size, (fft_size-N_re)/2-1) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re/2, fft_size, (fft_size)/2) self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex*N_re) self.gr_channel_model_0 = gr.channel_model( noise_voltage=0.005*noise_level, frequency_offset=0.0, epsilon=1, taps=(0.005*exp(rot*2*numpy.pi*1j), ), noise_seed=0, ) self.gr_add_xx_0 = gr.add_vcc(1) self.blks2_selector_0_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=2, num_outputs=1, input_index=0, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=3, num_outputs=2, input_index=0, output_index=0, ) ################################################## # Connections ################################################## self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0)) self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0)) self.connect((self.gr_channel_model_0, 0), (self.blks2_selector_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_selector_0_0, 1)) self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0)) self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_vector_to_stream_0_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0_0, 0), (self.wxgui_scopesink2_0_1_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.wxgui_scopesink2_0_1_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_0_1, 0), (self.wxgui_scopesink2_0_1_0_1, 0)) self.connect((self.gr_vector_to_stream_0_0_1_0, 0), (self.wxgui_scopesink2_0_1_0_1, 1)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_0_1_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1)) self.connect((self.gr_multiply_xx_1_0, 0), (self.gr_vector_to_stream_0_0_1, 0)) self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0_0, 0)) self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1)) self.connect((self.gr_stream_mux_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2)) self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
def __init__(self, frame, panel, vbox, argv): stdgui.gui_flow_graph.__init__(self) self.frame = frame self.panel = panel parser = OptionParser (option_class=eng_option) #parser.add_option("-S", "--subdev", type="subdev", default=(0, None), # help="select USRP Rx side A or B (default=A)") parser.add_option("-d", "--decim", type="int", default=128, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=146.585e6, help="set frequency to FREQ [default=%default])", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=20, help="set gain in dB [default=%default]") parser.add_option("-F", "--filter", action="store_true", default=True, help="Enable channel filter") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit nchan = 4 if options.filter: sw_decim = 4 else: sw_decim = 1 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf") if self.u.nddc() < nchan: sys.stderr.write('This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % ( nchan, self.u.nddc())) raise SystemExit if not self.u.set_nchannels(nchan): sys.stderr.write('set_nchannels(%d) failed\n' % (nchan,)) raise SystemExit input_rate = self.u.adc_freq() / self.u.decim_rate() print "USB data rate = %s" % (eng_notation.num_to_str(input_rate),) print "Scope data rate = %s" % (eng_notation.num_to_str(input_rate/sw_decim),) self.subdev = self.u.db[0] + self.u.db[1] if (len (self.subdev) != 4 or self.u.db[0][0].dbid() != usrp_dbid.BASIC_RX or self.u.db[1][0].dbid() != usrp_dbid.BASIC_RX): sys.stderr.write('This code requires a Basic Rx board on Sides A & B\n') sys.exit(1) self.u.set_mux(gru.hexint(0xf3f2f1f0)) # deinterleave four channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, di) # taps for channel filter chan_filt_coeffs = optfir.low_pass (1, # gain input_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) for i in range(nchan): scope = fftsink.fft_sink_c(self, panel, sample_rate=input_rate/sw_decim, title="Input %d" % (i,), ref_level=80, y_per_div=20) vbox.Add(scope.win, 10, wx.EXPAND) if options.filter: chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs) self.connect((di, i), chan_filt, scope) else: self.connect((di, i), scope) self.set_gain(options.gain) self.set_freq(options.freq)
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 (option_class=eng_option) #parser.add_option("-S", "--subdev", type="subdev", default=(0, None), # help="select USRP Rx side A or B (default=A)") parser.add_option("-d", "--decim", type="int", default=128, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=146.585e6, help="set frequency to FREQ [default=%default])", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=20, help="set gain in dB [default=%default]") parser.add_option("-F", "--filter", action="store_true", default=True, help="Enable channel filter") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit nchan = 4 if options.filter: sw_decim = 4 else: sw_decim = 1 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf") if self.u.nddcs() < nchan: sys.stderr.write('This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % ( nchan, self.u.nddcs())) raise SystemExit if not self.u.set_nchannels(nchan): sys.stderr.write('set_nchannels(%d) failed\n' % (nchan,)) raise SystemExit input_rate = self.u.adc_freq() / self.u.decim_rate() print "USB data rate = %s" % (eng_notation.num_to_str(input_rate),) print "Scope data rate = %s" % (eng_notation.num_to_str(input_rate/sw_decim),) self.subdev = self.u.db(0) + self.u.db(1) if (len(self.subdev) < 4 or self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX or self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX): sys.stderr.write('This code requires a Basic Rx board on Sides A & B\n') sys.exit(1) self.u.set_mux(gru.hexint(0xf3f2f1f0)) # deinterleave four channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, di) # our destination (8 float inputs) self.scope = scopesink2.scope_sink_f(panel, sample_rate=input_rate/sw_decim, num_inputs=2*nchan) # taps for channel filter chan_filt_coeffs = optfir.low_pass (1, # gain input_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) # bust the deinterleaved complex channels into floats for i in range(nchan): if options.filter: chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs) c2f = gr.complex_to_float() self.connect((di, i), chan_filt, c2f) else: c2f = gr.complex_to_float() self.connect((di, i), c2f) self.connect((c2f, 0), (self.scope, 2*i + 0)) self.connect((c2f, 1), (self.scope, 2*i + 1)) self._build_gui(vbox) self.set_gain(options.gain) self.set_freq(options.freq)
def __init__(self, fg, master_serialno, decim, nchan=2, pga_gain=0.0, cordic_freq=0.0, mux=None, align_interval=-1, fpga_filename="multi_2rxhb_2tx.rbf"): """ Align multiple sources (usrps) using samplenumbers in the first channel. Takes two ore more sources producing interleaved shorts. produces nchan * nsources gr_complex output streams. @param nchan: number of interleaved channels in source @param align_interval: number of samples to minimally skip between alignments default = -1 which means align only once per work call. @param master_serial_no: serial number of the source which must be the master. Exported sub-blocks (attributes): master_source slave_source usrp_master usrp_slave """ mode = usrp.FPGA_MODE_NORMAL mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT align = gr.align_on_samplenumbers_ss(nchan, align_interval) self.usrp_master = None self.usrp_slave = None # um is master usrp # us is slave usrp if mux is None: mux = self.get_default_mux( ) #Note that all channels have shifted left because of the added 32 bit counter channel u1 = usrp.source_s(1, decim, nchan, gru.hexint(mux), mode, fpga_filename=fpga_filename) u0 = usrp.source_s(0, decim, nchan, gru.hexint(mux), mode, fpga_filename=fpga_filename) print 'usrp[0] serial', u0.serial_number() print 'usrp[1] serial', u1.serial_number() #default, choose the second found usrp as master (which is usually the usrp which was first plugged in) um_index = 1 um = u1 us_index = 0 us = u0 if (not (master_serialno is None)): #((master_serialno>0) | (master_serialno <-2)): if (u0.serial_number() == master_serialno): um_index = 0 um = u0 us_index = 1 us = u1 elif (u1.serial_number() != master_serialno): errorstring = 'Error. requested master_serialno ' + master_serialno + ' not found\n' errorstring = errorstring + 'Available are:\n' errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number( ) + '\n' errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number( ) + '\n' print errorstring raise ValueError, errorstring else: #default, just choose the first found usrp as master um_index = 1 um = u1 us_index = 0 us = u0 self.usrp_master = um self.usrp_slave = us print 'usrp_master=usrp[%i] serial_no = %s' % ( um_index, self.usrp_master.serial_number(), ) print 'usrp_slave=usrp[%i] serial_no = %s' % ( us_index, self.usrp_slave.serial_number(), ) self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0, 0)) self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1, 0)) self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0, 0)) self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1, 0)) #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate) if not (pga_gain is None): um.set_pga(0, pga_gain) um.set_pga(1, pga_gain) us.set_pga(0, pga_gain) us.set_pga(1, pga_gain) self.input_rate = um.adc_freq() / um.decim_rate() deintm = gr.deinterleave(gr.sizeof_gr_complex) deints = gr.deinterleave(gr.sizeof_gr_complex) nullsinkm = gr.null_sink(gr.sizeof_gr_complex) nullsinks = gr.null_sink(gr.sizeof_gr_complex) tocomplexm = gr.interleaved_short_to_complex() tocomplexs = gr.interleaved_short_to_complex() fg.connect(um, (align, 0)) fg.connect(us, (align, 1)) fg.connect((align, 0), tocomplexm) fg.connect((align, 1), tocomplexs) fg.connect(tocomplexm, deintm) fg.connect(tocomplexs, deints) fg.connect( (deintm, 0), nullsinkm ) #The counters are not usefull for the user but must be connected to something fg.connect( (deints, 0), nullsinks ) #The counters are not usefull for the user but must be connected to something if 4 == nchan: nullsinkm3 = gr.null_sink(gr.sizeof_gr_complex) nullsinks3 = gr.null_sink(gr.sizeof_gr_complex) fg.connect( (deintm, 3), nullsinkm3) #channel 4 is not used but must be connected fg.connect( (deints, 3), nullsinks3) #channel 4 is not used but must be connected self.fg = fg self.master_source = deintm self.slave_source = deints if not (cordic_freq is None): um.set_rx_freq(1, cordic_freq) um.set_rx_freq(0, cordic_freq) us.set_rx_freq(1, cordic_freq) us.set_rx_freq(0, cordic_freq) self.enable_master_and_slave() # add an idle handler self.unsynced = True
def __init__(self, freq_corr=0, N_id_1=134, avg_frames=1, N_id_2=0, decim=16): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr2 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.N_id_1 = N_id_1 self.avg_frames = avg_frames self.N_id_2 = N_id_2 self.decim = decim ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720 * 5 / decim self.samp_rate = samp_rate = 30720e3 / decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048 / decim ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.gr_vector_to_stream_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_2 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_float * 1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, fft_size, False).get_data()), True, fft_size) self.gr_vector_source_x_0 = gr.vector_source_c( (gen_sss_fd(N_id_1, N_id_2, fft_size).get_sss(True)), True, fft_size) self.gr_stream_to_vector_0_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_repeat_0 = gr.repeat(gr.sizeof_float * 1, fft_size) self.gr_null_sink_0_0 = gr.null_sink(gr.sizeof_gr_complex * 1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1 = gr.multiply_vcc(1) self.gr_multiply_xx_0 = gr.multiply_vcc(fft_size) self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((1 / 1500., )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (exp(rot * 2 * numpy.pi * 1j), )) self.gr_interleave_0 = gr.interleave(gr.sizeof_gr_complex * fft_size) self.gr_integrate_xx_0 = gr.integrate_ff(fft_size) self.gr_float_to_complex_0_0 = gr.float_to_complex(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/foo_pss0_sss_in.cfile", True) self.gr_fft_vxx_1 = gr.fft_vcc(fft_size, False, (window.blackmanharris(1024)), True, 1) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_divide_xx_0_1 = gr.divide_cc(1) self.gr_divide_xx_0_0 = gr.divide_ff(1) self.gr_divide_xx_0 = gr.divide_cc(1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * fft_size) self.gr_conjugate_cc_1 = gr.conjugate_cc() self.gr_conjugate_cc_0 = gr.conjugate_cc() self.gr_complex_to_mag_squared_0_0 = gr.complex_to_mag_squared(1) self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(fft_size) self.gr_add_xx_0 = gr.add_vcc(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1, )) self.const_source_x_0_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.gr_file_source_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_conjugate_cc_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_integrate_xx_0, 0)) self.connect((self.gr_integrate_xx_0, 0), (self.gr_repeat_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_divide_xx_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_conjugate_cc_1, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_vector_to_stream_0_1, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_conjugate_cc_1, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.gr_complex_to_mag_squared_0_0, 0)) self.connect((self.gr_complex_to_mag_squared_0_0, 0), (self.gr_divide_xx_0_0, 0)) self.connect((self.gr_repeat_0, 0), (self.gr_divide_xx_0_0, 1)) self.connect((self.gr_divide_xx_0_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_complex_0_0, 0)) self.connect((self.const_source_x_0_0, 0), (self.gr_float_to_complex_0_0, 1)) self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_divide_xx_0_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_divide_xx_0_1, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_vector_to_stream_0_2, 0), (self.gr_conjugate_cc_0, 0)) self.connect((self.gr_divide_xx_0_1, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_vector_source_x_0, 0), (self.gr_interleave_0, 1)) self.connect((self.gr_interleave_0, 0), (self.gr_fft_vxx_1, 0)) self.connect((self.gr_fft_vxx_1, 0), (self.gr_vector_to_stream_1, 0)) self.connect((self.gr_vector_source_x_0_0, 0), (self.gr_interleave_0, 0)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_2, 0)) self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_vector_to_stream_1, 0), (self.gr_add_xx_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_1, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.gr_divide_xx_0_1, 0), (self.wxgui_scopesink2_0, 0))
def __init__(self, rx_callback_cc2420, rx_callback_cc1k): gr.flow_graph.__init__(self) cc2420_cordic_freq = 2475000000 cc2420_data_rate = 2000000 cc1k_cordic_freq = 434845200 cc1k_data_rate = 38400 cc1k_sps = 8 payload_size = 128 print "cc2420_cordic_freq = %s" % ( eng_notation.num_to_str(cc2420_cordic_freq)) print "cc1k_cordic_freq = %s" % ( eng_notation.num_to_str(cc1k_cordic_freq)) # ---------------------------------------------------------------- self.data_rate = cc2420_data_rate self.samples_per_symbol = 2 self.usrp_decim = int(64e6 / self.samples_per_symbol / self.data_rate) self.fs = self.data_rate * self.samples_per_symbol payload_size = 128 # bytes print "usrp_decim = ", self.usrp_decim print "fs = ", eng_notation.num_to_str(self.fs) u = usrp.source_c(0, nchan=2) u.set_decim_rate(self.usrp_decim) self.subdev = (u.db[0][0], u.db[1][0]) print "Using RX d'board %s" % (self.subdev[0].side_and_name(), ) print "Using RX d'board %s" % (self.subdev[1].side_and_name(), ) u.set_mux(0x2301) width = 8 shift = 8 format = u.make_format(width, shift) r = u.set_format(format) #this is the cc2420 code u.tune(self.subdev[0]._which, self.subdev[0], cc2420_cordic_freq) u.tune(self.subdev[1]._which, self.subdev[1], cc1k_cordic_freq) u.set_pga(0, 0) u.set_pga(1, 0) self.u = u # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) #self.u = gr.file_source(gr.sizeof_gr_complex, 'rx_test.dat') # CC2420 receiver self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback_cc2420, sps=self.samples_per_symbol, symbol_rate=self.data_rate, threshold=-1) self.squelch = gr.pwr_squelch_cc(50, 1, 0, True) self.connect((di, 0), self.squelch, self.packet_receiver) # CC1K receiver gain_mu = 0.002 * self.samples_per_symbol self.packet_receiver_cc1k = cc1k_sos_pkt.cc1k_demod_pkts( self, callback=rx_callback_cc1k, sps=cc1k_sps, symbol_rate=cc1k_data_rate, p_size=payload_size, threshold=-1) #self.squelch2 = gr.pwr_squelch_cc(50, 1, 0, True) keep = gr.keep_one_in_n(gr.sizeof_gr_complex, 13) #self.connect((di, 1), keep, self.squelch2, self.packet_receiver_cc1k) self.connect((di, 1), keep, self.packet_receiver_cc1k)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel self.offset = 0.0 parser = OptionParser(option_class=eng_option) parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help= "select USRP Rx side A or B (default=first one with a daughterboard)" ) parser.add_option( "-d", "--decim", type="int", default=256, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option( "-p", "--protocol", type="int", default=0, help="set protocol: 0 = RDLAP 19.2kbps (default); 1 = APCO25") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option( "-C", "--basic-complex", action="store_true", default=False, help= "Use both inputs of a basicRX or LFRX as a single Complex input channel" ) parser.add_option( "-D", "--basic-dualchan", action="store_true", default=False, help= "Use both inputs of a basicRX or LFRX as seperate Real input channels" ) parser.add_option( "-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option( "-v", "--v-scale", type="eng_float", default=1000, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option( "-t", "--t-scale", type="eng_float", default=49e-6, help="set oscope initial s/div to SCALE [default=50us]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True # build the graph if options.basic_dualchan: self.num_inputs = 2 else: self.num_inputs = 1 if options.no_hb or (options.decim < 8): #Min decimation of this firmware is 4. #contains 4 Rx paths without halfbands and 0 tx paths. self.fpga_filename = "std_4rx_0tx.rbf" self.u = usrp.source_c(nchan=self.num_inputs, decim_rate=options.decim, fpga_filename=self.fpga_filename) else: #Min decimation of standard firmware is 8. #standard fpga firmware "std_2rxhb_2tx.rbf" #contains 2 Rx paths with halfband filters and 2 tx paths (the default) self.u = usrp.source_c(nchan=self.num_inputs, decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) #print "format =", hex(format) r = self.u.set_format(format) #print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) if (options.basic_complex or options.basic_dualchan): if ((self.subdev.dbid() == usrp_dbid.BASIC_RX) or (self.subdev.dbid() == usrp_dbid.LF_RX)): side = options.rx_subdev_spec[0] # side A = 0, side B = 1 if options.basic_complex: #force Basic_RX and LF_RX in complex mode (use both I and Q channel) print "Receiver daughterboard forced in complex mode. Both inputs will combined to form a single complex channel." self.dualchan = False if side == 0: self.u.set_mux( 0x00000010 ) #enable adc 0 and 1 to form a single complex input on side A else: #side ==1 self.u.set_mux( 0x00000032 ) #enable adc 3 and 2 to form a single complex input on side B elif options.basic_dualchan: #force Basic_RX and LF_RX in dualchan mode (use input A for channel 0 and input B for channel 1) print "Receiver daughterboard forced in dualchannel mode. Each input will be used to form a seperate channel." self.dualchan = True if side == 0: self.u.set_mux( gru.hexint(0xf0f0f1f0) ) #enable adc 0, side A to form a real input on channel 0 and adc1,side A to form a real input on channel 1 else: #side ==1 self.u.set_mux( 0xf0f0f3f2 ) #enable adc 2, side B to form a real input on channel 0 and adc3,side B to form a real input on channel 1 else: sys.stderr.write( 'options basic_dualchan or basic_complex is only supported for Basic Rx or LFRX at the moment\n' ) sys.exit(1) else: self.dualchan = False self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) input_rate = self.u.adc_freq() / self.u.decim_rate() self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) if self.dualchan: # deinterleave two channels from FPGA self.di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, self.di) self.connect((self.di, 0), (self.scope, 0)) self.connect((self.di, 1), (self.scope, 1)) else: self.connect(self.u, self.scope) self.msgq = gr.msg_queue(2) # queue that holds a maximum of 2 messages self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm) #------------------------------------------------------------------------------- if options.protocol == 0: # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel, self.symbol_rate = 9600 # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps self.channel_decimation = 10 # decimation (final rate should be at least several symbol rate) self.max_frequency_offset = 12000.0 # coarse carrier tracker leash, ~ half a channel either way self.symbol_deviation = 1200.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = 64e6 / options.decim # for USRP: 64MHz / FPGA decimation rate self.protocol_processing = fsk4.rdlap_f( self.msgq, 0) # desired protocol processing block selected here self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter characteristics channel_taps = optfir.low_pass( 1.0, # Filter gain self.input_sample_rate, # Sample rate 10000, # One-sided modulation bandwidth 12000, # One-sided channel bandwidth 0.1, # Passband ripple 60) # Stopband attenuation # symbol shaping filter characteristics symbol_coeffs = gr.firdes.root_raised_cosine( 1.0, # gain self.channel_rate, # sampling rate self.symbol_rate, # symbol rate 0.2, # width of trans. band 500) # filter type if options.protocol == 1: # ---------- APCO-25 C4FM Test Data self.symbol_rate = 4800 # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps self.channel_decimation = 20 # decimation self.max_frequency_offset = 6000.0 # coarse carrier tracker leash self.symbol_deviation = 600.0 # this is frequency offset from center of channel to +1 / -1 symbols self.input_sample_rate = 64e6 / options.decim # for USRP: 64MHz / FPGA decimation rate self.protocol_processing = fsk4.apco25_f(self.msgq, 0) self.channel_rate = self.input_sample_rate / self.channel_decimation # channel selection filter channel_taps = optfir.low_pass( 1.0, # Filter gain self.input_sample_rate, # Sample rate 5000, # One-sided modulation bandwidth 6500, # One-sided channel bandwidth 0.1, # Passband ripple 60) # Stopband attenuation # symbol shaping filter symbol_coeffs = gr.firdes.root_raised_cosine( 1.0, # gain self.channel_rate, # sampling rate self.symbol_rate, # symbol rate 0.2, # width of trans. band 500) # filter type # ----------------- End of setup block self.chan = gr.freq_xlating_fir_filter_ccf( self.channel_decimation, # Decimation rate channel_taps, # Filter taps 0.0, # Offset frequency self.input_sample_rate) # Sample rate self.scope2 = scopesink2.scope_sink_f(panel, sample_rate=self.symbol_rate, frame_decim=1, v_scale=2, t_scale=0.025, num_inputs=self.num_inputs) # also note: # this specifies the nominal frequency deviation for the 4-level fsk signal self.fm_demod_gain = self.channel_rate / (2.0 * pi * self.symbol_deviation) self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain) symbol_decim = 1 self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) # eventually specify: sample rate, symbol rate self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate, self.symbol_rate) #self.rdlap_processing = fsk4.rdlap_f(self.msgq, 0) self.connect(self.u, self.chan, self.fm_demod, self.symbol_filter, self.demod_fsk4, self.protocol_processing) self.connect(self.demod_fsk4, self.scope2) # --------------- End of most of the 4L-FSK hack & slash self._build_gui(vbox) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: if ((self.subdev.dbid() == usrp_dbid.BASIC_RX) or (self.subdev.dbid() == usrp_dbid.LF_RX)): #for Basic RX and LFRX if no freq is specified you probably want 0.0 Hz and not 45 GHz options.freq = 0.0 else: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if self.show_debug_info: # self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if self.num_inputs == 2: self.myform['baseband2'].set_value(0) self.myform['ddc2'].set_value(0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") if self.num_inputs == 2: if not (self.set_freq2(options.freq)): self._set_status_msg( "Failed to set initial frequency for channel 2")
def __init__(self, frame, panel, vbox, argv): stdgui.gui_flow_graph.__init__(self) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help= "select SMINI Rx side A or B (default=first one with a daughterboard)" ) parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display") parser.add_option("-F", "--filename", default=None, help="Name of file with filter coefficients") parser.add_option("-C", "--cfilename", default=None, help="Name of file with compensator coefficients") parser.add_option("-B", "--bitstream", default="mrfm.rbf", help="Name of FPGA Bitstream file (.rbf)") parser.add_option( "-n", "--frame-decim", type="int", default=20, help="set oscope frame decimation factor to n [default=12]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True # default filter coefs b00 = b01 = 16384 b10 = b20 = a10 = a20 = b11 = b21 = a11 = a21 = 0 ba = read_ints(options.filename) if len(ba) >= 6: b00 = ba[0] b10 = ba[1] b20 = ba[2] a10 = ba[4] a20 = ba[5] if len(ba) >= 12: b01 = ba[6] b11 = ba[7] b21 = ba[8] a11 = ba[10] a21 = ba[11] print b00, b10, b20, a10, a20, b01, b11, b21, a11, a21 # default compensator coefficients c11 = c22 = 1 c12 = c21 = cscale = 0 cs = read_ints(options.cfilename) if len(cs) >= 5: c11 = cs[0] c12 = cs[1] c21 = cs[2] c22 = cs[3] cscale = cs[4] print c11, c12, c21, c22, cscale # build the graph self.u = mrfm.source_c(options.bitstream) self.u.set_decim_rate(options.decim) self.u.set_center_freq(options.freq) frac_bits = 14 self.u.set_coeffs(frac_bits, b20, b10, b00, a20, a10, b21, b11, b01, a21, a11) self.u.set_compensator(c11, c12, c21, c22, cscale) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux( smini.determine_rx_mux_value(self.u, options.rx_subdev_spec)) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) print "format =", hex(format) r = self.u.set_format(format) print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = smini.selected_subdev(self.u, options.rx_subdev_spec) #input_rate = self.u.adc_freq() / self.u.decim_rate() input_rate = self.u.adc_freq() / options.decim # fft_rate = 15 fft_rate = 5 self.deint = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, self.deint) if options.waterfall: self.scope1 = waterfallsink.waterfall_sink_c( self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) self.scope2 = waterfallsink.waterfall_sink_c( self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) elif options.oscilloscope: self.scope1 = scopesink.scope_sink_c( self, panel, sample_rate=input_rate, frame_decim=options.frame_decim) # added option JPJ 4/21/2006 self.scope2 = scopesink.scope_sink_c( self, panel, sample_rate=input_rate, frame_decim=options.frame_decim) else: self.scope1 = fftsink.fft_sink_c(self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) self.scope2 = fftsink.fft_sink_c(self, panel, fft_size=1024, sample_rate=input_rate, fft_rate=fft_rate) # Show I, I' on top scope panel, Q, Q' on bottom #self.fin = gr.complex_to_float() #self.fout = gr.complex_to_float() #self.connect((self.deint,0), self.fin) #self.connect((self.deint,1), self.fout) #self.ii = gr.float_to_complex() #self.qq = gr.float_to_complex() #self.connect((self.fin,0), (self.ii,0)) #self.connect((self.fout,0), (self.ii,1)) #self.connect((self.fin,1), (self.qq,0)) #self.connect((self.fout,1), (self.qq,1)) #self.connect(self.ii, self.scope1) #self.connect(self.qq, self.scope2) self.connect((self.deint, 0), self.scope1) self.connect((self.deint, 1), self.scope2) self._build_gui(vbox) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name())
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(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=first one with a daughterboard)") parser.add_option("-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option( "--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option("-C", "--basic-complex", action="store_true", default=False, help="Use both inputs of a basicRX or LFRX as a single Complex input channel") parser.add_option("-D", "--basic-dualchan", action="store_true", default=False, help="Use both inputs of a basicRX or LFRX as seperate Real input channels") parser.add_option("-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option("-v", "--v-scale", type="eng_float", default=1000, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6, help="set oscope initial s/div to SCALE [default=50us]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True # build the graph if options.basic_dualchan: self.num_inputs=2 else: self.num_inputs=1 if options.no_hb or (options.decim<8): #Min decimation of this firmware is 4. #contains 4 Rx paths without halfbands and 0 tx paths. self.fpga_filename="std_4rx_0tx.rbf" self.u = usrp.source_c(nchan=self.num_inputs,decim_rate=options.decim, fpga_filename=self.fpga_filename) else: #Min decimation of standard firmware is 8. #standard fpga firmware "std_2rxhb_2tx.rbf" #contains 2 Rx paths with halfband filters and 2 tx paths (the default) self.u = usrp.source_c(nchan=self.num_inputs,decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) #print "format =", hex(format) r = self.u.set_format(format) #print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) if (options.basic_complex or options.basic_dualchan ): if ((self.subdev.dbid()==usrp_dbid.BASIC_RX) or (self.subdev.dbid()==usrp_dbid.LF_RX)): side = options.rx_subdev_spec[0] # side A = 0, side B = 1 if options.basic_complex: #force Basic_RX and LF_RX in complex mode (use both I and Q channel) print "Receiver daughterboard forced in complex mode. Both inputs will combined to form a single complex channel." self.dualchan=False if side==0: self.u.set_mux(0x00000010) #enable adc 0 and 1 to form a single complex input on side A else: #side ==1 self.u.set_mux(0x00000032) #enable adc 3 and 2 to form a single complex input on side B elif options.basic_dualchan: #force Basic_RX and LF_RX in dualchan mode (use input A for channel 0 and input B for channel 1) print "Receiver daughterboard forced in dualchannel mode. Each input will be used to form a seperate channel." self.dualchan=True if side==0: self.u.set_mux(gru.hexint(0xf0f0f1f0)) #enable adc 0, side A to form a real input on channel 0 and adc1,side A to form a real input on channel 1 else: #side ==1 self.u.set_mux(0xf0f0f3f2) #enable adc 2, side B to form a real input on channel 0 and adc3,side B to form a real input on channel 1 else: sys.stderr.write('options basic_dualchan or basic_complex is only supported for Basic Rx or LFRX at the moment\n') sys.exit(1) else: self.dualchan=False self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) input_rate = self.u.adc_freq() / self.u.decim_rate() self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale, num_inputs=self.num_inputs) if self.dualchan: # deinterleave two channels from FPGA self.di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u,self.di) self.connect((self.di,0),(self.scope,0)) self.connect((self.di,1),(self.scope,1)) else: self.connect(self.u, self.scope) self._build_gui(vbox) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 if options.freq is None: if ((self.subdev.dbid()==usrp_dbid.BASIC_RX) or (self.subdev.dbid()==usrp_dbid.LF_RX)): #for Basic RX and LFRX if no freq is specified you probably want 0.0 Hz and not 45 GHz options.freq=0.0 else: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0]+r[1])/2 self.set_gain(options.gain) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if self.num_inputs==2: self.myform['baseband2'].set_value(0) self.myform['ddc2'].set_value(0) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") if self.num_inputs==2: if not(self.set_freq2(options.freq)): self._set_status_msg("Failed to set initial frequency for channel 2")
def __init__(self): gr.flow_graph.__init__(self) parser = OptionParser (option_class=eng_option) #parser.add_option("-S", "--subdev", type="subdev", default=(0, None), # help="select USRP Rx side A or B (default=A)") parser.add_option("-d", "--decim", type="int", default=128, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=146.585e6, help="set frequency to FREQ [default=%default])", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=20, help="set gain in dB [default=%default]") parser.add_option("-F", "--filter", action="store_true", default=True, help="Enable channel filter") parser.add_option("-o", "--output", type="string", default=None, help="set output basename") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit if options.output is None: parser.print_help() sys.stderr.write("You must provide an output filename base with -o OUTPUT\n") raise SystemExit else: basename = options.output nchan = 4 nsecs = 4.0 if options.filter: sw_decim = 4 else: sw_decim = 1 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf") if self.u.nddc() < nchan: sys.stderr.write('This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % ( nchan, self.u.nddc())) raise SystemExit if not self.u.set_nchannels(nchan): sys.stderr.write('set_nchannels(%d) failed\n' % (nchan,)) raise SystemExit input_rate = self.u.adc_freq() / self.u.decim_rate() print "USB data rate = %s" % (eng_notation.num_to_str(input_rate),) sink_data_rate = input_rate/sw_decim print "Scope data rate = %s" % (eng_notation.num_to_str(sink_data_rate),) self.subdev = self.u.db[0] + self.u.db[1] if (len(self.subdev) != 4 or self.u.db[0][0].dbid() != usrp_dbid.BASIC_RX or self.u.db[1][0].dbid() != usrp_dbid.BASIC_RX): sys.stderr.write('This code requires a Basic Rx board on Sides A & B\n') sys.exit(1) self.u.set_mux(gru.hexint(0xf3f2f1f0)) # collect 1 second worth of data limit = int(nsecs * input_rate * nchan) print "limit = ", limit head = gr.head(gr.sizeof_gr_complex, limit) # deinterleave four channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, head, di) # taps for channel filter chan_filt_coeffs = optfir.low_pass (1, # gain input_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) for i in range(nchan): sink = gr.file_sink(gr.sizeof_gr_complex, basename + ("-%s-%d.dat" % (eng_notation.num_to_str(sink_data_rate), i))) if options.filter: chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs) self.connect((di, i), chan_filt, sink) else: self.connect((di, i), sink) self.set_gain(options.gain) self.set_freq(options.freq)
def setup_dual(self, setimode): self.setup_radiometer_common(2) self.di = gr.deinterleave(gr.sizeof_gr_complex) self.addchans = gr.add_cc () self.detector = gr.add_ff () self.h_power = gr.complex_to_mag_squared() self.v_power = gr.complex_to_mag_squared() self.connect (self.u, self.di) if (self.use_notches == True): self.connect((self.di, 0), self.notch_filt1, (self.addchans, 0)) self.connect((self.di, 1), self.notch_filt2, (self.addchans, 1)) else: # # For spectral, adding the two channels works, assuming no gross # phase or amplitude error self.connect ((self.di, 0), (self.addchans, 0)) self.connect ((self.di, 1), (self.addchans, 1)) # # Connect heads of spectral and total-power chains # if (self.use_notches == False): self.head = self.di else: self.head = (self.notch_filt1, self.notch_filt2) self.shead = self.addchans if (setimode == False): # # For dual-polarization mode, we compute the sum of the # powers on each channel, after they've been detected # self.detector = gr.add_ff() # # In dual-polarization mode, we compute things a little differently # In effect, we have two radiometer chains, terminating in an adder # if self.use_notches == True: self.connect(self.notch_filt1, self.h_power) self.connect(self.notch_filt2, self.v_power) else: self.connect((self.head, 0), self.h_power) self.connect((self.head, 1), self.v_power) self.connect(self.h_power, (self.detector, 0)) self.connect(self.v_power, (self.detector, 1)) self.connect(self.detector, self.mute, self.reference_level, self.integrator, self.keepn, self.cal_mult, self.cal_offs, self.chart) self.connect(self.cal_offs, self.probe) self.connect(self.shead, self.scope) # # Add a side-chain detector chain, with a different integrator, for sampling # The reference channel data # This is used to derive the offset value for self.reference_level, used above # if (self.switch_mode == True): self.connect(self.detector, self.cmute, self.cintegrator, self.swkeep, self.cprobe) return
def __init__(self, decim=16, fft_size=2048/16, N_re=62, avg_frames=8, dump=None, N_id_1s = range(0,168), slot_0_10s = range(0,2)): self.logger = logging.getLogger('sss_corr') # store parameters self.decim = decim self.fft_size = fft_size self.N_re = N_re self.avg_frames = avg_frames self.dump = dump self.N_id_1s = N_id_1s self.slot_0_10s = slot_0_10s # calculate statics self.symbol_mask = numpy.zeros(20*7) self.symbol_mask[5:7] = 1 self.symbol_mask[75:77] = 1 # generate PSS sequences self.pss_fd_vec = [] for N_id_2 in range(0,3): self.pss_fd_vec.append(gen_pss_fd(N_id_2, self.N_re, False).get_data()) # generate SSS sequences self.sss_fd_vec = [] for N_id_2 in range(0,3): self.sss_fd_vec.append([]) for N_id_1 in range(0,168): self.sss_fd_vec[N_id_2].append([]) for slot_0_10 in range(0,2): self.sss_fd_vec[N_id_2][N_id_1].append(gen_sss_fd(N_id_1,N_id_2, N_re).get_sss_conj(slot_0_10!=0)) # SSS equalization flow graph self.equ_source = symbol_source(decim=self.decim, vlen=self.fft_size) fft = gr.fft_vcc(self.fft_size, True, (window.blackmanharris(1024)), True, 1) vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, self.fft_size) keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, self.N_re, self.fft_size, (self.fft_size-self.N_re)/2) stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, self.N_re) deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex*self.N_re) self.equ = sss_equ(N_id_2=0) self.equ_sink = gr.vector_sink_c(self.N_re) self.equ_top = gr.top_block("sss equ graph") self.equ_top.connect(self.equ_source, fft, vector_to_stream_0, keep_m_in_n_0, stream_to_vector_0_0, deinterleave_0) self.equ_top.connect((deinterleave_0,0), (self.equ,1)) self.equ_top.connect((deinterleave_0,1), (self.equ,0)) self.equ_top.connect(self.equ, self.equ_sink) if self.dump != None: self.equ_top.connect(self.equ_source, gr.file_sink(gr.sizeof_gr_complex*self.fft_size, self.dump + "_sss_td_in.cfile")) self.equ_top.connect((deinterleave_0,0), gr.file_sink(gr.sizeof_gr_complex*self.N_re, self.dump + "_sss_fd_in.cfile")) self.equ_top.connect((deinterleave_0,1), gr.file_sink(gr.sizeof_gr_complex*self.N_re, self.dump + "_pss_fd_in.cfile")) self.equ_top.connect(self.equ, gr.file_sink(gr.sizeof_gr_complex*self.N_re, self.dump + "_sss_fd_equ.cfile")) # SSS maximum likelihood estimation self.ml_src = gr.vector_source_c(zeros(0), False, self.N_re) self.ml_sss = sss_ml_fd(decim=self.decim,N_id_1=0,N_id_2=0,avg_frames=self.avg_frames,slot_0_10=0) self.ml_sink = gr.vector_sink_f() self.ml_top = gr.top_block("sss ml graph") self.ml_top.connect(self.ml_src, self.ml_sss, self.ml_sink) if self.dump != None: self.ml_top.connect(self.ml_sss, gr.file_sink(gr.sizeof_float, self.dump + "_sss_corr.cfile"))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) #parser.add_option("-S", "--subdev", type="subdev", default=(0, None), # help="select USRP Rx side A or B (default=A)") parser.add_option( "-d", "--decim", type="int", default=128, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=146.585e6, help="set frequency to FREQ [default=%default])", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=20, help="set gain in dB [default=%default]") parser.add_option("-F", "--filter", action="store_true", default=True, help="Enable channel filter") parser.add_option("-o", "--output", type="string", default=None, help="set output basename") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit if options.output is None: parser.print_help() sys.stderr.write( "You must provide an output filename base with -o OUTPUT\n") raise SystemExit else: basename = options.output nchan = 4 nsecs = 4.0 if options.filter: sw_decim = 4 else: sw_decim = 1 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf") if self.u.nddcs() < nchan: sys.stderr.write( 'This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % (nchan, self.u.nddcs())) raise SystemExit if not self.u.set_nchannels(nchan): sys.stderr.write('set_nchannels(%d) failed\n' % (nchan, )) raise SystemExit input_rate = self.u.adc_freq() / self.u.decim_rate() print "USB data rate = %s" % (eng_notation.num_to_str(input_rate), ) sink_data_rate = input_rate / sw_decim print "Scope data rate = %s" % ( eng_notation.num_to_str(sink_data_rate), ) self.subdev = self.u.db(0) + self.u.db(1) if (len(self.subdev) < 4 or self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX or self.u.db(1, 0).dbid() != usrp_dbid.BASIC_RX): sys.stderr.write( 'This code requires a Basic Rx board on Sides A & B\n') sys.exit(1) self.u.set_mux(gru.hexint(0xf3f2f1f0)) # collect 1 second worth of data limit = int(nsecs * input_rate * nchan) print "limit = ", limit head = gr.head(gr.sizeof_gr_complex, limit) # deinterleave four channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) self.connect(self.u, head, di) # taps for channel filter chan_filt_coeffs = optfir.low_pass( 1, # gain input_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) for i in range(nchan): sink = gr.file_sink( gr.sizeof_gr_complex, basename + ("-%s-%d.dat" % (eng_notation.num_to_str(sink_data_rate), i))) if options.filter: chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs) self.connect((di, i), chan_filt, sink) else: self.connect((di, i), sink) self.set_gain(options.gain) self.set_freq(options.freq)
def __init__(self, fg, master_serialno,decim,nchan=2,pga_gain=0.0,cordic_freq=0.0,mux=None,align_interval=-1): """ Align multiple sources (usrps) using samplenumbers in the first channel. Takes two ore more sources producing interleaved shorts. produces nchan * nsources gr_complex output streams. @param nchan: number of interleaved channels in source @param align_interval: number of samples to minimally skip between alignments default = -1 which means align only once per work call. @param master_serial_no: serial number of the source which must be the master. Exported sub-blocks (attributes): master_source slave_source usrp_master usrp_slave """ mode=usrp.FPGA_MODE_NORMAL mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT align=gr.align_on_samplenumbers_ss (nchan,align_interval) self.usrp_master = None self.usrp_slave = None # um is master usrp # us is slave usrp if mux is None: mux=self.get_default_mux() #Note that all channels have shifted left because of the added 32 bit counter channel u1 = usrp.source_s (1, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" ) u0 = usrp.source_s (0, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" ) print 'usrp[0] serial',u0.serial_number() print 'usrp[1] serial',u1.serial_number() #default, choose the second found usrp as master (which is usually the usrp which was first plugged in) um_index=1 um=u1 us_index=0 us=u0 if (not (master_serialno is None)): #((master_serialno>0) | (master_serialno <-2)): if (u0.serial_number() == master_serialno): um_index=0 um=u0 us_index=1 us=u1 elif (u1.serial_number() != master_serialno): errorstring = 'Error. requested master_serialno ' + master_serialno +' not found\n' errorstring = errorstring + 'Available are:\n' errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number() +'\n' errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number() +'\n' print errorstring raise ValueError, errorstring else: #default, just choose the first found usrp as master um_index=0 um=u0 us_index=1 us=u1 self.usrp_master=um self.usrp_slave=us print 'usrp_master=usrp[%i] serial_no = %s' % (um_index,self.usrp_master.serial_number() ,) print 'usrp_slave=usrp[%i] serial_no = %s' % (us_index,self.usrp_slave.serial_number() ,) self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0,0)) self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1,0)) self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0,0)) self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1,0)) #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate) if not (pga_gain is None): um.set_pga (0, pga_gain) um.set_pga (1, pga_gain) us.set_pga (0, pga_gain) us.set_pga (1, pga_gain) self.input_rate = um.adc_freq () / um.decim_rate () deintm=gr.deinterleave(gr.sizeof_gr_complex) deints=gr.deinterleave(gr.sizeof_gr_complex) nullsinkm=gr.null_sink(gr.sizeof_gr_complex) nullsinks=gr.null_sink(gr.sizeof_gr_complex) tocomplexm=gr.interleaved_short_to_complex() tocomplexs=gr.interleaved_short_to_complex() fg.connect(um,(align,0)) fg.connect(us,(align,1)) fg.connect((align,0),tocomplexm) fg.connect((align,1),tocomplexs) fg.connect(tocomplexm,deintm) fg.connect(tocomplexs,deints) fg.connect((deintm,0),nullsinkm) #The counters are not usefull for the user but must be connected to something fg.connect((deints,0),nullsinks) #The counters are not usefull for the user but must be connected to something if 4==nchan: nullsinkm3=gr.null_sink(gr.sizeof_gr_complex) nullsinks3=gr.null_sink(gr.sizeof_gr_complex) fg.connect((deintm,3), nullsinkm3) #channel 4 is not used but must be connected fg.connect((deints,3), nullsinks3) #channel 4 is not used but must be connected self.fg=fg self.master_source=deintm self.slave_source=deints if not (cordic_freq is None): um.set_rx_freq (1, cordic_freq) um.set_rx_freq (0, cordic_freq) us.set_rx_freq (1, cordic_freq) us.set_rx_freq (0, cordic_freq) self.enable_master_and_slave() # add an idle handler self.unsynced=True
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1) < 1e6: options.f1 *= 1e6 if abs(options.f2) < 1e6: options.f2 *= 1e6 if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" # build graph self.u = usrp.source_c(0, nchan=2) # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) mv = usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec) mv |= (mv << 8) & 0xff00 # both DDC inputs setup same way self.u.set_mux(mv) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) mid_freq = (f[0] + f[1]) / 2 # set front end PLL to middle frequency tune_result = self.subdev.set_freq(mid_freq) for n in range(2): chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) guts = blks2.wfm_rcv(demod_rate, audio_decimation) volume_control = gr.multiply_const_ff(self.vol) self.connect((di, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (audio_sink, n)) dxc_freq, inverted = calc_dxc_freq(f[n], tune_result.baseband_freq, self.u.converter_rate()) self.u.set_rx_freq(n, dxc_freq) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 # set initial values self.set_gain(options.gain)