summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-examples/python')
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_rx.py53
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_tx.py46
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_rx.py108
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_tx.py66
-rw-r--r--gnuradio-examples/python/hier/sounder/usrp_source.py4
5 files changed, 162 insertions, 115 deletions
diff --git a/gnuradio-examples/python/hier/sounder/sounder_rx.py b/gnuradio-examples/python/hier/sounder/sounder_rx.py
index 6c8154baf..336e604a3 100644
--- a/gnuradio-examples/python/hier/sounder/sounder_rx.py
+++ b/gnuradio-examples/python/hier/sounder/sounder_rx.py
@@ -28,51 +28,28 @@ n2s = eng_notation.num_to_str
class sounder_rx(gr.hier_block2):
"""
- Creates a top-level channel sounder block with the given parameters.
+ Creates a channel sounder receiver block with the given parameters.
"""
- def __init__(self, subdev_spec, freq, cal, verbose, max_delay, chip_rate, gain):
+ def __init__(self, chip_rate, degree, verbose):
# 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
+ "sounder_rx", # Block typename
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
- 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
+ self._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
+ self._length = 2**self._degree-1
+ self._rep_rate = self._chip_rate/float(self._length)
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
+ print "Using PN sequence of degree", self._degree, "length", self._length
+ print "Sequence repetition rate is", n2s(self._rep_rate), "per sec"
- 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)
+ self.define_component("corr", gr.pn_correlator_cc(self._degree))
+ self.connect("self", 0, "corr", 0)
+ self.connect("corr", 0, "self", 0)
diff --git a/gnuradio-examples/python/hier/sounder/sounder_tx.py b/gnuradio-examples/python/hier/sounder/sounder_tx.py
index e6a3e84f8..7d91f36e1 100644
--- a/gnuradio-examples/python/hier/sounder/sounder_tx.py
+++ b/gnuradio-examples/python/hier/sounder/sounder_tx.py
@@ -21,50 +21,26 @@
#
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.
+ Creates a channel sounder generator 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
+ def __init__(self, degree, chip_rate, verbose):
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
+ "sounder_tx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
- 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._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
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)
+ # Connect PN source to block output
+ self.define_component("glfsr", gr.glfsr_source_f(degree))
+ self.connect("glfsr", 0, "self", 0)
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
index dd8007cbb..72ebeccfa 100755
--- a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
@@ -23,47 +23,85 @@
from gnuradio import gr, eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
+from usrp_source import usrp_source_c
from sounder_rx import sounder_rx
-def main():
- parser = OptionParser(option_class=eng_option)
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_rx(gr.hier_block2):
+ def __init__(self, options):
+ gr.hier_block2.__init__(self, "usrp_sounder_rx",
+ gr.io_signature(0,0,0),
+ gr.io_signature(0,0,0))
+
+ self._options = options
+ self._u = usrp_source_c(0,
+ self._options.rx_subdev_spec,
+ self._options.gain,
+ self._options.chip_rate,
+ self._options.freq,
+ self._options.cal,
+ self._options.verbose)
+ self._options.chip_rate = self._u._if_rate
+ self._length = 2**self._options.degree-1
+ self._receiver = sounder_rx(self._options.chip_rate,
+ self._options.degree,
+ self._options.verbose)
+
+ samples = 100 * self._length**2
- # 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()
+ self.define_component("usrp", self._u)
+ self.define_component("head", gr.head(gr.sizeof_gr_complex, samples))
+ self.define_component("rx", self._receiver)
+ self.define_component("c2m", gr.complex_to_mag())
+ self.define_component("s2v", gr.stream_to_vector(gr.sizeof_float, self._length))
+ self.define_component("lpf", gr.single_pole_iir_filter_ff(self._options.alpha, self._length))
+ self.define_component("v2s", gr.vector_to_stream(gr.sizeof_float, self._length))
+ self.define_component("sink", gr.file_sink(gr.sizeof_float, "impulse.dat"))
- if len(args) != 0:
- parser.print_help()
- sys.exit(1)
+ self.connect("usrp", 0, "head", 0)
+ self.connect("head", 0, "rx", 0)
+ self.connect("rx", 0, "c2m", 0)
+ self.connect("c2m", 0, "s2v", 0)
+ self.connect("s2v", 0, "lpf", 0)
+ self.connect("lpf", 0, "v2s", 0)
+ self.connect("v2s", 0, "sink", 0)
+
+ if self._options.verbose:
+ print "Chip rate is", n2s(self._options.chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._options.chip_rate), "sec"
+ print "Using PN code of degree", self._options.degree
+
+def main():
+ 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 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", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, 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 receiver gain (default=%default)")
+ parser.add_option("", "--alpha", type="eng_float", default=1.0,
+ help="set smoothing constant (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)
+ top_block = usrp_sounder_rx(options)
+ runtime = gr.runtime(top_block)
- try:
- # Run forever
- runtime.run()
- except KeyboardInterrupt:
- # Ctrl-C exits
- pass
+ try:
+ runtime.run()
+ except KeyboardInterrupt:
+ 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
index c96313c67..00146146c 100755
--- a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
@@ -23,8 +23,49 @@
from gnuradio import gr, eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
+from usrp_sink import usrp_sink_c
from sounder_tx import sounder_tx
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_tx(gr.hier_block2):
+ def __init__(self, subdev_spec, freq, cal, verbose, degree, chip_rate, amplitude):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.hier_block2.__init__(self,
+ "usrp_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._degree = degree
+ self._length = 2**degree-1
+ self._amplitude = amplitude
+
+ self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, self._verbose)
+ self.define_component("usrp", self._u)
+ self._chip_rate = self._u._if_rate
+ self._max_time = float(self._length)/self._chip_rate
+ self.define_component("pn", sounder_tx(self._degree, self._chip_rate, self._verbose))
+ self.define_component("gain", gr.multiply_const_ff(amplitude));
+ self.define_component("f2c", gr.float_to_complex())
+
+ if self._verbose:
+ print "Chip rate is", n2s(self._chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._chip_rate), "sec"
+ print "Using PN code of degree", self._degree, "length", 2**self._degree-1
+ print "Maximum measurable impulse response is", n2s(self._max_time), "sec"
+ print "Output amplitude is", amplitude
+
+ # Ultimately this will be
+ # self.connect("pn gain f2c usrp")
+ self.connect("pn", 0, "gain", 0)
+ self.connect("gain", 0, "f2c", 0)
+ self.connect("f2c", 0, "usrp", 0)
+
def main():
parser = OptionParser(option_class=eng_option)
@@ -37,22 +78,35 @@ def main():
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("-d", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, 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,
+ parser.add_option("-g", "--amplitude", type="eng_float", default=8000.0,
help="set output amplitude (default=%default)")
+ parser.add_option("", "--real-time", action="store_true", default=False,
+ help="Attempt to enable real-time scheduling")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
sys.exit(1)
+ if not options.real_time:
+ realtime = False
+ else:
+ # Attempt to enable realtime scheduling
+ r = gr.enable_realtime_scheduling()
+ if r == gr.RT_OK:
+ realtime = True
+ else:
+ realtime = False
+ print "Note: failed to enable realtime scheduling"
+
# 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)
+ top_block = usrp_sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
+ options.verbose, options.degree, options.chip_rate,
+ options.amplitude)
# Create an instance of a runtime, passing it the top block
# to process
diff --git a/gnuradio-examples/python/hier/sounder/usrp_source.py b/gnuradio-examples/python/hier/sounder/usrp_source.py
index 16949998b..0ba9e6161 100644
--- a/gnuradio-examples/python/hier/sounder/usrp_source.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_source.py
@@ -93,7 +93,9 @@ class usrp_source_c(gr.hier_block2):
gain = (g[0]+g[1])/2.0
self._gain = gain
self._subdev.set_gain(self._gain)
-
+ if self._verbose:
+ print "USRP gain set to", self._gain
+
def set_calibration(self, calibration):
self._cal = calibration
if self._verbose: