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