Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / nbfm_rx.py
1 #
2 # Copyright 2005 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 2, 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 import math
23 from gnuradio import gr, optfir
24 from gnuradio.blksimpl.fm_emph import fm_deemph
25 from gnuradio.blksimpl.standard_squelch import standard_squelch
26
27 class nbfm_rx(gr.hier_block):
28     def __init__(self, fg, audio_rate, quad_rate, tau=75e-6, max_dev=5e3):
29         """
30         Narrow Band FM Receiver.
31
32         Takes a single complex baseband input stream and produces a single
33         float output stream of audio sample in the range [-1, +1].
34
35         @param fg: flow graph
36         @param audio_rate: sample rate of audio stream, >= 16k
37         @type audio_rate: integer
38         @param quad_rate: sample rate of output stream
39         @type quad_rate: integer
40         @param tau: preemphasis time constant (default 75e-6)
41         @type tau: float
42         @param max_dev: maximum deviation in Hz (default 5e3)
43         @type max_dev: float
44
45         quad_rate must be an integer multiple of audio_rate.
46
47         Exported sub-blocks (attributes):
48           squelch
49           quad_demod
50           deemph
51           audio_filter
52         """
53
54         # FIXME audio_rate and quad_rate ought to be exact rationals
55         audio_rate = int(audio_rate)
56         quad_rate = int(quad_rate)
57
58         if quad_rate % audio_rate != 0:
59             raise ValueError, "quad_rate is not an integer multiple of audio_rate"
60
61         squelch_threshold = 20          # dB
62         #self.squelch = gr.simple_squelch_cc(squelch_threshold, 0.001)
63
64         # FM Demodulator  input: complex; output: float
65         k = quad_rate/(2*math.pi*max_dev)
66         self.quad_demod = gr.quadrature_demod_cf(k)
67
68         # FM Deemphasis IIR filter
69         self.deemph = fm_deemph (fg, quad_rate, tau=tau)
70
71         # compute FIR taps for audio filter
72         audio_decim = quad_rate // audio_rate
73         audio_taps = gr.firdes.low_pass (1.0,            # gain
74                                          quad_rate,      # sampling rate
75                                          4.5e3,          # Audio LPF cutoff
76                                          2.5e3,          # Transition band
77                                          gr.firdes.WIN_HAMMING)  # filter type
78
79         print "len(audio_taps) =", len(audio_taps)
80
81         # Decimating audio filter
82         # input: float; output: float; taps: float
83         self.audio_filter = gr.fir_filter_fff(audio_decim, audio_taps)
84
85         fg.connect(self.quad_demod, self.deemph, self.audio_filter)
86
87         gr.hier_block.__init__(self, fg, self.quad_demod, self.audio_filter)