summaryrefslogtreecommitdiff
path: root/gnuradio-examples
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-examples')
-rw-r--r--gnuradio-examples/python/hier/Makefile.am5
-rw-r--r--gnuradio-examples/python/hier/networking/Makefile.am30
-rw-r--r--gnuradio-examples/python/hier/sounder/Makefile.am30
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_rx.py78
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_tx.py70
-rw-r--r--gnuradio-examples/python/hier/sounder/usrp_sink.py120
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_rx.py69
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_tx.py69
-rw-r--r--gnuradio-examples/python/hier/sounder/usrp_source.py126
-rw-r--r--gnuradio-examples/python/hier/usrp/Makefile.am25
-rwxr-xr-xgnuradio-examples/python/hier/usrp/usrp_fft.py253
11 files changed, 874 insertions, 1 deletions
diff --git a/gnuradio-examples/python/hier/Makefile.am b/gnuradio-examples/python/hier/Makefile.am
index f39864324..e58b36122 100644
--- a/gnuradio-examples/python/hier/Makefile.am
+++ b/gnuradio-examples/python/hier/Makefile.am
@@ -21,4 +21,7 @@
SUBDIRS = \
audio \
- ofdm
+ ofdm \
+ networking \
+ sounder \
+ usrp
diff --git a/gnuradio-examples/python/hier/networking/Makefile.am b/gnuradio-examples/python/hier/networking/Makefile.am
new file mode 100644
index 000000000..eaa568008
--- /dev/null
+++ b/gnuradio-examples/python/hier/networking/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Copyright 2007 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 2, 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.
+#
+
+EXTRA_DIST = \
+ audio_sink.py \
+ audio_source.py \
+ dial_tone_sink.py \
+ dial_tone_source.py \
+ vector_sink.py \
+ vector_source.py
+
+MOSTLYCLEANFILES = *.pyc *~
diff --git a/gnuradio-examples/python/hier/sounder/Makefile.am b/gnuradio-examples/python/hier/sounder/Makefile.am
new file mode 100644
index 000000000..ecbbb4718
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Copyright 2007 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 2, 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.
+#
+
+EXTRA_DIST = \
+ usrp_sounder_rx.py \
+ usrp_sounder_tx.py \
+ usrp_source.py \
+ usrp_sink.py \
+ sounder_rx.py \
+ sounder_tx.py
+
+MOSTLYCLEANFILES = *.pyc *~
diff --git a/gnuradio-examples/python/hier/sounder/sounder_rx.py b/gnuradio-examples/python/hier/sounder/sounder_rx.py
new file mode 100644
index 000000000..6c8154baf
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/sounder_rx.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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, usrp, eng_notation
+from usrp_source import usrp_source_c
+import math
+
+n2s = eng_notation.num_to_str
+
+class sounder_rx(gr.hier_block2):
+ """
+ Creates a top-level channel sounder block with the given parameters.
+ """
+
+ def __init__(self, subdev_spec, freq, cal, verbose, max_delay, chip_rate, gain):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.hier_block2.__init__(self,
+ "sounder_rx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(0,0,0)) # Output signature
+ self._freq = freq
+ self._cal = cal
+ self._verbose = verbose
+ self._max_delay = max_delay
+
+ self._u = usrp_source_c(0, subdev_spec, gain, chip_rate, self._freq, self._cal, verbose)
+ self.define_component("usrp", self._u)
+
+ self._chip_rate = self._u._if_rate
+ self._resolution = 1.0/self._chip_rate
+
+ min_chips = int(math.ceil(2.0*self._max_delay * self._chip_rate))
+ degree = int(math.ceil(math.log(min_chips)/math.log(2)))
+ self._length = 2**degree-1
+ self._seq_per_sec = self._chip_rate/self._length
+ self._tap = 0.0001
+
+ if self._verbose:
+ print "Actual chip rate is", n2s(self._chip_rate), "chips/sec"
+ print "Resolution is", n2s(self._resolution), "sec"
+ print "Using specified maximum delay spread of", self._max_delay, "sec"
+ print "Mininum sequence length needed is", n2s(min_chips), "chips"
+ print "Using PN sequence of degree", degree, "length", self._length
+ print "Sequences per second is", self._seq_per_sec
+ print "IIR tap is", self._tap
+
+ self.define_component("s2v", gr.stream_to_vector(gr.sizeof_gr_complex, self._length))
+ self.define_component("fft", gr.fft_vcc(self._length, True, ())) # No window needed
+ self.define_component("avg", gr.single_pole_iir_filter_cc(self._tap, self._length))
+ self.define_component("keep", gr.keep_one_in_n(gr.sizeof_gr_complex*self._length, int(self._seq_per_sec)))
+ self.define_component("sink", gr.file_sink(gr.sizeof_gr_complex*self._length, "FFT.dat"))
+
+ self.connect("usrp", 0, "s2v", 0)
+ self.connect("s2v", 0, "fft", 0)
+ self.connect("fft", 0, "avg", 0)
+ self.connect("avg", 0, "keep", 0)
+ self.connect("keep", 0, "sink", 0)
diff --git a/gnuradio-examples/python/hier/sounder/sounder_tx.py b/gnuradio-examples/python/hier/sounder/sounder_tx.py
new file mode 100644
index 000000000..e6a3e84f8
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/sounder_tx.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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, usrp, eng_notation
+from usrp_sink import usrp_sink_c
+import math
+
+n2s = eng_notation.num_to_str
+
+class sounder_tx(gr.hier_block2):
+ """
+ Creates a top-level channel sounder block with the given parameters.
+ """
+
+ def __init__(self, subdev_spec, freq, cal, verbose, max_delay, chip_rate, amplitude):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.hier_block2.__init__(self,
+ "sounder_tx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(0,0,0)) # Output signature
+ self._freq = freq
+ self._cal = cal
+ self._verbose = verbose
+ self._max_delay = max_delay
+
+ self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, verbose)
+ self._chip_rate = self._u._if_rate
+ self._resolution = 1.0/self._chip_rate
+
+ min_chips = int(math.ceil(2.0*self._max_delay * self._chip_rate))
+ degree = int(math.ceil(math.log(min_chips)/math.log(2)))
+ self._length = 2**degree-1
+
+ self._glfsr = gr.glfsr_source_b(degree)
+ self._mapper = gr.chunks_to_symbols_bc((-amplitude+0j, amplitude+0j), 1)
+
+ if self._verbose:
+ print "Actual chip rate is", n2s(self._chip_rate), "chips/sec"
+ print "Resolution is", n2s(self._resolution), "sec"
+ print "Using specified maximum delay spread of", self._max_delay, "sec"
+ print "Mininum sequence length needed is", n2s(min_chips), "chips"
+ print "Using PN sequence of degree", degree, "length", self._length
+ print "Output amplitude is", amplitude
+
+ self.define_component("glfsr", self._glfsr)
+ self.define_component("mapper", self._mapper)
+ self.define_component("usrp", self._u)
+ self.connect("glfsr", 0, "mapper", 0)
+ self.connect("mapper", 0, "usrp", 0)
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sink.py b/gnuradio-examples/python/hier/sounder/usrp_sink.py
new file mode 100644
index 000000000..000b831f5
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/usrp_sink.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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, usrp, eng_notation
+n2s = eng_notation.num_to_str
+
+# Hierarchical block implementing a USRP sink for complex floats,
+# with convenience functions for tuning, interpolation, etc.
+#
+class usrp_sink_c(gr.hier_block2):
+ """
+ Create a USRP sink object accepting complex floats.
+ """
+ def __init__(self, which=0, subdev_spec=None, if_rate=None,
+ freq=0.0, calibration=0.0, verbose=False):
+ # Call hierarchical block constructor
+ gr.hier_block2.__init__(self,
+ "usrp_sink_c", # Block typename
+ gr.io_signature(1,1,gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(0,0,0)) # Output signature
+
+ self._verbose = verbose
+ self._u = usrp.sink_c(which)
+ if self._verbose:
+ print 'DAC sample rate is', n2s(self._u.dac_rate()), "sps"
+ self.set_subdev(subdev_spec)
+ self.set_if_rate(if_rate)
+ self.set_calibration(calibration)
+ self.tune(freq)
+
+ self.define_component("usrp", self._u)
+ self.connect("self", 0, "usrp", 0)
+
+
+ def set_subdev(self, subdev_spec):
+ if subdev_spec is None:
+ subdev_spec = self.pick_subdevice()
+ self._subdev = usrp.selected_subdev(self._u, subdev_spec)
+ self._u.set_mux(usrp.determine_tx_mux_value(self._u, subdev_spec))
+ if self._verbose:
+ print 'TX using', self._subdev.name(), 'daughterboard'
+
+ def pick_subdevice(self):
+ """
+ The user didn't specify a subdevice.
+ If there's a daughterboard on A, select A.
+ If there's a daughterboard on B, select B.
+ Otherwise, select A.
+ """
+ if self._u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
+ return (0, 0)
+ if self._u.db[1][0].dbid() >= 0:
+ return (1, 0)
+ return (0, 0)
+
+ def set_if_rate(self, if_rate):
+ # If no IF rate specified, set to maximum interpolation
+ if if_rate is None:
+ self._interp = 512
+ else:
+ self._interp = 4*int(self._u.dac_rate()/(4.0*if_rate)+0.5)
+
+
+ self._if_rate = self._u.dac_rate()/self._interp
+ self._u.set_interp_rate(self._interp)
+
+ if self._verbose:
+ print "USRP interpolation rate is", self._interp
+ print "USRP IF rate is", n2s(self._if_rate), "sps"
+
+ def set_calibration(self, calibration):
+ self._cal = calibration
+ if self._verbose:
+ print "Using frequency calibration offset of", n2s(calibration), "Hz"
+
+ def tune(self, freq):
+ """
+ Set the center frequency we're interested in.
+
+ @param target_freq: frequency in Hz
+ @type: bool
+
+ Tuning is a two step process. First we ask the front-end to
+ tune as close to the desired frequency as it can. Then we use
+ the result of that operation and our target_frequency to
+ determine the value for the digital down converter.
+ """
+ self._tune_result = self._u.tune(self._subdev._which, self._subdev, freq+self._cal)
+ if self._tune_result:
+ if self._verbose:
+ print "Baseband frequency is", n2s(self._tune_result.baseband_freq), "Hz"
+ print "DXC frequency is", n2s(self._tune_result.dxc_freq), "Hz"
+ print "Center frequency is", n2s(freq), "Hz"
+ print "Residual frequency is", n2s(self._tune_result.residual_freq), "Hz"
+ return True
+
+ return False
+
+if __name__ == '__main__':
+ sink = usrp_sink_c(verbose=True)
+
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
new file mode 100755
index 000000000..dd8007cbb
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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.eng_option import eng_option
+from optparse import OptionParser
+from sounder_rx import sounder_rx
+
+def main():
+ parser = OptionParser(option_class=eng_option)
+
+ # Receive path options
+ parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B (default=first found)")
+ parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+ help="set center frequency (default=%default)")
+ parser.add_option("-c", "--cal", type="eng_float", default=0.0,
+ help="set frequency calibration offset (default=%default)")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="print extra debugging info")
+ parser.add_option("-d", "--max-delay", type="eng_float", default=10e-6,
+ help="set maximum delay spread (default=%default)")
+ parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
+ help="set sounder chip rate (default=%default)")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set output amplitude (default=%default)")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ # Create an instance of a hierarchical block
+ top_block = sounder_rx(options.rx_subdev_spec, options.freq, options.cal,
+ options.verbose, options.max_delay, options.chip_rate,
+ options.gain)
+
+ # Create an instance of a runtime, passing it the top block
+ # to process
+ runtime = gr.runtime(top_block)
+
+ try:
+ # Run forever
+ runtime.run()
+ except KeyboardInterrupt:
+ # Ctrl-C exits
+ pass
+
+if __name__ == '__main__':
+ main ()
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
new file mode 100755
index 000000000..c96313c67
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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.eng_option import eng_option
+from optparse import OptionParser
+from sounder_tx import sounder_tx
+
+def main():
+ parser = OptionParser(option_class=eng_option)
+
+ # Transmit path options
+ parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B (default=first found)")
+ parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+ help="set center frequency (default=%default)")
+ parser.add_option("-c", "--cal", type="eng_float", default=0.0,
+ help="set frequency calibration offset (default=%default)")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="print extra debugging info")
+ parser.add_option("-d", "--max-delay", type="eng_float", default=10e-6,
+ help="set maximum delay spread (default=%default)")
+ parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
+ help="set sounder chip rate (default=%default)")
+ parser.add_option("-g", "--amplitude", type="eng_float", default=32000.0,
+ help="set output amplitude (default=%default)")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ # Create an instance of a hierarchical block
+ top_block = sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
+ options.verbose, options.max_delay, options.chip_rate,
+ options.amplitude)
+
+ # Create an instance of a runtime, passing it the top block
+ # to process
+ runtime = gr.runtime(top_block)
+
+ try:
+ # Run forever
+ runtime.run()
+ except KeyboardInterrupt:
+ # Ctrl-C exits
+ pass
+
+if __name__ == '__main__':
+ main ()
diff --git a/gnuradio-examples/python/hier/sounder/usrp_source.py b/gnuradio-examples/python/hier/sounder/usrp_source.py
new file mode 100644
index 000000000..16949998b
--- /dev/null
+++ b/gnuradio-examples/python/hier/sounder/usrp_source.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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, usrp, eng_notation
+n2s = eng_notation.num_to_str
+
+# Hierarchical block implementing a USRP source for complex floats,
+# with convenience functions for gain, tune, decimation, etc.
+#
+class usrp_source_c(gr.hier_block2):
+ """
+ Create a USRP source object supplying complex floats.
+ """
+ def __init__(self, which=0, subdev_spec=None, gain=None, if_rate=None,
+ freq=0.0, calibration=0.0, verbose=False):
+ # Call hierarchical block constructor
+ gr.hier_block2.__init__(self,
+ "usrp_source_c", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(1,1,gr.sizeof_gr_complex)) # Output signature
+
+ self._verbose = verbose
+ self._u = usrp.source_c(which)
+ if self._verbose:
+ print 'ADC sample rate is', n2s(self._u.adc_rate()), "sps"
+ self.set_subdev(subdev_spec)
+ self.set_if_rate(if_rate)
+ self.set_gain(gain)
+ self.set_calibration(calibration)
+ self.tune(freq)
+
+ self.define_component("usrp", self._u)
+ self.connect("usrp", 0, "self", 0)
+
+ def set_subdev(self, subdev_spec):
+ if subdev_spec is None:
+ subdev_spec = self.pick_subdevice()
+ self._subdev = usrp.selected_subdev(self._u, subdev_spec)
+ self._u.set_mux(usrp.determine_rx_mux_value(self._u, subdev_spec))
+ if self._verbose:
+ print 'RX using', self._subdev.name(), 'daughterboard'
+
+ def pick_subdevice(self):
+ """
+ The user didn't specify a subdevice.
+ If there's a daughterboard on A, select A.
+ If there's a daughterboard on B, select B.
+ Otherwise, select A.
+ """
+ if self._u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
+ return (0, 0)
+ if self._u.db[1][0].dbid() >= 0:
+ return (1, 0)
+ return (0, 0)
+
+ def set_if_rate(self, if_rate):
+ # If no IF rate specified, set to maximum decimation
+ if if_rate is None:
+ self._decim = 256
+ else:
+ self._decim = int(self._u.adc_rate()/if_rate)
+
+ self._u.set_decim_rate(self._decim)
+ self._if_rate = self._u.adc_rate()/self._decim
+
+ if self._verbose:
+ print "USRP decimation rate is", self._decim
+ print "USRP IF rate is", n2s(self._if_rate), "sps"
+
+ def set_gain(self, gain):
+ # If no gain specified, set to midrange
+ if gain is None:
+ g = self._subdev.gain_range()
+ gain = (g[0]+g[1])/2.0
+ self._gain = gain
+ self._subdev.set_gain(self._gain)
+
+ def set_calibration(self, calibration):
+ self._cal = calibration
+ if self._verbose:
+ print "Using frequency calibration offset of", n2s(calibration), "Hz"
+
+ def tune(self, freq):
+ """
+ Set the center frequency we're interested in.
+
+ @param target_freq: frequency in Hz
+ @type: bool
+
+ Tuning is a two step process. First we ask the front-end to
+ tune as close to the desired frequency as it can. Then we use
+ the result of that operation and our target_frequency to
+ determine the value for the digital down converter.
+ """
+ self._tune_result = usrp.tune(self._u, 0, self._subdev, freq+self._cal)
+ if self._tune_result:
+ if self._verbose:
+ print "Baseband frequency is", n2s(self._tune_result.baseband_freq), "Hz"
+ print "DXC frequency is", n2s(self._tune_result.dxc_freq), "Hz"
+ print "Center frequency is", n2s(freq), "Hz"
+ print "Residual frequency is", n2s(self._tune_result.residual_freq), "Hz"
+ return True
+
+ return False
+
+if __name__ == '__main__':
+ src = usrp_source_c(verbose=True)
diff --git a/gnuradio-examples/python/hier/usrp/Makefile.am b/gnuradio-examples/python/hier/usrp/Makefile.am
new file mode 100644
index 000000000..20a21cf66
--- /dev/null
+++ b/gnuradio-examples/python/hier/usrp/Makefile.am
@@ -0,0 +1,25 @@
+#
+# Copyright 2007 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 2, 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.
+#
+
+EXTRA_DIST = \
+ usrp_fft.py
+
+MOSTLYCLEANFILES = *.pyc *~
diff --git a/gnuradio-examples/python/hier/usrp/usrp_fft.py b/gnuradio-examples/python/hier/usrp/usrp_fft.py
new file mode 100755
index 000000000..5cd5c1482
--- /dev/null
+++ b/gnuradio-examples/python/hier/usrp/usrp_fft.py
@@ -0,0 +1,253 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2005,2007 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 2, 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 stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider
+from optparse import OptionParser
+import wx
+import sys
+
+
+def pick_subdevice(u):
+ """
+ The user didn't specify a subdevice on the command line.
+ If there's a daughterboard on A, select A.
+ If there's a daughterboard on B, select B.
+ Otherwise, select A.
+ """
+ if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
+ return (0, 0)
+ if u.db[1][0].dbid() >= 0:
+ return (1, 0)
+ return (0, 0)
+
+
+class app_top_block(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("-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")
+ (options, args) = parser.parse_args()
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ self.show_debug_info = True
+
+ self.u = usrp.source_c(decim_rate=options.decim)
+ self.define_component("usrp", self.u)
+ 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()
+
+
+ if options.waterfall:
+ self.scope = waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate)
+ elif options.oscilloscope:
+ self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
+ else:
+ self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate)
+ self.define_component("scope", self.scope)
+
+ # Ultimately this will be
+ # self.connect("usrp scope")
+ self.connect("usrp", 0, "scope", 0)
+
+ 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 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 not(self.set_freq(options.freq)):
+ self._set_status_msg("Failed to set initial frequency")
+
+ def _set_status_msg(self, msg):
+ self.frame.GetStatusBar().SetStatusText(msg, 0)
+
+ def _build_gui(self, vbox):
+
+ def _form_set_freq(kv):
+ return self.set_freq(kv['freq'])
+
+ vbox.Add(self.scope.win, 10, wx.EXPAND)
+
+ # add control area at the bottom
+ self.myform = myform = form.form()
+ hbox = wx.BoxSizer(wx.HORIZONTAL)
+ hbox.Add((5,0), 0, 0)
+ myform['freq'] = form.float_field(
+ parent=self.panel, sizer=hbox, label="Center freq", weight=1,
+ callback=myform.check_input_and_call(_form_set_freq, self._set_status_msg))
+
+ hbox.Add((5,0), 0, 0)
+ g = self.subdev.gain_range()
+ myform['gain'] = form.slider_field(parent=self.panel, sizer=hbox, label="Gain",
+ weight=3,
+ min=int(g[0]), max=int(g[1]),
+ callback=self.set_gain)
+
+ hbox.Add((5,0), 0, 0)
+ vbox.Add(hbox, 0, wx.EXPAND)
+
+ self._build_subpanel(vbox)
+
+ def _build_subpanel(self, vbox_arg):
+ # build a secondary information panel (sometimes hidden)
+
+ # FIXME figure out how to have this be a subpanel that is always
+ # created, but has its visibility controlled by foo.Show(True/False)
+
+ def _form_set_decim(kv):
+ return self.set_decim(kv['decim'])
+
+ if not(self.show_debug_info):
+ return
+
+ panel = self.panel
+ vbox = vbox_arg
+ myform = self.myform
+
+ #panel = wx.Panel(self.panel, -1)
+ #vbox = wx.BoxSizer(wx.VERTICAL)
+
+ hbox = wx.BoxSizer(wx.HORIZONTAL)
+ hbox.Add((5,0), 0)
+
+ myform['decim'] = form.int_field(
+ parent=panel, sizer=hbox, label="Decim",
+ callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg))
+
+ hbox.Add((5,0), 1)
+ myform['fs@usb'] = form.static_float_field(
+ parent=panel, sizer=hbox, label="Fs@USB")
+
+ hbox.Add((5,0), 1)
+ myform['dbname'] = form.static_text_field(
+ parent=panel, sizer=hbox)
+
+ hbox.Add((5,0), 1)
+ myform['baseband'] = form.static_float_field(
+ parent=panel, sizer=hbox, label="Analog BB")
+
+ hbox.Add((5,0), 1)
+ myform['ddc'] = form.static_float_field(
+ parent=panel, sizer=hbox, label="DDC")
+
+ hbox.Add((5,0), 0)
+ vbox.Add(hbox, 0, wx.EXPAND)
+
+
+ def set_freq(self, target_freq):
+ """
+ Set the center frequency we're interested in.
+
+ @param target_freq: frequency in Hz
+ @rypte: bool
+
+ Tuning is a two step process. First we ask the front-end to
+ tune as close to the desired frequency as it can. Then we use
+ the result of that operation and our target_frequency to
+ determine the value for the digital down converter.
+ """
+ r = self.u.tune(0, self.subdev, target_freq)
+
+ if r:
+ self.myform['freq'].set_value(target_freq) # update displayed value
+ if self.show_debug_info:
+ self.myform['baseband'].set_value(r.baseband_freq)
+ self.myform['ddc'].set_value(r.dxc_freq)
+ return True
+
+ return False
+
+ def set_gain(self, gain):
+ self.myform['gain'].set_value(gain) # update displayed value
+ self.subdev.set_gain(gain)
+
+ def set_decim(self, decim):
+ ok = self.u.set_decim_rate(decim)
+ if not ok:
+ print "set_decim failed"
+ input_rate = self.u.adc_freq() / self.u.decim_rate()
+ self.scope.set_sample_rate(input_rate)
+ if self.show_debug_info: # update displayed values
+ self.myform['decim'].set_value(self.u.decim_rate())
+ self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
+ return ok
+
+def main ():
+ app = stdgui2.stdapp(app_top_block, "USRP FFT", nstatus=1)
+ app.MainLoop()
+
+if __name__ == '__main__':
+ main ()