summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/digital
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-examples/python/digital')
-rw-r--r--gnuradio-examples/python/digital/pick_bitrate2.py64
-rw-r--r--gnuradio-examples/python/digital/usrp_receive_path.py19
-rw-r--r--gnuradio-examples/python/digital/usrp_transmit_path.py16
3 files changed, 84 insertions, 15 deletions
diff --git a/gnuradio-examples/python/digital/pick_bitrate2.py b/gnuradio-examples/python/digital/pick_bitrate2.py
new file mode 100644
index 000000000..c0188dc3c
--- /dev/null
+++ b/gnuradio-examples/python/digital/pick_bitrate2.py
@@ -0,0 +1,64 @@
+from gnuradio import eng_notation
+
+def pick_rx_bitrate(bitrate, bits_per_symbol,
+ converter_rate, possible_decims):
+ """
+ Given the 4 input parameters, return at configuration that matches
+
+ @param bitrate: desired bitrate or None
+ @type bitrate: number or None
+ @param bits_per_symbol: E.g., BPSK -> 1, QPSK -> 2, 8-PSK -> 3
+ @type bits_per_symbol: integer >= 1
+ @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)
+ """
+
+ rates = list(possible_decims)
+ rates.sort()
+
+ for i in xrange(len(rates)):
+ if((converter_rate / float(bits_per_symbol) / rates[i]) >= 2*bitrate):
+ decim = rates[i]
+ else:
+ break
+
+ sps = converter_rate / float(bits_per_symbol) / decim / bitrate
+ br = converter_rate / float(bits_per_symbol) / decim / sps
+
+ return (br, sps, int(decim))
+
+
+def pick_tx_bitrate(bitrate, bits_per_symbol,
+ converter_rate, possible_interps):
+ """
+ Given the 4 input parameters, return at configuration that matches
+
+ @param bitrate: desired bitrate or None
+ @type bitrate: number or None
+ @param bits_per_symbol: E.g., BPSK -> 1, QPSK -> 2, 8-PSK -> 3
+ @type bits_per_symbol: integer >= 1
+ @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)
+ """
+
+ rates = list(possible_interps)
+ rates.sort()
+
+ for i in xrange(len(rates)):
+ if((converter_rate / float(bits_per_symbol) / rates[i]) >= 2*bitrate):
+ interp = rates[i]
+ else:
+ break
+
+ sps = converter_rate / float(bits_per_symbol) / interp / bitrate
+ br = converter_rate / float(bits_per_symbol) / interp / sps
+
+ return (br, sps, int(interp))
diff --git a/gnuradio-examples/python/digital/usrp_receive_path.py b/gnuradio-examples/python/digital/usrp_receive_path.py
index 517825cc1..2d3d648a0 100644
--- a/gnuradio-examples/python/digital/usrp_receive_path.py
+++ b/gnuradio-examples/python/digital/usrp_receive_path.py
@@ -22,7 +22,7 @@
from gnuradio import gr
from gnuradio import usrp_options
import receive_path
-from pick_bitrate import pick_rx_bitrate
+from pick_bitrate2 import pick_rx_bitrate
from gnuradio import eng_notation
def add_freq_option(parser):
@@ -81,16 +81,19 @@ class usrp_receive_path(gr.hier_block2):
self.rs_rate = options.bitrate
if options.verbose:
print 'USRP Source:', self.u
+
+
+ #(self._bitrate, self._samples_per_symbol, self._decim) = \
+ # pick_rx_bitrate(options.bitrate, self._demod_class.bits_per_symbol(), \
+ # options.samples_per_symbol, options.decim, adc_rate, \
+ # self.u.get_decim_rates())
(self._bitrate, self._samples_per_symbol, self._decim) = \
pick_rx_bitrate(options.bitrate, self._demod_class.bits_per_symbol(), \
- options.samples_per_symbol, options.decim, adc_rate, \
- self.u.get_decim_rates())
+ adc_rate, self.u.get_decim_rates())
+
+ print "USRP Decimation: ", self._decim
+ print "Samples Per Symbol: ", self._samples_per_symbol
- # Calculate resampler rate based on requested and actual rates
- self.rs_rate = 1.0 /(self._bitrate / self.rs_rate)
-
- print "Resampling by %f to get bitrate of %ssps" % ( self.rs_rate, eng_notation.num_to_str(self._bitrate/self.rs_rate))
-
self.u.set_decim(self._decim)
if not self.u.set_center_freq(options.rx_freq):
diff --git a/gnuradio-examples/python/digital/usrp_transmit_path.py b/gnuradio-examples/python/digital/usrp_transmit_path.py
index ee63dcd2b..4244c33f2 100644
--- a/gnuradio-examples/python/digital/usrp_transmit_path.py
+++ b/gnuradio-examples/python/digital/usrp_transmit_path.py
@@ -22,7 +22,7 @@
from gnuradio import gr
from gnuradio import usrp_options
import transmit_path
-from pick_bitrate import pick_tx_bitrate
+from pick_bitrate2 import pick_tx_bitrate
from gnuradio import eng_notation
def add_freq_option(parser):
@@ -84,15 +84,17 @@ class usrp_transmit_path(gr.hier_block2):
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(), \
+ # options.samples_per_symbol, options.interp, dac_rate, \
+ # self.u.get_interp_rates())
(self._bitrate, self._samples_per_symbol, self._interp) = \
pick_tx_bitrate(options.bitrate, self._modulator_class.bits_per_symbol(), \
- options.samples_per_symbol, options.interp, dac_rate, \
- self.u.get_interp_rates())
-
- # Calculate resampler rate based on requested and actual rates
- self.rs_rate = self._bitrate / self.rs_rate
- print "Resampling by %f to get bitrate of %ssps" % (self.rs_rate, eng_notation.num_to_str(self._bitrate/self.rs_rate))
+ dac_rate, self.u.get_interp_rates())
+ print "USRP Interpolation: ", self._interp
+ print "Samples Per Symbol: ", self._samples_per_symbol
+
self.u.set_interp(self._interp)
self.u.set_auto_tr(True)