~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gnuradio-examples/python/digital/pick_bitrate.py

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
1
#
3
2
# Copyright 2005,2006 Free Software Foundation, Inc.
4
3
20
19
# Boston, MA 02110-1301, USA.
21
20
22
21
 
 
22
from gnuradio import eng_notation
 
23
 
23
24
_default_bitrate = 500e3
24
25
 
25
26
_valid_samples_per_symbol = (2,3,4,5,6,7)
26
27
 
27
 
def _gen_tx_info(converter_rate):
 
28
def _gen_tx_info(converter_rate, xrates):
28
29
    results = []
29
30
    for samples_per_symbol in _valid_samples_per_symbol:
30
 
        for interp in range(16, 512 + 1, 4):
 
31
        for interp in xrates:
31
32
            bitrate = converter_rate / interp / samples_per_symbol
32
33
            results.append((bitrate, samples_per_symbol, interp))
33
34
    results.sort()
34
35
    return results
35
36
 
36
 
def _gen_rx_info(converter_rate):
 
37
def _gen_rx_info(converter_rate, xrates):
37
38
    results = []
38
39
    for samples_per_symbol in _valid_samples_per_symbol:
39
 
        for decim in range(8, 256 + 1, 2):
 
40
        for decim in xrates:
40
41
            bitrate = converter_rate / decim / samples_per_symbol
41
42
            results.append((bitrate, samples_per_symbol, decim))
42
43
    results.sort()
78
79
    return ((best[0] * bits_per_symbol),) + best[1:]
79
80
 
80
81
def _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
81
 
                  xrate, converter_rate, gen_info):
 
82
                  xrate, converter_rate, xrates, gen_info):
82
83
    """
83
84
    @returns tuple (bitrate, samples_per_symbol, interp_rate_or_decim_rate)
84
85
    """
95
96
    # now we have a target bitrate and possibly an xrate or
96
97
    # samples_per_symbol constraint, but not both of them.
97
98
 
98
 
    return _pick_best(bitrate, bits_per_symbol,
99
 
                      _filter_info(gen_info(converter_rate), samples_per_symbol, xrate))
 
99
    ret = _pick_best(bitrate, bits_per_symbol,
 
100
                      _filter_info(gen_info(converter_rate, xrates), samples_per_symbol, xrate))
 
101
    print "Actual Bitrate:", eng_notation.num_to_str(ret[0])
 
102
    return ret
100
103
    
101
104
# ---------------------------------------------------------------------------------------
102
105
 
103
106
def pick_tx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
104
 
                    interp_rate, converter_rate=128e6):
 
107
                    interp_rate, converter_rate, possible_interps):
105
108
    """
106
109
    Given the 4 input parameters, return at configuration that matches
107
110
 
115
118
    @type interp_rate: integer or None
116
119
    @param converter_rate: converter sample rate in Hz
117
120
    @type converter_rate: number
 
121
    @param possible_interps: a list of possible rates
 
122
    @type possible_interps: a list of integers
118
123
 
119
124
    @returns tuple (bitrate, samples_per_symbol, interp_rate)
120
125
    """
 
126
    print "Requested TX Bitrate:", bitrate and eng_notation.num_to_str(bitrate) or 'Auto',
121
127
    return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
122
 
                         interp_rate, converter_rate, _gen_tx_info)
 
128
                         interp_rate, converter_rate, possible_interps, _gen_tx_info)
123
129
 
124
130
 
125
131
def pick_rx_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
126
 
                    decim_rate, converter_rate=64e6):
 
132
                    decim_rate, converter_rate, possible_decims):
127
133
    """
128
134
    Given the 4 input parameters, return at configuration that matches
129
135
 
137
143
    @type decim_rate: integer or None
138
144
    @param converter_rate: converter sample rate in Hz
139
145
    @type converter_rate: number
 
146
    @param possible_decims: a list of possible rates
 
147
    @type possible_decims: a list of integers
140
148
 
141
149
    @returns tuple (bitrate, samples_per_symbol, decim_rate)
142
150
    """
 
151
    print "Requested RX Bitrate:", bitrate and eng_notation.num_to_str(bitrate) or 'Auto'
143
152
    return _pick_bitrate(bitrate, bits_per_symbol, samples_per_symbol,
144
 
                         decim_rate, converter_rate, _gen_rx_info)
 
153
                         decim_rate, converter_rate, possible_decims, _gen_rx_info)