3 from gnuradio import gr, gru, eng_notation
4 from gnuradio import usrp
5 from gnuradio.eng_option import eng_option
6 from gnuradio import eng_notation
7 from gnuradio import optfir
8 from optparse import OptionParser
9 from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider
11 from usrpm import usrp_dbid
16 # required FPGA that can do 4 rx channels.
19 class my_graph(stdgui2.std_top_block):
21 def __init__(self, frame, panel, vbox, argv):
22 stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
27 parser = OptionParser (option_class=eng_option)
28 #parser.add_option("-S", "--subdev", type="subdev", default=(0, None),
29 # help="select USRP Rx side A or B (default=A)")
30 parser.add_option("-d", "--decim", type="int", default=128,
31 help="set fgpa decimation rate to DECIM [default=%default]")
32 parser.add_option("-f", "--freq", type="eng_float", default=146.585e6,
33 help="set frequency to FREQ [default=%default])", metavar="FREQ")
34 parser.add_option("-g", "--gain", type="eng_float", default=20,
35 help="set gain in dB [default=%default]")
36 parser.add_option("-F", "--filter", action="store_true", default=True,
37 help="Enable channel filter")
38 (options, args) = parser.parse_args()
51 self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf")
52 if self.u.nddcs() < nchan:
53 sys.stderr.write('This code requires an FPGA build with %d DDCs. This FPGA has only %d.\n' % (
54 nchan, self.u.nddcs()))
57 if not self.u.set_nchannels(nchan):
58 sys.stderr.write('set_nchannels(%d) failed\n' % (nchan,))
61 input_rate = self.u.adc_freq() / self.u.decim_rate()
62 print "USB data rate = %s" % (eng_notation.num_to_str(input_rate),)
63 print "Scope data rate = %s" % (eng_notation.num_to_str(input_rate/sw_decim),)
65 self.subdev = self.u.db(0) + self.u.db(1)
67 if (len (self.subdev) != 4 or
68 self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX or
69 self.u.db(0, 0).dbid() != usrp_dbid.BASIC_RX):
70 sys.stderr.write('This code requires a Basic Rx board on Sides A & B\n')
73 self.u.set_mux(gru.hexint(0xf3f2f1f0))
75 # deinterleave four channels from FPGA
76 di = gr.deinterleave(gr.sizeof_gr_complex)
78 self.connect(self.u, di)
82 # taps for channel filter
83 chan_filt_coeffs = optfir.low_pass (1, # gain
84 input_rate, # sampling rate
85 80e3, # passband cutoff
86 115e3, # stopband cutoff
87 0.1, # passband ripple
88 60) # stopband attenuation
89 #print len(chan_filt_coeffs)
91 for i in range(nchan):
92 scope = fftsink2.fft_sink_c(panel, sample_rate=input_rate/sw_decim,
93 title="Input %d" % (i,),
94 ref_level=80, y_per_div=20)
95 vbox.Add(scope.win, 10, wx.EXPAND)
98 chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs)
99 self.connect((di, i), chan_filt, scope)
101 self.connect((di, i), scope)
104 self.set_gain(options.gain)
105 self.set_freq(options.freq)
107 def set_gain(self, gain):
108 for i in range(len(self.subdev)):
109 self.subdev[i].set_gain(gain)
111 def set_freq(self, target_freq):
113 for i in range(len(self.subdev)):
114 r = usrp.tune(self.u, i, self.subdev[i], target_freq)
117 print "set_freq: failed to set subdev[%d] freq to %f" % (
124 app = stdgui2.stdapp(my_graph, "Multi Scope", nstatus=1)
127 if __name__ == '__main__':