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):
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 converter_rate = float(converter_rate)
36 bits_per_symbol = float(bits_per_symbol)
38 # completely determined; if bitrate is specified, this overwrites it
39 if (samples_per_symbol is not None) and (xrate is not None):
40 bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
42 # If only SPS is given
43 if (bitrate is None) and (samples_per_symbol is not None) and (xrate is None):
45 bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
47 # If only xrate is given
48 if (bitrate is None) and (samples_per_symbol is None) and (xrate is not None):
49 samples_per_symbol = 2.0
50 bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
52 # If no parameters are give, use the default bit rate
53 if (bitrate is None) and (samples_per_symbol is None) and (xrate is None):
54 bitrate = _default_bitrate
56 # If only bitrate is specified, return max xrate and appropriate
57 # samples per symbol (minimum of 2.0) to reach bit rate
58 if (samples_per_symbol is None) and (xrate is None):
60 for i in xrange(len(xrates)):
61 if((converter_rate / bits_per_symbol / xrates[i]) >= 2*bitrate):
67 samples_per_symbol = converter_rate / bits_per_symbol / rate / bitrate
68 bitrate = converter_rate / bits_per_symbol / xrate / samples_per_symbol
70 # If bitrate and xrate are specified
71 if(samples_per_symbol is None):
72 samples_per_symbol = converter_rate / xrate / bits_per_symbol / bitrate
74 # If bitrate and SPS are specified
76 xrate = converter_rate / samples_per_symbol / bits_per_symbol / bitrate
78 return (bitrate, samples_per_symbol, int(xrate))
81 def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
82 interp_rate, converter_rate, possible_interps):
84 Given the 4 input parameters, return at configuration that matches
86 @param bitrate: desired bitrate or None
87 @type bitrate: number or None
88 @param bits_per_symbol: E.g., BPSK -> 1, QPSK -> 2, 8-PSK -> 3
89 @type bits_per_symbol: integer >= 1
90 @param samples_per_symbol: samples/baud (aka samples/symbol)
91 @type samples_per_symbol: number or None
92 @param interp_rate: USRP interpolation factor
93 @type interp_rate: integer or None
94 @param converter_rate: converter sample rate in Hz
95 @type converter_rate: number
96 @param possible_interps: a list of possible rates
97 @type possible_interps: a list of integers
99 @returns tuple (bitrate, samples_per_symbol, interp_rate)
102 return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
103 interp_rate, converter_rate, possible_interps)
106 def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
107 decim_rate, converter_rate, possible_decims):
109 Given the 4 input parameters, return at configuration that matches
111 @param bitrate: desired bitrate or None
112 @type bitrate: number or None
113 @param bits_per_symbol: E.g., BPSK -> 1, QPSK -> 2, 8-PSK -> 3
114 @type bits_per_symbol: integer >= 1
115 @param samples_per_symbol: samples/baud (aka samples/symbol)
116 @type samples_per_symbol: number or None
117 @param decim_rate: USRP decimation factor
118 @type decim_rate: integer or None
119 @param converter_rate: converter sample rate in Hz
120 @type converter_rate: number
121 @param possible_decims: a list of possible rates
122 @type possible_decims: a list of integers
124 @returns tuple (bitrate, samples_per_symbol, decim_rate)
127 return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
128 decim_rate, converter_rate, possible_decims)