3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, gru
24 from gnuradio import usrp
25 from gnuradio import eng_notation
26 from gnuradio.eng_option import eng_option
27 from gnuradio.wxgui import stdgui, fftsink, scopesink
28 from optparse import OptionParser
31 class app_flow_graph (stdgui.gui_flow_graph):
32 def __init__(self, frame, panel, vbox, argv):
33 stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)
38 parser = OptionParser (option_class=eng_option)
39 parser.add_option ("-d", "--decim", type="int", default=16,
40 help="set fgpa decimation rate to DECIM")
41 parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0,
42 help="set Rx DDC frequency to FREQ", metavar="FREQ")
43 parser.add_option ("-m", "--mux", type="intx", default=0x32103210,
44 help="set fpga FR_RX_MUX register to MUX")
45 parser.add_option ("-g", "--gain", type="eng_float", default=0,
46 help="set Rx PGA gain in dB (default 0 dB)")
47 (options, args) = parser.parse_args ()
49 self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0)
50 self.u.set_rx_freq (0, options.ddc_freq)
52 self.u.set_pga (0, options.gain)
53 self.u.set_pga (1, options.gain)
55 self.u.set_verbose (0)
57 input_rate = self.u.adc_freq () / self.u.decim_rate ()
59 fft = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate)
60 #fft = fftsink.fft_sink_c (self, panel, fft_size=1024, fft_rate=50, sample_rate=input_rate)
61 self.connect (self.u, fft)
62 vbox.Add (fft.win, 10, wx.EXPAND)
65 c2f_1 = gr.complex_to_float ()
66 scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate)
67 vbox.Add (scope.win, 4, wx.EXPAND)
69 self.connect (self.u,c2f_1)
70 self.connect ((c2f_1, 0), (scope, 0))
71 self.connect ((c2f_1, 1), (scope, 1))
73 # build small control area at bottom
74 hbox = wx.BoxSizer (wx.HORIZONTAL)
75 hbox.Add ((1, 1), 1, wx.EXPAND)
76 hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER)
77 self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER)
78 hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER)
79 wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter)
80 hbox.Add ((1, 1), 1, wx.EXPAND)
81 # add it to the main vbox
82 vbox.Add (hbox, 0, wx.EXPAND)
84 self.update_status_bar ()
86 def handle_text_enter (self, event):
87 str = event.GetString ()
89 self.u.set_rx_freq (0, eng_notation.str_to_num (str))
90 self.update_status_bar ()
92 def update_status_bar (self):
93 ddc_freq = self.u.rx_freq (0)
94 decim_rate = self.u.decim_rate ()
95 sample_rate = self.u.adc_freq () / decim_rate
96 msg = "decim: %d %sS/s DDC: %s" % (
98 eng_notation.num_to_str (sample_rate),
99 eng_notation.num_to_str (ddc_freq))
101 self.frame.GetStatusBar().SetStatusText (msg, 1)
106 app = stdgui.stdapp (app_flow_graph, "USRP FFT")
109 if __name__ == '__main__':