diff options
Diffstat (limited to 'gr-uhd/examples/multi-antenna/multi_fft.py')
-rwxr-xr-x | gr-uhd/examples/multi-antenna/multi_fft.py | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/gr-uhd/examples/multi-antenna/multi_fft.py b/gr-uhd/examples/multi-antenna/multi_fft.py new file mode 100755 index 000000000..d4c878c84 --- /dev/null +++ b/gr-uhd/examples/multi-antenna/multi_fft.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, eng_notation +from gnuradio import uhd +from gnuradio.eng_option import eng_option +from gnuradio import eng_notation +from gnuradio import optfir +from optparse import OptionParser +from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2 +from gnuradio.wxgui import scopesink2, form, slider +import wx +import time +import os.path +import sys + +# required FPGA that can do 4 rx channels. + +class my_graph(stdgui2.std_top_block): + + 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("-a", "--address", type="string", + default="addr=192.168.10.2", + help="Address of UHD device, [default=%default]") + parser.add_option("-A", "--antenna", type="string", default=None, + help="select Rx Antenna where appropriate") + parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, + help="set sample rate (bandwidth) [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("-F", "--filter", action="store_true", default=True, + help="Enable channel filter") + parser.add_option("-N", "--nchans", type="int", default=1, + help="set number of channels (default=%default)") + (options, args) = parser.parse_args() + + if len(args) != 0: + parser.print_help() + raise SystemExit + + self.nchans = options.nchans + + if options.filter: + sw_decim = 4 + else: + sw_decim = 1 + + self.u = uhd.usrp_source(device_addr=options.address, + io_type=uhd.io_type.COMPLEX_FLOAT32, + num_channels=self.nchans) + self.u.set_samp_rate(options.samp_rate) + input_rate = self.u.get_samp_rate() + + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = self.u.get_gain_range() + options.gain = float(g.start()+g.stop())/2 + + if options.freq is None: + # if no freq was specified, use the mid-point + r = self.u.get_freq_range() + options.freq = float(r.start()+r.stop())/2 + + self.set_gain(options.gain) + self.set_freq(options.freq) + + #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 (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) + + # 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(self.nchans): + scope = fftsink2.fft_sink_c(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) + + def set_gain(self, gain): + for i in range(self.nchans): + self.u.set_gain(gain, i) + + + def set_freq(self, target_freq): + for i in range(self.nchans): + r = self.u.set_center_freq(target_freq, 0) + + if r: + return True + else: + print "set_freq: failed to set subdev[%d] freq to %f" % \ + (i, target_freq) + return False + +def main (): + app = stdgui2.stdapp(my_graph, "Multi Scope", nstatus=1) + app.MainLoop() + +if __name__ == '__main__': + main () |