summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/digital/pick_bitrate2.py
diff options
context:
space:
mode:
authorTom Rondeau2010-02-25 18:50:24 -0500
committerTom Rondeau2010-02-25 18:50:24 -0500
commit85aad96915db5f53897f91257794c85eb67f39d4 (patch)
treeb7ceed4422687cc3aa62187da702f1501556cb45 /gnuradio-examples/python/digital/pick_bitrate2.py
parent7d5e47e14126e37ad78164df448d0fcc4b04c558 (diff)
downloadgnuradio-85aad96915db5f53897f91257794c85eb67f39d4.tar.gz
gnuradio-85aad96915db5f53897f91257794c85eb67f39d4.tar.bz2
gnuradio-85aad96915db5f53897f91257794c85eb67f39d4.zip
Fixing pick_bitrate2 for transmit side with all cases tested.
Diffstat (limited to 'gnuradio-examples/python/digital/pick_bitrate2.py')
-rw-r--r--gnuradio-examples/python/digital/pick_bitrate2.py33
1 files changed, 30 insertions, 3 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))