2 # Copyright 2005,2006 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.
22 from gnuradio import gr
23 from gnuradio.blks2impl.fm_emph import fm_deemph
26 class wfm_rcv_pll(gr.hier_block2):
27 def __init__ (self, demod_rate, audio_decimation):
29 Hierarchical block for demodulating a broadcast FM signal.
31 The input is the downconverted complex baseband signal (gr_complex).
32 The output is two streams of the demodulated audio (float) 0=Left, 1=Right.
34 @param demod_rate: input sample rate of complex baseband input.
35 @type demod_rate: float
36 @param audio_decimation: how much to decimate demod_rate to get to audio.
37 @type audio_decimation: integer
39 gr.hier_block2.__init__(self, "wfm_rcv_pll",
40 gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
41 gr.io_signature(2, 2, gr.sizeof_float)) # Output signature
43 audio_rate = demod_rate / audio_decimation
46 # We assign to self so that outsiders can grab the demodulator
47 # if they need to. E.g., to plot its output.
49 # input: complex; output: float
50 alpha = 0.25*bandwidth * math.pi / demod_rate
51 beta = alpha * alpha / 4.0
52 max_freq = 2.0*math.pi*90e3/demod_rate
54 self.fm_demod = gr.pll_freqdet_cf (alpha,beta,max_freq,-max_freq)
56 # input: float; output: float
57 self.deemph_Left = fm_deemph (audio_rate)
58 self.deemph_Right = fm_deemph (audio_rate)
60 # compute FIR filter taps for audio filter
61 width_of_transition_band = audio_rate / 32
62 audio_coeffs = gr.firdes.low_pass (1.0 , # gain
63 demod_rate, # sampling rate
65 width_of_transition_band,
66 gr.firdes.WIN_HAMMING)
67 # input: float; output: float
68 self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs)
70 # Pick off the stereo carrier/2 with this filter. It attenuated 10 dB so apply 10 dB gain
71 # We pick off the negative frequency half because we want to base band by it!
72 ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO DEEMPHASIS
74 stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass(10.0,
78 width_of_transition_band,
79 gr.firdes.WIN_HAMMING)
81 #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs)
82 #print "stereo carrier filter ", stereo_carrier_filter_coeffs
83 #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate
85 # Pick off the double side band suppressed carrier Left-Right audio. It is attenuated 10 dB so apply 10 dB gain
87 stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass(20.0,
91 width_of_transition_band,
92 gr.firdes.WIN_HAMMING)
93 #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
94 #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs
95 # construct overlap add filter system from coefficients for stereo carrier
97 self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs)
99 # carrier is twice the picked off carrier so arrange to do a commplex multiply
101 self.stereo_carrier_generator = gr.multiply_cc();
103 # Pick off the rds signal
105 stereo_rds_filter_coeffs = gr.firdes.complex_band_pass(30.0,
109 width_of_transition_band,
110 gr.firdes.WIN_HAMMING)
111 #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs)
112 #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs
113 # construct overlap add filter system from coefficients for stereo carrier
115 self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs)
122 self.rds_carrier_generator = gr.multiply_cc();
123 self.rds_signal_generator = gr.multiply_cc();
124 self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex);
128 alpha = 5 * 0.25 * math.pi / (audio_rate)
129 beta = alpha * alpha / 4.0
130 max_freq = -2.0*math.pi*18990/audio_rate;
131 min_freq = -2.0*math.pi*19010/audio_rate;
133 self.stereo_carrier_pll_recovery = gr.pll_refout_cc(alpha,beta,max_freq,min_freq);
134 #self.stereo_carrier_pll_recovery.squelch_enable(False) #pll_refout does not have squelch yet, so disabled for now
137 # set up mixer (multiplier) to get the L-R signal at baseband
139 self.stereo_basebander = gr.multiply_cc();
141 # pick off the real component of the basebanded L-R signal. The imaginary SHOULD be zero
143 self.LmR_real = gr.complex_to_real();
144 self.Make_Left = gr.add_ff();
145 self.Make_Right = gr.sub_ff();
147 self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs)
152 # send the real signal to complex filter to pick off the carrier and then to one side of a multiplier
153 self.connect (self, self.fm_demod,self.stereo_carrier_filter,self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,0))
154 # send the already filtered carrier to the otherside of the carrier
155 self.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1))
156 # the resulting signal from this multiplier is the carrier with correct phase but at -38000 Hz.
158 # send the new carrier to one side of the mixer (multiplier)
159 self.connect (self.stereo_carrier_generator, (self.stereo_basebander,0))
160 # send the demphasized audio to the DSBSC pick off filter, the complex
161 # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier
162 self.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1))
163 # the result is BASEBANDED DSBSC with phase zero!
165 # Pick off the real part since the imaginary is theoretically zero and then to one side of a summer
166 self.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0))
167 #take the same real part of the DSBSC baseband signal and send it to negative side of a subtracter
168 self.connect (self.LmR_real,(self.Make_Right,1))
170 # Make rds carrier by taking the squared pilot tone and multiplying by pilot tone
171 self.connect (self.stereo_basebander,(self.rds_carrier_generator,0))
172 self.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1))
173 # take signal, filter off rds, send into mixer 0 channel
174 self.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0))
175 # take rds_carrier_generator output and send into mixer 1 channel
176 self.connect (self.rds_carrier_generator,(self.rds_signal_generator,1))
177 # send basebanded rds signal and send into "processor" which for now is a null sink
178 self.connect (self.rds_signal_generator,self_rds_signal_processor)
182 # pick off the audio, L+R that is what we used to have and send it to the summer
183 self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1))
184 # take the picked off L+R audio and send it to the PLUS side of the subtractor
185 self.connect(self.audio_filter,(self.Make_Right, 0))
186 # The result of Make_Left gets (L+R) + (L-R) and results in 2*L
187 # The result of Make_Right gets (L+R) - (L-R) and results in 2*R
188 self.connect(self.Make_Left , self.deemph_Left, (self, 0))
189 self.connect(self.Make_Right, self.deemph_Right, (self, 1))
190 # NOTE: mono support will require variable number of outputs in hier_block2s
191 # See ticket:174 in Trac database
193 # self.connect (self.fm_demod, self.audio_filter, self)