2 # Copyright 2005 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
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)
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.
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.
23 from gnuradio import gr, optfir
24 from gnuradio.blks2impl.fm_emph import fm_deemph
25 #from gnuradio.blks2impl.standard_squelch import standard_squelch
27 class nbfm_rx(gr.hier_block2):
28 def __init__(self, audio_rate, quad_rate, tau=75e-6, max_dev=5e3):
30 Narrow Band FM Receiver.
32 Takes a single complex baseband input stream and produces a single
33 float output stream of audio sample in the range [-1, +1].
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)
41 @param max_dev: maximum deviation in Hz (default 5e3)
44 quad_rate must be an integer multiple of audio_rate.
46 Exported sub-blocks (attributes):
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
57 # FIXME audio_rate and quad_rate ought to be exact rationals
58 audio_rate = int(audio_rate)
59 quad_rate = int(quad_rate)
61 if quad_rate % audio_rate != 0:
62 raise ValueError, "quad_rate is not an integer multiple of audio_rate"
64 squelch_threshold = 20 # dB
65 #self.squelch = gr.simple_squelch_cc(squelch_threshold, 0.001)
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)
71 # FM Deemphasis IIR filter
72 self.deemph = fm_deemph (quad_rate, tau=tau)
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
82 print "len(audio_taps) =", len(audio_taps)
84 # Decimating audio filter
85 # input: float; output: float; taps: float
86 self.audio_filter = gr.fir_filter_fff(audio_decim, audio_taps)
88 self.connect(self, self.quad_demod, self.deemph, self.audio_filter, self)