Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blks2impl / fm_demod.py
1 #
2 # Copyright 2006,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, optfir
23 from gnuradio.blks2impl.fm_emph import fm_deemph
24 from math import pi
25
26 class fm_demod_cf(gr.hier_block2):
27     """
28     Generalized FM demodulation block with deemphasis and audio 
29     filtering.
30
31     This block demodulates a band-limited, complex down-converted FM 
32     channel into the the original baseband signal, optionally applying
33     deemphasis. Low pass filtering is done on the resultant signal. It
34     produces an output float strem in the range of [-1.0, +1.0].
35
36     @param channel_rate:  incoming sample rate of the FM baseband
37     @type sample_rate: integer
38     @param deviation: maximum FM deviation (default = 5000)
39     @type deviation: float
40     @param audio_decim: input to output decimation rate
41     @type audio_decim: integer
42     @param audio_pass: audio low pass filter passband frequency 
43     @type audio_pass: float
44     @param audio_stop: audio low pass filter stop frequency
45     @type audio_stop: float
46     @param gain: gain applied to audio output (default = 1.0)
47     @type gain: float
48     @param tau: deemphasis time constant (default = 75e-6), specify 'None'
49        to prevent deemphasis
50     """ 
51     def __init__(self, channel_rate, audio_decim, deviation, 
52                  audio_pass, audio_stop, gain=1.0, tau=75e-6):
53         gr.hier_block2.__init__(self, "fm_demod_cf",
54                                 gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
55                                 gr.io_signature(1, 1, gr.sizeof_float))      # Output signature
56                                 
57         k = channel_rate/(2*pi*deviation)
58         QUAD = gr.quadrature_demod_cf(k)
59
60         audio_taps = optfir.low_pass(gain,         # Filter gain
61                                      channel_rate, # Sample rate
62                                      audio_pass,   # Audio passband
63                                      audio_stop,   # Audio stopband
64                                      0.1,          # Passband ripple
65                                      60)           # Stopband attenuation
66         LPF = gr.fir_filter_fff(audio_decim, audio_taps)
67
68         if tau is not None:
69             DEEMPH = fm_deemph(channel_rate, tau)
70             self.connect(self, QUAD, DEEMPH, LPF, self)
71         else:
72             self.connect(self, QUAD, LPF, self)
73
74 class demod_20k0f3e_cf(fm_demod_cf):
75     """
76     NBFM demodulation block, 20 KHz channels
77
78     This block demodulates a complex, downconverted, narrowband FM 
79     channel conforming to 20K0F3E emission standards, outputting
80     floats in the range [-1.0, +1.0].
81     
82     @param sample_rate:  incoming sample rate of the FM baseband
83     @type sample_rate: integer
84     @param audio_decim: input to output decimation rate
85     @type audio_decim: integer
86     """ 
87     def __init__(self, channel_rate, audio_decim):
88         fm_demod_cf.__init__(self, channel_rate, audio_decim,
89                              5000,      # Deviation
90                              3000,      # Audio passband frequency
91                              4000)      # Audio stopband frequency
92
93 class demod_200kf3e_cf(fm_demod_cf):
94     """
95     WFM demodulation block, mono.
96     
97     This block demodulates a complex, downconverted, wideband FM 
98     channel conforming to 200KF3E emission standards, outputting 
99     floats in the range [-1.0, +1.0].
100
101     @param sample_rate:  incoming sample rate of the FM baseband
102     @type sample_rate: integer
103     @param audio_decim: input to output decimation rate
104     @type audio_decim: integer
105     """
106     def __init__(self, channel_rate, audio_decim): 
107         fm_demod_cf.__init__(self, channel_rate, audio_decim,
108                              75000,     # Deviation
109                              15000,     # Audio passband
110                              16000,     # Audio stopband
111                              20.0)      # Audio gain