Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-examples / python / digital / pick_bitrate.py
index 82a47688884d542c95e5a1e3d174e066c4944f73..ce1e021c577103e99a0ee85070e4fee01bd91dd0 100644 (file)
 # Boston, MA 02110-1301, USA.
 # 
 
+from gnuradio import eng_notation
+
 _default_bitrate = 500e3
 
 _valid_samples_per_symbol = (2,3,4,5,6,7)
 
-def _gen_tx_info(converter_rate):
+def _gen_tx_info(converter_rate, xrates):
     results = []
     for samples_per_symbol in _valid_samples_per_symbol:
-        for interp in range(16, 512 + 1, 4):
+        for interp in xrates:
             bitrate = converter_rate / interp / samples_per_symbol
             results.append((bitrate, samples_per_symbol, interp))
     results.sort()
     return results
 
-def _gen_rx_info(converter_rate):
+def _gen_rx_info(converter_rate, xrates):
     results = []
     for samples_per_symbol in _valid_samples_per_symbol:
-        for decim in range(8, 256 + 1, 2):
+        for decim in xrates:
             bitrate = converter_rate / decim / samples_per_symbol
             results.append((bitrate, samples_per_symbol, decim))
     results.sort()
@@ -77,7 +79,7 @@ def _pick_best(target_bitrate, bits_per_symbol, info):
     return ((best[0] * bits_per_symbol),) + best[1:]
 
 def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
-                  xrate, converter_rate, gen_info):
+                  xrate, converter_rate, xrates, gen_info):
     """
     @returns tuple (bitrate, samples_per_symbol, interp_rate_or_decim_rate)
     """
@@ -94,13 +96,15 @@ def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
     # now we have a target bitrate and possibly an xrate or
     # samples_per_symbol constraint, but not both of them.
 
-    return _pick_best(bitrate, bits_per_symbol,
-                      _filter_info(gen_info(converter_rate), samples_per_symbol, xrate))
+    ret = _pick_best(bitrate, bits_per_symbol,
+                      _filter_info(gen_info(converter_rate, xrates), samples_per_symbol, xrate))
+    print "Actual Bitrate:", eng_notation.num_to_str(ret[0])
+    return ret
     
 # ---------------------------------------------------------------------------------------
 
 def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
-                    interp_rate, converter_rate=128e6):
+                    interp_rate, converter_rate, possible_interps):
     """
     Given the 4 input parameters, return at configuration that matches
 
@@ -114,15 +118,18 @@ def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
     @type interp_rate: integer or None
     @param converter_rate: converter sample rate in Hz
     @type converter_rate: number
+    @param possible_interps: a list of possible rates
+    @type possible_interps: a list of integers
 
     @returns tuple (bitrate, samples_per_symbol, interp_rate)
     """
+    print "Requested TX Bitrate:", bitrate and eng_notation.num_to_str(bitrate) or 'Auto',
     return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
-                         interp_rate, converter_rate, _gen_tx_info)
+                         interp_rate, converter_rate, possible_interps, _gen_tx_info)
 
 
 def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
-                    decim_rate, converter_rate=64e6):
+                    decim_rate, converter_rate, possible_decims):
     """
     Given the 4 input parameters, return at configuration that matches
 
@@ -136,8 +143,11 @@ def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
     @type decim_rate: integer or None
     @param converter_rate: converter sample rate in Hz
     @type converter_rate: number
+    @param possible_decims: a list of possible rates
+    @type possible_decims: a list of integers
 
     @returns tuple (bitrate, samples_per_symbol, decim_rate)
     """
+    print "Requested RX Bitrate:", bitrate and eng_notation.num_to_str(bitrate) or 'Auto'
     return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
-                         decim_rate, converter_rate, _gen_rx_info)
+                         decim_rate, converter_rate, possible_decims, _gen_rx_info)