Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gnuradio-examples / python / hier / dect / dect_receiver.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 from gnuradio import gr, optfir
24 from usrp_source import usrp_source_c
25 from gmsk2 import gmsk2_demod
26
27 _dect_symbol_rate = 1.152e6
28 _dect_occupied_bandwidth = _dect_symbol_rate * 1.03 # BT=0.5
29 _dect_channel_bandwidth = 1.728e6
30
31 # Top-level hierarchical block that implements DECT demodulation and
32 # decoding.
33 class dect_receiver(gr.top_block):
34     def __init__(self, options):
35         gr.top_block.__init__(self, "dect_receiver")
36         self._options = options
37
38         # Need greater than 2 samples per symbol. This makes a decimation
39         # rate of 26 and a samples per symbol of 2.136752
40         if_rate = 2.461538e6
41         self._usrp = usrp_source_c(which=0,
42                                    subdev_spec=options.rx_subdev_spec,
43                                    if_rate=if_rate,
44                                    gain=options.gain,
45                                    freq=options.freq,
46                                    calibration=options.calibration,
47                                    verbose=options.verbose)
48
49         # Filter baseband to 1.186 MHz passband, 1.728 MHz stopband
50         chan_taps = optfir.low_pass(1.0,              # Gain
51                                     if_rate,          # Sample rate
52                                     _dect_occupied_bandwidth/2, # One sided modulation bandwidth
53                                     _dect_channel_bandwidth/2,  # One sided channel bandwidth
54                                     1.0,              # Passband ripple (db)
55                                     60)               # Stopband attenuation (db)
56         if self._options.verbose:
57             print "Channel filter has", len(chan_taps), "taps"
58         self._channel_filter = gr.freq_xlating_fir_filter_ccf(1,         # Decimation rate
59                                                               chan_taps, # Filter taps
60                                                               0.0,       # Offset frequency
61                                                               if_rate)   # Sample rate
62
63         self._demod = gmsk2_demod(samples_per_symbol=if_rate/_dect_symbol_rate,
64                                   verbose=options.verbose)
65
66         self._sink = gr.null_sink(gr.sizeof_char)
67         self.connect(self._usrp, self._channel_filter, self._demod, self._sink)
68
69         # Log baseband to file if requested
70         if options.log_baseband is not None:
71             if options.verbose:
72                 print "Logging baseband to file", options.log_baseband
73             self.baseband_log = gr.file_sink(gr.sizeof_gr_complex, options.log_baseband)
74             self.connect(self._channel_filter, self.baseband_log)
75
76         # Log demodulator output to file if requested
77         if options.log_demod is not None:
78             if options.verbose:
79                 print "Logging demodulator to file", options.log_demod
80             self.demod_log = gr.file_sink(gr.sizeof_char, options.log_demod)
81             self.connect(self._demod, self.demod_log)