491159a3171993daa89f068e9d4a5bc652d92c27
[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 2, 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.hier_block2):
34     def __init__(self, options):
35         gr.hier_block2.__init__(self, 
36                                 "dect_receiver",        # Block typename
37                                 gr.io_signature(0,0,0), # Input signature
38                                 gr.io_signature(0,0,0)) # Output signature
39         self._options = options
40
41         # Need greater than 2 samples per symbol. This makes a decimation
42         # rate of 26 and a samples per symbol of 2.136752
43         if_rate = 2.461538e6
44         self._usrp = usrp_source_c(self,
45                                    which=0,
46                                    subdev_spec=options.rx_subdev_spec,
47                                    if_rate=if_rate,
48                                    gain=options.gain,
49                                    freq=options.freq,
50                                    calibration=options.calibration,
51                                    verbose=options.verbose)
52
53         # Filter baseband to 1.186 MHz passband, 1.728 MHz stopband
54         chan_taps = optfir.low_pass(1.0,              # Gain
55                                     if_rate,          # Sample rate
56                                     _dect_occupied_bandwidth/2, # One sided modulation bandwidth
57                                     _dect_channel_bandwidth/2,  # One sided channel bandwidth
58                                     1.0,              # Passband ripple (db)
59                                     60)               # Stopband attenuation (db)
60         if self._options.verbose:
61             print "Channel filter has", len(chan_taps), "taps"
62         self._channel_filter = gr.freq_xlating_fir_filter_ccf(1,         # Decimation rate
63                                                               chan_taps, # Filter taps
64                                                               0.0,       # Offset frequency
65                                                               if_rate)   # Sample rate
66
67         self._demod = gmsk2_demod(samples_per_symbol=if_rate/_dect_symbol_rate,
68                                   verbose=options.verbose)
69
70         # Define and connect components
71         self.define_component("usrp", self._usrp)
72         self.define_component("channel", self._channel_filter)
73         self.define_component("demod", self._demod)
74         self.define_component("sink", gr.null_sink(gr.sizeof_char))
75         self.connect("usrp", 0, "channel", 0)
76         self.connect("channel", 0, "demod", 0)
77         self.connect("demod", 0, "sink", 0)
78
79         # Log baseband to file if requested
80         if options.log_baseband is not None:
81             if options.verbose:
82                 print "Logging baseband to file", options.log_baseband
83             self.define_component("baseband_log", gr.file_sink(gr.sizeof_gr_complex, options.log_baseband))
84             self.connect("channel", 0, "baseband_log", 0)
85
86         # Log demodulator output to file if requested
87         if options.log_demod is not None:
88             if options.verbose:
89                 print "Logging demodulator to file", options.log_demod
90             self.define_component("demod_log", gr.file_sink(gr.sizeof_char, options.log_demod))
91             self.connect("demod", 0, "demod_log", 0)