2 # Copyright 2005,2007 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
31 # tau is the RC time constant.
32 # critical frequency: w_p = 1/tau
34 # We prewarp and use the bilinear z-transform to get our IIR coefficients.
35 # See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis
38 class fm_deemph(gr.hier_block2):
40 FM Deemphasis IIR filter.
44 def __init__(self, fs, tau=75e-6):
46 @param fs: sampling frequency in Hz
48 @param tau: Time constant in seconds (75us in US, 50us in EUR)
51 gr.hier_block2.__init__(self, "fm_deemph",
52 gr.io_signature(1, 1, gr.sizeof_float), # Input signature
53 gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
56 w_pp = math.tan (w_p / (fs * 2)) # prewarped analog freq
58 a1 = (w_pp - 1)/(w_pp + 1)
66 print "btaps =", btaps
67 print "ataps =", ataps
69 plot1 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True)
71 deemph = gr.iir_filter_ffd(btaps, ataps)
72 self.connect(self, deemph, self)
79 # I think this is the right transfer function.
82 # This fine ASCII rendition is based on Figure 5-15
83 # in "Digital and Analog Communication Systems", Leon W. Couch II
89 # o------+ +-----+--------o
97 # o--------------------------+--------o
99 # f1 = 1/(2*pi*t1) = 1/(2*pi*R1*C)
102 # f2 = ------- = ------------
103 # 2*pi*t2 2*pi*R1*R2*C
105 # t1 is 75us in US, 50us in EUR
106 # f2 should be higher than our audio bandwidth.
109 # The Bode plot looks like this:
114 # / <-- slope = 20dB/decade
119 # We prewarp and use the bilinear z-transform to get our IIR coefficients.
120 # See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis
123 class fm_preemph(gr.hier_block2):
125 FM Preemphasis IIR filter.
127 def __init__(self, fs, tau=75e-6):
129 @param fs: sampling frequency in Hz
131 @param tau: Time constant in seconds (75us in US, 50us in EUR)
135 gr.hier_block2.__init__(self, "fm_deemph",
136 gr.io_signature(1, 1, gr.sizeof_float), # Input signature
137 gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
139 # FIXME make this compute the right answer
145 print "btaps =", btaps
146 print "ataps =", ataps
148 plot2 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True)
150 preemph = gr.iir_filter_ffd(btaps, ataps)
151 self.connect(self, preemph, self)