Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blks2impl / wfm_rcv.py
1 #
2 # Copyright 2005,2007 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
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)
9 # any later version.
10
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.
15
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.
20
21
22 from gnuradio import gr
23 from gnuradio.blks2impl.fm_emph import fm_deemph
24 import math
25
26 class wfm_rcv(gr.hier_block2):
27     def __init__ (self, quad_rate, audio_decimation):
28         """
29         Hierarchical block for demodulating a broadcast FM signal.
30         
31         The input is the downconverted complex baseband signal (gr_complex).
32         The output is the demodulated audio (float).
33         
34         @param quad_rate: input sample rate of complex baseband input.
35         @type quad_rate: float
36         @param audio_decimation: how much to decimate quad_rate to get to audio.
37         @type audio_decimation: integer
38         """
39         gr.hier_block2.__init__(self, "wfm_rcv",
40                                 gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
41                                 gr.io_signature(1, 1, gr.sizeof_float))      # Output signature
42
43         volume = 20.
44
45         max_dev = 75e3
46         fm_demod_gain = quad_rate/(2*math.pi*max_dev)
47         audio_rate = quad_rate / audio_decimation
48         
49
50         # We assign to self so that outsiders can grab the demodulator 
51         # if they need to.  E.g., to plot its output.
52         #
53         # input: complex; output: float
54         self.fm_demod = gr.quadrature_demod_cf (fm_demod_gain)
55
56         # input: float; output: float
57         self.deemph = fm_deemph (audio_rate)
58         
59         # compute FIR filter taps for audio filter
60         width_of_transition_band = audio_rate / 32
61         audio_coeffs = gr.firdes.low_pass (1.0,         # gain
62                                            quad_rate,      # sampling rate
63                                            audio_rate/2 - width_of_transition_band,
64                                            width_of_transition_band,
65                                            gr.firdes.WIN_HAMMING)
66         # input: float; output: float
67         self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs)
68
69         self.connect (self, self.fm_demod, self.audio_filter, self.deemph, self)