summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-examples/python')
-rw-r--r--gnuradio-examples/python/digital/pick_bitrate2.py33
-rw-r--r--gnuradio-examples/python/digital/transmit_path.py2
-rw-r--r--gnuradio-examples/python/digital/usrp_transmit_path.py10
3 files changed, 38 insertions, 7 deletions
diff --git a/gnuradio-examples/python/digital/pick_bitrate2.py b/gnuradio-examples/python/digital/pick_bitrate2.py
index a951c4a65..23081117c 100644
--- a/gnuradio-examples/python/digital/pick_bitrate2.py
+++ b/gnuradio-examples/python/digital/pick_bitrate2.py
@@ -22,6 +22,8 @@
from gnuradio import eng_notation
_default_bitrate = 500e3
+_sps_min = 2
+_sps_max = 100
def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
xrate, converter_rate, xrates):
@@ -44,7 +46,7 @@ def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
xrate = max(xrates)
bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
- # If only xrate is given
+ # If only xrate is given, just set SPS to 2 and calculate bitrate
if (bitrate is None) and (samples_per_symbol is None) and (xrate is not None):
samples_per_symbol = 2.0
bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
@@ -63,7 +65,12 @@ def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
else:
break
- xrate = rate
+ try:
+ xrate = rate
+ except UnboundLocalError:
+ print "Requested bitrate out of bounds"
+ sys.exit(1)
+
samples_per_symbol = converter_rate / bits_per_symbol / rate / bitrate
bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
@@ -74,7 +81,27 @@ def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
# If bitrate and SPS are specified
if(xrate is None):
xrate = converter_rate / samples_per_symbol / bits_per_symbol / bitrate
-
+ if((xrate in xrates) == False):
+ # Find the closest avaiable rate larger than the calculated one
+ xrates.sort()
+ for x in xrates:
+ if(x > xrate):
+ xrate = x
+ break
+ if(xrate > max(xrates)):
+ xrate = max(xrates)
+
+ bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
+ print "Could not find suitable rate for specified SPS and Bitrate"
+ print "Using rate = %d for bitrate of %sbps" % \
+ (xrate, (eng_notation.num_to_str(bitrate)))
+
+ if((xrate in xrates) == False):
+ raise ValueError(("Invalid rate (rate = %d)" % xrate))
+ if((samples_per_symbol < _sps_min) or (samples_per_symbol > _sps_max)):
+ raise ValueError(("Invalid samples per symbol (sps = %.2f). Must be in [%.0f, %.0f]." \
+ % (xrate, _sps_min, _sps_max)))
+
return (bitrate, samples_per_symbol, int(xrate))
diff --git a/gnuradio-examples/python/digital/transmit_path.py b/gnuradio-examples/python/digital/transmit_path.py
index a23f8d191..ba0c434da 100644
--- a/gnuradio-examples/python/digital/transmit_path.py
+++ b/gnuradio-examples/python/digital/transmit_path.py
@@ -99,7 +99,7 @@ class transmit_path(gr.hier_block2):
help="set transmitter digital amplitude: 0 <= AMPL < 1 [default=%default]")
normal.add_option("-v", "--verbose", action="store_true", default=False)
- expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
+ expert.add_option("-S", "--samples-per-symbol", type="int", default=None,
help="set samples/symbol [default=%default]")
expert.add_option("", "--log", action="store_true", default=False,
help="Log all parts of flow graph to file (CAUTION: lots of data)")
diff --git a/gnuradio-examples/python/digital/usrp_transmit_path.py b/gnuradio-examples/python/digital/usrp_transmit_path.py
index 5d841d3e6..2a2765bcd 100644
--- a/gnuradio-examples/python/digital/usrp_transmit_path.py
+++ b/gnuradio-examples/python/digital/usrp_transmit_path.py
@@ -79,15 +79,19 @@ class usrp_transmit_path(gr.hier_block2):
self.u = usrp_options.create_usrp_sink(options)
dac_rate = self.u.dac_rate()
self.rs_rate = options.bitrate # Store requested bit rate
- if options.verbose:
- print 'USRP Sink:', self.u
(self._bitrate, self._samples_per_symbol, self._interp) = \
- pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(), \
+ pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(),
+ options.samples_per_symbol, options.interp,
dac_rate, self.u.get_interp_rates())
options.interp = self._interp
options.samples_per_symbol = self._samples_per_symbol
+ options.bitrate = self._bitrate
+
+ if options.verbose:
+ print 'USRP Sink:', self.u
+ print "Interpolation Rate: ", self._interp
self.u.set_interp(self._interp)
self.u.set_auto_tr(True)