1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#
# Copyright 2005,2007,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, filter
import math
#
# 1
# H(s) = -------
# 1 + s
#
# tau is the RC time constant.
# critical frequency: w_p = 1/tau
#
# We prewarp and use the bilinear z-transform to get our IIR coefficients.
# See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis
#
class fm_deemph(gr.hier_block2):
"""
FM Deemphasis IIR filter.
"""
def __init__(self, fs, tau=75e-6):
"""
Args:
fs: sampling frequency in Hz (float)
tau: Time constant in seconds (75us in US, 50us in EUR) (float)
"""
gr.hier_block2.__init__(self, "fm_deemph",
gr.io_signature(1, 1, gr.sizeof_float), # Input signature
gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
w_p = 1/tau
w_pp = math.tan(w_p / (fs * 2)) # prewarped analog freq
a1 = (w_pp - 1)/(w_pp + 1)
b0 = w_pp/(1 + w_pp)
b1 = b0
btaps = [b0, b1]
ataps = [1, a1]
if 0:
print "btaps =", btaps
print "ataps =", ataps
global plot1
plot1 = gru.gnuplot_freqz(gru.freqz(btaps, ataps), fs, True)
deemph = filter.iir_filter_ffd(btaps, ataps)
self.connect(self, deemph, self)
#
# 1 + s*t1
# H(s) = ----------
# 1 + s*t2
#
# I think this is the right transfer function.
#
#
# This fine ASCII rendition is based on Figure 5-15
# in "Digital and Analog Communication Systems", Leon W. Couch II
#
#
# R1
# +-----||------+
# | |
# o------+ +-----+--------o
# | C1 | |
# +----/\/\/\/--+ \
# /
# \ R2
# /
# \
# |
# o--------------------------+--------o
#
# f1 = 1/(2*pi*t1) = 1/(2*pi*R1*C)
#
# 1 R1 + R2
# f2 = ------- = ------------
# 2*pi*t2 2*pi*R1*R2*C
#
# t1 is 75us in US, 50us in EUR
# f2 should be higher than our audio bandwidth.
#
#
# The Bode plot looks like this:
#
#
# /----------------
# /
# / <-- slope = 20dB/decade
# /
# -------------/
# f1 f2
#
# We prewarp and use the bilinear z-transform to get our IIR coefficients.
# See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis
#
class fm_preemph(gr.hier_block2):
"""
FM Preemphasis IIR filter.
"""
def __init__(self, fs, tau=75e-6):
"""
Args:
fs: sampling frequency in Hz (float)
tau: Time constant in seconds (75us in US, 50us in EUR) (float)
"""
gr.hier_block2.__init__(self, "fm_deemph",
gr.io_signature(1, 1, gr.sizeof_float), # Input signature
gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
# FIXME make this compute the right answer
btaps = [1]
ataps = [1]
if 0:
print "btaps =", btaps
print "ataps =", ataps
global plot2
plot2 = gru.gnuplot_freqz(gru.freqz(btaps, ataps), fs, True)
preemph = filter.iir_filter_ffd(btaps, ataps)
self.connect(self, preemph, self)
|