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.
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_block):
40 FM Deemphasis IIR filter.
42 def __init__(self, fg, fs, tau=75e-6):
45 @type fg: gr.flow_graph
46 @param fs: sampling frequency in Hz
48 @param tau: Time constant in seconds (75us in US, 50us in EUR)
52 w_pp = math.tan (w_p / (fs * 2)) # prewarped analog freq
54 a1 = (w_pp - 1)/(w_pp + 1)
62 print "btaps =", btaps
63 print "ataps =", ataps
65 plot1 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True)
67 deemph = gr.iir_filter_ffd(btaps, ataps)
68 gr.hier_block.__init__(self, fg, deemph, deemph)
75 # I think this is the right transfer function.
78 # This fine ASCII rendition is based on Figure 5-15
79 # in "Digital and Analog Communication Systems", Leon W. Couch II
85 # o------+ +-----+--------o
93 # o--------------------------+--------o
95 # f1 = 1/(2*pi*t1) = 1/(2*pi*R1*C)
98 # f2 = ------- = ------------
99 # 2*pi*t2 2*pi*R1*R2*C
101 # t1 is 75us in US, 50us in EUR
102 # f2 should be higher than our audio bandwidth.
105 # The Bode plot looks like this:
110 # / <-- slope = 20dB/decade
115 # We prewarp and use the bilinear z-transform to get our IIR coefficients.
116 # See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis
119 class fm_preemph(gr.hier_block):
121 FM Preemphasis IIR filter.
123 def __init__(self, fg, fs, tau=75e-6):
125 @param fg: flow graph
126 @type fg: gr.flow_graph
127 @param fs: sampling frequency in Hz
129 @param tau: Time constant in seconds (75us in US, 50us in EUR)
133 # FIXME make this compute the right answer
139 print "btaps =", btaps
140 print "ataps =", ataps
142 plot2 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True)
144 preemph = gr.iir_filter_ffd(btaps, ataps)
145 gr.hier_block.__init__(self, fg, preemph, preemph)