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.blksimpl.fm_emph import fm_deemph
26 class wfm_rcv_pll(gr.hier_block):
27 def __init__ (self, fg, 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 fg: flow graph.
36 @param demod_rate: input sample rate of complex baseband input.
37 @type demod_rate: float
38 @param audio_decimation: how much to decimate demod_rate to get to audio.
39 @type audio_decimation: integer
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*100e3/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 (fg, audio_rate)
58 self.deemph_Right = fm_deemph (fg, 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.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs)
116 self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs)
123 self.rds_carrier_generator = gr.multiply_cc();
124 self.rds_signal_generator = gr.multiply_cc();
125 self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex);
129 alpha = 5 * 0.25 * math.pi / (audio_rate)
130 beta = alpha * alpha / 4.0
131 max_freq = -2.0*math.pi*18990/audio_rate;
132 min_freq = -2.0*math.pi*19010/audio_rate;
134 self.stereo_carrier_pll_recovery = gr.pll_refout_cc(alpha,beta,max_freq,min_freq);
135 #self.stereo_carrier_pll_recovery.squelch_enable(False) #pll_refout does not have squelch yet, so disabled for now
138 # set up mixer (multiplier) to get the L-R signal at baseband
140 self.stereo_basebander = gr.multiply_cc();
142 # pick off the real component of the basebanded L-R signal. The imaginary SHOULD be zero
144 self.LmR_real = gr.complex_to_real();
145 self.Make_Left = gr.add_ff();
146 self.Make_Right = gr.sub_ff();
148 self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs)
153 # send the real signal to complex filter to pick off the carrier and then to one side of a multiplier
154 fg.connect (self.fm_demod,self.stereo_carrier_filter,self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,0))
155 # send the already filtered carrier to the otherside of the carrier
156 fg.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1))
157 # the resulting signal from this multiplier is the carrier with correct phase but at -38000 Hz.
159 # send the new carrier to one side of the mixer (multiplier)
160 fg.connect (self.stereo_carrier_generator, (self.stereo_basebander,0))
161 # send the demphasized audio to the DSBSC pick off filter, the complex
162 # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier
163 fg.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1))
164 # the result is BASEBANDED DSBSC with phase zero!
166 # Pick off the real part since the imaginary is theoretically zero and then to one side of a summer
167 fg.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0))
168 #take the same real part of the DSBSC baseband signal and send it to negative side of a subtracter
169 fg.connect (self.LmR_real,(self.Make_Right,1))
171 # Make rds carrier by taking the squared pilot tone and multiplying by pilot tone
172 fg.connect (self.stereo_basebander,(self.rds_carrier_generator,0))
173 fg.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1))
174 # take signal, filter off rds, send into mixer 0 channel
175 fg.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0))
176 # take rds_carrier_generator output and send into mixer 1 channel
177 fg.connect (self.rds_carrier_generator,(self.rds_signal_generator,1))
178 # send basebanded rds signal and send into "processor" which for now is a null sink
179 fg.connect (self.rds_signal_generator,self_rds_signal_processor)
183 # pick off the audio, L+R that is what we used to have and send it to the summer
184 fg.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1))
185 # take the picked off L+R audio and send it to the PLUS side of the subtractor
186 fg.connect(self.audio_filter,(self.Make_Right, 0))
187 # The result of Make_Left gets (L+R) + (L-R) and results in 2*L
188 # The result of Make_Right gets (L+R) - (L-R) and results in 2*R
191 # kludge the signals into a stereo channel
192 kludge = gr.kludge_copy(gr.sizeof_float)
193 fg.connect(self.Make_Left , self.deemph_Left, (kludge, 0))
194 fg.connect(self.Make_Right, self.deemph_Right, (kludge, 1))
196 #send it to the audio system
197 gr.hier_block.__init__(self,
199 self.fm_demod, # head of the pipeline
200 kludge) # tail of the pipeline
202 fg.connect (self.fm_demod, self.audio_filter)
203 gr.hier_block.__init__(self,
205 self.fm_demod, # head of the pipeline
206 self.audio_filter) # tail of the pipeline