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.blksimpl.fm_emph import fm_deemph
25 from gnuradio.blksimpl.standard_squelch import standard_squelch
27 class nbfm_rx(gr.hier_block):
28 def __init__(self, fg, 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].
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)
42 @param max_dev: maximum deviation in Hz (default 5e3)
45 quad_rate must be an integer multiple of audio_rate.
47 Exported sub-blocks (attributes):
54 # FIXME audio_rate and quad_rate ought to be exact rationals
55 audio_rate = int(audio_rate)
56 quad_rate = int(quad_rate)
58 if quad_rate % audio_rate != 0:
59 raise ValueError, "quad_rate is not an integer multiple of audio_rate"
61 squelch_threshold = 20 # dB
62 #self.squelch = gr.simple_squelch_cc(squelch_threshold, 0.001)
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)
68 # FM Deemphasis IIR filter
69 self.deemph = fm_deemph (fg, quad_rate, tau=tau)
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
79 print "len(audio_taps) =", len(audio_taps)
81 # Decimating audio filter
82 # input: float; output: float; taps: float
83 self.audio_filter = gr.fir_filter_fff(audio_decim, audio_taps)
85 fg.connect(self.quad_demod, self.deemph, self.audio_filter)
87 gr.hier_block.__init__(self, fg, self.quad_demod, self.audio_filter)