2 # Copyright 2010 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
22 from gnuradio import eng_notation
24 _default_bitrate = 500e3
26 def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
27 xrate, converter_rate, xrates, gen_info):
29 @returns tuple (bitrate, samples_per_symbol, interp_rate_or_decim_rate)
32 if not isinstance(bits_per_symbol, int) or bits_per_symbol < 1:
33 raise ValueError, "bits_per_symbol must be an int >= 1"
35 if samples_per_symbol is not None and xrate is not None: # completely determined
36 return (float(converter_rate) / xrate / samples_per_symbol,
37 samples_per_symbol, xrate)
39 # If no parameters are give, use the default bit rate
40 if bitrate is None and samples_per_symbol is None and xrate is None:
41 bitrate = _default_bitrate
43 # If only bitrate is specified, return max xrate and appropriate
44 # samples per symbol to reach bit rate
45 if samples_per_symbol is None and xrate is None:
47 for i in xrange(len(xrates)):
48 if((converter_rate / float(bits_per_symbol) / xrates[i]) >= 2*bitrate):
53 sps = converter_rate / float(bits_per_symbol) / decim / bitrate
54 br = converter_rate / float(bits_per_symbol) / decim / sps
56 return (br, sps, int(decim))
59 # now we have a target bitrate and possibly an xrate or
60 # samples_per_symbol constraint, but not both of them.
61 ret = _pick_best(bitrate, bits_per_symbol,
62 _filter_info(gen_info(converter_rate, xrates),
63 samples_per_symbol, xrate))
65 print "Actual Bitrate:", eng_notation.num_to_str(ret[0])
70 def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
71 interp_rate, converter_rate, possible_interps):
73 Given the 4 input parameters, return at configuration that matches
75 @param bitrate: desired bitrate or None
76 @type bitrate: number or None
77 @param bits_per_symbol: E.g., BPSK -> 1, QPSK -> 2, 8-PSK -> 3
78 @type bits_per_symbol: integer >= 1
79 @param samples_per_symbol: samples/baud (aka samples/symbol)
80 @type samples_per_symbol: number or None
81 @param interp_rate: USRP interpolation factor
82 @type interp_rate: integer or None
83 @param converter_rate: converter sample rate in Hz
84 @type converter_rate: number
85 @param possible_interps: a list of possible rates
86 @type possible_interps: a list of integers
88 @returns tuple (bitrate, samples_per_symbol, interp_rate)
91 return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
92 interp_rate, converter_rate, possible_interps, _gen_tx_info)
94 rates = list(possible_interps)
97 for i in xrange(len(rates)):
98 if((converter_rate / float(bits_per_symbol) / rates[i]) >= 2*bitrate):
103 sps = converter_rate / float(bits_per_symbol) / interp / bitrate
104 br = converter_rate / float(bits_per_symbol) / interp / sps
106 return (br, sps, int(interp))