diff options
Diffstat (limited to 'gnuradio-examples/python/usrp')
-rw-r--r-- | gnuradio-examples/python/usrp/Makefile.am | 2 | ||||
-rwxr-xr-x | gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py | 154 | ||||
-rwxr-xr-x | gnuradio-examples/python/usrp/limbo/usrp_fft_old.py | 110 | ||||
-rwxr-xr-x | gnuradio-examples/python/usrp/usrp_benchmark_usb.py | 106 | ||||
-rwxr-xr-x | gnuradio-examples/python/usrp/usrp_test_loop_lfsr.py | 62 | ||||
-rwxr-xr-x[-rw-r--r--] | gnuradio-examples/python/usrp/usrp_wfm_rcv_sca.py | 0 | ||||
-rwxr-xr-x | gnuradio-examples/python/usrp/wfm_rcv_file.py | 99 |
7 files changed, 170 insertions, 363 deletions
diff --git a/gnuradio-examples/python/usrp/Makefile.am b/gnuradio-examples/python/usrp/Makefile.am index 71f460721..712aec16b 100644 --- a/gnuradio-examples/python/usrp/Makefile.am +++ b/gnuradio-examples/python/usrp/Makefile.am @@ -25,9 +25,11 @@ EXTRA_DIST = \ fm_tx_2_daughterboards.py \ fm_tx4.py \ max_power.py \ + usrp_benchmark_usb.py \ usrp_nbfm_ptt.py \ usrp_nbfm_rcv.py \ usrp_spectrum_sense.py \ + usrp_test_loop_lfsr.py \ usrp_tv_rcv_nogui.py \ usrp_tv_rcv.py \ usrp_wfm_rcv.py \ diff --git a/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py b/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py deleted file mode 100755 index 403cf3fa4..000000000 --- a/gnuradio-examples/python/usrp/limbo/tvrx_am_rcv_gui.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 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. -# -# -# Demodulate an AM signal from the TVRX or a recorded file. -# The file format must be 256 ksps, complex data. -# - -from gnuradio import gr, gru, eng_notation -from gnuradio import audio_oss as audio -from gnuradio import usrp -from gnuradio import tv_rx -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import sys -import math -from gnuradio.wxgui import stdgui, fftsink, scopesink -import wx - -# -# return a gr.flow_graph -# -class wfm_rx_graph (stdgui.gui_flow_graph): - def __init__(self,frame,panel,vbox,argv): - stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv) - - #set rf freq - rf_freq = 120.e6 - - # Decimation rate from USRP ADC to IF. - usrp_decim = 100 - - # Calculate the sampling rate of the USRP and capture file. - # Decimate the IF sampling rate down by 4 to 64 ksps - # This is a flow graph that has an input (capture file) and output (audio channel). - #self = gr.flow_graph () - - # Signal source is assumed to be 256 kspb / complex data stream. - which_side = 0 - # usrp is data source - if which_side == 0: - src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f0), 0) - else: - src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f2), 0) - - if_rate = 640e3 # src.adc_freq() / usrp_decim - if_decim = 5 - demod_rate = if_rate / if_decim - - audio_decimation = 4 - audio_rate = demod_rate / audio_decimation - - # set up frontend - dboard = tv_rx.tv_rx (src, which_side) - self.dboard = dboard - (success, actual_freq) = dboard.set_freq(rf_freq) - assert success - - if_freq = rf_freq - actual_freq - src.set_rx_freq (0, -if_freq) - - print "actual freq ", actual_freq - print "IF freq ", if_freq - - dboard.set_gain(50) - - #src = gr.file_source (gr.sizeof_gr_complex, "samples/atis_ffz_am_baseband_256k_complex.dat") - #src = gr.file_source (gr.sizeof_gr_complex, "samples/garagedoor1.dat", True) - - #channel_coeffs = gr.firdes.band_pass ( - # 1.0, # gain - # if_rate, - # 10, # center of low transition band - # 10000, # center of hi transition band - # 200, # width of transition band - # gr.firdes.WIN_HAMMING) - - channel_coeffs = gr.firdes.low_pass (1.0, if_rate, 10e3, 4e3, gr.firdes.WIN_HANN) - print "len(channel_coeffs) = ", len(channel_coeffs) - - # Tune to the desired frequency. - ddc = gr.freq_xlating_fir_filter_ccf (if_decim, channel_coeffs, -20e3, if_rate) - - # Demodule with classic sqrt (I*I + Q*Q) - magblock = gr.complex_to_mag() - - # Scale the audio - volumecontrol = gr.multiply_const_ff(.1) - - #band-pass - audio_coeffs = gr.firdes.band_pass ( - 1.0, # gain - demod_rate, - 10, # center of low transition band - 6000, # center of hi transition band - 200, # width of transition band - gr.firdes.WIN_HAMMING) - - - # Low pass filter the demodulator output - #audio_coeffs = gr.firdes.low_pass (1.0, demod_rate, 500, 200, gr.firdes.WIN_HANN) - print "len(audio_coeffs) = ", len(audio_coeffs) - - # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - - # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) - - # now wire it all together - self.connect (src, ddc) - self.connect (ddc, magblock) - self.connect (magblock, volumecontrol) - self.connect (volumecontrol, audio_filter) - self.connect (audio_filter, (audio_sink, 0)) - - d_win = fftsink.fft_sink_c (self, panel, title="RF", fft_size=512, sample_rate=if_rate) - self.connect (src,d_win) - vbox.Add (d_win.win, 4, wx.EXPAND) - - p_win = fftsink.fft_sink_c (self, panel, title="IF", fft_size=512, sample_rate=demod_rate) - self.connect (ddc,p_win) - vbox.Add (p_win.win, 4, wx.EXPAND) - - r_win = fftsink.fft_sink_f (self, panel, title="Audio", fft_size=512, sample_rate=audio_rate) - self.connect (audio_filter,r_win) - vbox.Add (r_win.win, 4, wx.EXPAND) - - #audio_oscope = scopesink.scope_sink_f (self, panel, "Oscope Data", audio_rate) - #self.connect (audio_filter, audio_oscope) - #vbox.Add (audio_oscope.win, 4, wx.EXPAND) - -if __name__ == '__main__': - - app = stdgui.stdapp (wfm_rx_graph, "TVRX AM RX") - app.MainLoop () diff --git a/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py b/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py deleted file mode 100755 index 5edb372b9..000000000 --- a/gnuradio-examples/python/usrp/limbo/usrp_fft_old.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004 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, gru -from gnuradio import usrp -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, fftsink, scopesink -from optparse import OptionParser -import wx - -class app_flow_graph (stdgui.gui_flow_graph): - def __init__(self, frame, panel, vbox, argv): - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) - - self.frame = frame - self.panel = panel - - parser = OptionParser (option_class=eng_option) - parser.add_option ("-d", "--decim", type="int", default=16, - help="set fgpa decimation rate to DECIM") - parser.add_option ("-c", "--ddc-freq", type="eng_float", default=0, - help="set Rx DDC frequency to FREQ", metavar="FREQ") - parser.add_option ("-m", "--mux", type="intx", default=0x32103210, - help="set fpga FR_RX_MUX register to MUX") - parser.add_option ("-g", "--gain", type="eng_float", default=0, - help="set Rx PGA gain in dB (default 0 dB)") - (options, args) = parser.parse_args () - - self.u = usrp.source_c (0, options.decim, 1, gru.hexint(options.mux), 0) - self.u.set_rx_freq (0, options.ddc_freq) - - self.u.set_pga (0, options.gain) - self.u.set_pga (1, options.gain) - - self.u.set_verbose (0) - - input_rate = self.u.adc_freq () / self.u.decim_rate () - - fft = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) - #fft = fftsink.fft_sink_c (self, panel, fft_size=1024, fft_rate=50, sample_rate=input_rate) - self.connect (self.u, fft) - vbox.Add (fft.win, 10, wx.EXPAND) - - if 0: - c2f_1 = gr.complex_to_float () - scope = scopesink.scope_sink_f (self, panel, "Rx Data", input_rate) - vbox.Add (scope.win, 4, wx.EXPAND) - - self.connect (self.u,c2f_1) - self.connect ((c2f_1, 0), (scope, 0)) - self.connect ((c2f_1, 1), (scope, 1)) - - # build small control area at bottom - hbox = wx.BoxSizer (wx.HORIZONTAL) - hbox.Add ((1, 1), 1, wx.EXPAND) - hbox.Add (wx.StaticText (panel, -1, "Set ddc freq: "), 0, wx.ALIGN_CENTER) - self.tc_freq = wx.TextCtrl (panel, -1, "", style=wx.TE_PROCESS_ENTER) - hbox.Add (self.tc_freq, 0, wx.ALIGN_CENTER) - wx.EVT_TEXT_ENTER (self.tc_freq, self.tc_freq.GetId(), self.handle_text_enter) - hbox.Add ((1, 1), 1, wx.EXPAND) - # add it to the main vbox - vbox.Add (hbox, 0, wx.EXPAND) - - self.update_status_bar () - - def handle_text_enter (self, event): - str = event.GetString () - self.tc_freq.Clear () - self.u.set_rx_freq (0, eng_notation.str_to_num (str)) - self.update_status_bar () - - def update_status_bar (self): - ddc_freq = self.u.rx_freq (0) - decim_rate = self.u.decim_rate () - sample_rate = self.u.adc_freq () / decim_rate - msg = "decim: %d %sS/s DDC: %s" % ( - decim_rate, - eng_notation.num_to_str (sample_rate), - eng_notation.num_to_str (ddc_freq)) - - self.frame.GetStatusBar().SetStatusText (msg, 1) - - - -def main (): - app = stdgui.stdapp (app_flow_graph, "USRP FFT") - app.MainLoop () - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/usrp/usrp_benchmark_usb.py b/gnuradio-examples/python/usrp/usrp_benchmark_usb.py new file mode 100755 index 000000000..fc01514a1 --- /dev/null +++ b/gnuradio-examples/python/usrp/usrp_benchmark_usb.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005 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. +# + +""" +Benchmark the USB/USRP throughput. Finds the maximum full-duplex speed +the USRP/USB combination can sustain without errors. + +This program does not currently give reliable results. Sorry about that... +""" + +from gnuradio import gr +from gnuradio import usrp +from gnuradio import eng_notation + +import sys + +def run_test (usb_throughput, verbose): + # usb_throughput is in bytes/sec. + # + # Returns True or False + + nsec = 1 + stream_length = int (usb_throughput/2 * nsec) # length of stream to examine + + adc_freq = 64e6 + dac_freq = 128e6 + sizeof_sample = 2 * gr.sizeof_short + + usb_throughput_in_samples = usb_throughput / sizeof_sample + + # allocate usb throughput 50/50 between Tx and Rx + + tx_interp = int (dac_freq) / int (usb_throughput_in_samples / 2) + rx_decim = int (adc_freq) / int (usb_throughput_in_samples / 2) + + # print "tx_interp =", tx_interp, "rx_decim =", rx_decim + assert (tx_interp == 2 * rx_decim) + + fg = gr.flow_graph () + + # Build the Tx pipeline + data_src = gr.lfsr_32k_source_s () + src_head = gr.head (gr.sizeof_short, int (stream_length * 2)) + usrp_tx = usrp.sink_s (0, tx_interp) + fg.connect (data_src, src_head, usrp_tx) + + # and the Rx pipeline + usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) + head = gr.head (gr.sizeof_short, stream_length) + check = gr.check_lfsr_32k_s () + fg.connect (usrp_rx, head, check) + + fg.run () + + ntotal = check.ntotal () + nright = check.nright () + runlength = check.runlength () + + if verbose: + print "usb_throughput =", eng_notation.num_to_str (usb_throughput) + print "ntotal =", ntotal + print "nright =", nright + print "runlength =", runlength + print "delta =", ntotal - runlength + + return runlength >= stream_length - 80000 + +def main (): + verbose = True + best_rate = 0 + usb_rate = [ 2e6, 4e6, 8e6, 16e6, 32e6 ] + #usb_rate = [ 32e6, 32e6, 32e6, 32e6, 32e6 ] + # usb_rate.reverse () + for rate in usb_rate: + sys.stdout.write ("Testing %sB/sec... " % (eng_notation.num_to_str (rate))) + sys.stdout.flush () + ok = run_test (rate, verbose) + if ok: + best_rate = max (best_rate, rate) + sys.stdout.write ("OK\n") + else: + sys.stdout.write ("FAILED\n") + + print "Max USB/USRP throughput = %sB/sec" % (eng_notation.num_to_str (best_rate),) + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/usrp_test_loop_lfsr.py b/gnuradio-examples/python/usrp/usrp_test_loop_lfsr.py new file mode 100755 index 000000000..446ca30a1 --- /dev/null +++ b/gnuradio-examples/python/usrp/usrp_test_loop_lfsr.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# +# Copyright 2004 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. +# + +""" +Digital loopback (Tx to Rx) for the USRP Rev1. +""" + +from gnuradio import gr +from gnuradio import usrp + + +def build_graph (): + tx_interp = 32 # tx should be twice rx + rx_decim = 16 + + fg = gr.flow_graph () + + data_src = gr.lfsr_32k_source_s () + + # usrp_tx = usrp.sink_s (0, tx_interp, 1, 0x98) + usrp_tx = usrp.sink_s (0, tx_interp) + + fg.connect (data_src, usrp_tx) + + usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) + + sink = gr.check_lfsr_32k_s () + fg.connect (usrp_rx, sink) + + # file_sink = gr.file_sink (gr.sizeof_short, "loopback.dat") + # fg.connect (usrp_rx, file_sink) + + return fg + +def main (): + fg = build_graph () + try: + fg.run() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main () diff --git a/gnuradio-examples/python/usrp/usrp_wfm_rcv_sca.py b/gnuradio-examples/python/usrp/usrp_wfm_rcv_sca.py index 64d51e223..64d51e223 100644..100755 --- a/gnuradio-examples/python/usrp/usrp_wfm_rcv_sca.py +++ b/gnuradio-examples/python/usrp/usrp_wfm_rcv_sca.py diff --git a/gnuradio-examples/python/usrp/wfm_rcv_file.py b/gnuradio-examples/python/usrp/wfm_rcv_file.py deleted file mode 100755 index 2c8d4f760..000000000 --- a/gnuradio-examples/python/usrp/wfm_rcv_file.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr, eng_notation -from gnuradio import audio -# from gnuradio import usrp -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import sys -import math - - -# -# return a gr.flow_graph -# -def build_graph (input_filename, repeat): - adc_rate = 64e6 # USRP A/D sampling rate - decim = 250 # FPGA decimated by this amount - - quad_rate = adc_rate / decim # 256 kHz (the sample rate of the file) - audio_decimation = 8 - audio_rate = quad_rate / audio_decimation # 32 kHz - - fg = gr.flow_graph () - - # usrp is data source - # src = usrp.source_c (0, decim) - # src.set_rx_freq (0, -IF_freq) - - src = gr.file_source (gr.sizeof_gr_complex, input_filename, repeat) - - (head, tail) = build_pipeline (fg, quad_rate, audio_decimation) - - # sound card as final sink - audio_sink = audio.sink (int (audio_rate)) - - # now wire it all together - fg.connect (src, head) - fg.connect (tail, (audio_sink, 0)) - - return fg - -def build_pipeline (fg, quad_rate, audio_decimation): - '''Given a flow_graph, fg, construct a pipeline - for demodulating a broadcast FM signal. The - input is the downconverteed complex baseband - signal. The output is the demodulated audio. - - build_pipeline returns a two element tuple - containing the input and output endpoints. - ''' - fm_demod_gain = 2200.0/32768.0 - audio_rate = quad_rate / audio_decimation - volume = 1.0 - - # input: complex; output: float - fm_demod = gr.quadrature_demod_cf (volume*fm_demod_gain) - - # compute FIR filter taps for audio filter - width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0, # gain - quad_rate, # sampling rate - audio_rate/2 - width_of_transition_band, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - - TAU = 75e-6 # 75us in US, 50us in EUR - fftaps = [ 1 - math.exp(-1/TAU/quad_rate), 0] - fbtaps= [ 0 , math.exp(-1/TAU/quad_rate) ] - deemph = gr.iir_filter_ffd(fftaps,fbtaps) - - # input: float; output: float - audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - - fg.connect (fm_demod, deemph) - fg.connect (deemph, audio_filter) - return ((fm_demod, 0), (audio_filter, 0)) - - -def main (): - usage = "usage: %prog [options] filename" - parser = OptionParser (option_class=eng_option, usage=usage) - parser.add_option ("-r", "--repeat", action="store_true", default=False) - # parser.add_option (... your stuff here...) - (options, args) = parser.parse_args () - - if len (args) != 1: - parser.print_help () - sys.exit (1) - - fg = build_graph (args[0], options.repeat) - - fg.start () # fork thread(s) and return - raw_input ('Press Enter to quit: ') - fg.stop () - -if __name__ == '__main__': - main () - - |