Imported Upstream version 3.0.4
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / fm_demod.py
1 #
2 # Copyright 2006 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.blksimpl.fm_emph import fm_deemph
24 from math import pi
25
26 class fm_demod_cf(gr.hier_block):
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 fg: flowgraph
37     @param channel_rate:  incoming sample rate of the FM baseband
38     @type sample_rate: integer
39     @param deviation: maximum FM deviation (default = 5000)
40     @type deviation: float
41     @param audio_decim: input to output decimation rate
42     @type audio_decim: integer
43     @param audio_pass: audio low pass filter passband frequency 
44     @type audio_pass: float
45     @param audio_stop: audio low pass filter stop frequency
46     @type audio_stop: float
47     @param gain: gain applied to audio output (default = 1.0)
48     @type gain: float
49     @param tau: deemphasis time constant (default = 75e-6), specify 'None'
50        to prevent deemphasis
51     """ 
52     def __init__(self, fg, channel_rate, audio_decim, deviation, 
53                  audio_pass, audio_stop, gain=1.0, tau=75e-6):
54
55         """     
56         # Equalizer for ~100 us delay
57         delay = 100e-6
58         num_taps = int(channel_rate*delay)
59
60         mu = 1e-4/num_taps
61         print "CMA: delay =", delay, "n =", num_taps, "mu =", mu
62         CMA = gr.cma_equalizer_cc(num_taps, 1.0, mu)
63         """     
64         k = channel_rate/(2*pi*deviation)
65         QUAD = gr.quadrature_demod_cf(k)
66
67         audio_taps = optfir.low_pass(gain,         # Filter gain
68                                      channel_rate, # Sample rate
69                                      audio_pass,   # Audio passband
70                                      audio_stop,   # Audio stopband
71                                      0.1,          # Passband ripple
72                                      60)           # Stopband attenuation
73         LPF = gr.fir_filter_fff(audio_decim, audio_taps)
74
75         if tau is not None:
76             DEEMPH = fm_deemph(fg, channel_rate, tau)
77             fg.connect(QUAD, DEEMPH, LPF)
78         else:
79             fg.connect(QUAD, LPF)
80
81         gr.hier_block.__init__(self, fg, QUAD, LPF)
82
83 class demod_20k0f3e_cf(fm_demod_cf):
84     """
85     NBFM demodulation block, 20 KHz channels
86
87     This block demodulates a complex, downconverted, narrowband FM 
88     channel conforming to 20K0F3E emission standards, outputting
89     floats in the range [-1.0, +1.0].
90     
91     @param fg: flowgraph
92     @param sample_rate:  incoming sample rate of the FM baseband
93     @type sample_rate: integer
94     @param audio_decim: input to output decimation rate
95     @type audio_decim: integer
96     """ 
97     def __init__(self, fg, channel_rate, audio_decim):
98         fm_demod_cf.__init__(self, fg, channel_rate, audio_decim,
99                              5000,      # Deviation
100                              3000,      # Audio passband frequency
101                              4000)      # Audio stopband frequency
102
103 class demod_200kf3e_cf(fm_demod_cf):
104     """
105     WFM demodulation block, mono.
106     
107     This block demodulates a complex, downconverted, wideband FM 
108     channel conforming to 200KF3E emission standards, outputting 
109     floats in the range [-1.0, +1.0].
110
111     @param fg: flowgraph
112     @param sample_rate:  incoming sample rate of the FM baseband
113     @type sample_rate: integer
114     @param audio_decim: input to output decimation rate
115     @type audio_decim: integer
116     """
117     def __init__(self, fg, channel_rate, audio_decim): 
118         fm_demod_cf.__init__(self, fg, channel_rate, audio_decim,
119                              75000,     # Deviation
120                              15000,     # Audio passband
121                              16000,     # Audio stopband
122                              20.0)      # Audio gain