Fixing pick_bitrate2 for transmit side with all cases tested.
authorTom Rondeau <trondeau@vt.edu>
Thu, 25 Feb 2010 23:50:24 +0000 (18:50 -0500)
committerTom Rondeau <trondeau@vt.edu>
Thu, 25 Feb 2010 23:50:24 +0000 (18:50 -0500)
gnuradio-examples/python/digital/pick_bitrate2.py
gnuradio-examples/python/digital/transmit_path.py
gnuradio-examples/python/digital/usrp_transmit_path.py

index a951c4a6566868d695c6208ad8fd584fcc650738..23081117c9ee8809f54819d570b3eb4be88cd7e9 100644 (file)
@@ -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))
 
 
index a23f8d191788beeae606a38cd4cc83a8193318f4..ba0c434da27e67e30ec7b194e3595f06588c6478 100644 (file)
@@ -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)")
index 5d841d3e6e0457e85a6cdb79e84d295f465aa2c5..2a2765bcd792ab8240911cbb559898d01cdb6562 100644 (file)
@@ -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)