Professional Documents
Culture Documents
Specifications Specifications
Typical magnitude response H a ( j) of an In the passband, defined by 0 p , we
analog lowpass filter may be given as require
indicated below 1 p H a ( j ) 1 + p , p
i.e., H a ( j) approximates unity within an
error of p
In the stopband, defined by s < , we
require
H a ( j ) s , s <
i.e., H a ( j) approximates zero within an
1 2 error of s
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1
Butterworth Approximation
Butterworth Approximation
The magnitude-square response of an N-th
order analog lowpass Butterworth filter
is given by Gain in dB is G () = 10 log10 H a ( j) 2
1
H a ( j ) =
2
1 + ( / c ) 2 N As G (0) = 0 and
First 2 N 1 derivatives of H a ( j) at = 0
2
G (c ) = 10 log10 (0.5) = 3.0103 3 dB
are equal to zero c is called the 3-dB cutoff frequency
The Butterworth lowpass filter thus is said
to have a maximally-flat magnitude at = 0
7 8
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
9 10
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
2
Butterworth Approximation Butterworth Approximation
Example - Determine the lowest order of a
Transfer function of an analog Butterworth Butterworth lowpass filter with a 1-dB cutoff
frequency at 1 kHz and a minimum attenuation of 40
lowpass filter is given by dB at 5 kHz
cN cN
H a ( s) = C = N = Now
DN ( s ) s + lN=01d s l lN=1 ( s pl )
l 10 log10 1 2 = 1
1 +
where which yields 2 = 0.25895
pl = c e j[ ( N + 2l1) / 2 N ] , 1 l N and
Denominator DN (s ) is known as the 10 log10 12 = 40
Butterworth polynomial of order N A
which yields A2 = 10,000
13 14
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1
N=2
N=3
Solving the above we get
cosh 1 ( A2 1 / ) cosh 1 (1 / k1 )
0.8 N=8
Magnitude
0.6 N= =
0.4 cosh 1 ( s / p ) cosh 1 (1 / k )
0.2
Order N is chosen as the nearest integer
0
0 1
2 3
greater than or equal to the above value
17 18
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
3
Chebyshev Approximation Chebyshev Approximation
The magnitude-square response of an N-th Typical magnitude response plots of the
order analog lowpass Type 2 Chebyshev analog lowpass Type 2 Chebyshev filter are
(also called inverse Chebyshev) filter is shown below
given by Type 2 Chebyshev Filter
1 N=3
H a ( j ) =
2 1 N=5
T ( / p )
2 0.8 N=7
Magnitude
1+ 2 N s
0.6
TN ( s / ) 0.4
0.2
where TN () is the Chebyshev polynomial 0
0 1 2 3
of order N
19 20
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
4
Analog Lowpass Filter Design
Elliptic Approximation Example - Design an elliptic lowpass filter
of lowest order with a 1-dB cutoff
Typical magnitude response plots with p = 1 frequency at 1 kHz and a minimum
are shown below attenuation of 40 dB at 5 kHz
Elliptic Filter
N=3
Code fragments used
1 N=4 [N, Wn] = ellipord(Wp, Ws, Rp, Rs, s);
0.8
Magnitude
-20
Step 2 - Design the prototype analog
-40
lowpass filter
-60 Step 3 - Determine the transfer function HD (s )
0 2000 4000 6000
Frequency, Hz of desired analog filter by applying the
inverse frequency transformation to H LP (s)
27 28
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
5
Analog Highpass Filter Design
Analog Highpass Filter Design
Example - Design an analog Butterworth
p p highpass filter with the specifications:
= F p = 4 kHz, Fs = 1 kHz, p = 0.1 dB,
s = 40 dB
Stopband s p p s Stopband Choose p = 1
0
Lowpass
Passband Then 2F p F p 4000
s = = = =4
Passband Stopband Passband 2Fs Fs 1000
p
s 0 s p
Highpass Analog lowpass filter specifications: p = 1,
31 32
s = 4 , p = 0.1 dB, s = 40 dB
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
Gain, dB
-40 -40
desired bandpass filter H BP (s)
-60 -60
-80 -80
0 2 4 6 8 10 0 2 4 6 8 10
33 Frequency, kHz 34
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
6
Analog Bandpass Filter Analog Bandpass Filter
Design Design
Stopband edge frequency s is mapped Case 1: p1
p2 >
s1
s2
s1 and
into m s 2 , lower and upper
To make p1 p 2 = s1
s 2 we can either
stopband edge frequencies
increase any one of the stopband edges or
Also, decrease any one of the passband edges as
o2 =
p1
p2 = s1
s2 shown below
If bandedge frequencies do not satisfy the Passband
above condition, then one of the frequencies
needs to be changed to a new value so that Stopband Stopband
the condition is satisfied
s1
p1
p2
s2
37 38
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
7
Analog Bandpass Filter Analog Bandpass Filter
Design Design
Example - Design an analog elliptic
Note: The condition o2 =
p1
p2 =
s1
s2 bandpass filter with the specifications:
can also be satisfied by increasing p1 F p1 = 4 kHz, F p 2 = 7 kHz, Fs1 = 3 kHz
which is not acceptable as the passband is Fs 2 = 8 kHz, p = 1 dB, s = 22 dB
reduced from the desired value
Alternately, the condition can be satisfied Now F p1F p 2 = 28 106 and Fs1Fs 2 = 24 106
by decreasing s1 which is not acceptable
Since F p1F p 2 > Fs1Fs 2 we choose
as the lower stopband is reduced from the
desired value F p1 = Fs1Fs 2 / F p 2 = 3.571428 kHz
43 44
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
s = 1.4 , p = 1 dB, s = 22 dB
Gain, dB
Gain, dB
-20
-20
-40 -40
-60 -60
45 46 0 2 4 6 8 0 5 10 15
Copyright 2005, S. K. Mitra Frequency, kHz 2005, S. K. Mitra
Copyright
8
Analog Bandstop Filter Design Analog Bandstop Filter Design
Passband edge frequency p is mapped Also,
into m
p1 and
p 2 , lower and upper
o2 =
p1
p2 =
s1
s2
passband edge frequencies If bandedge frequencies do not satisfy the
Stopband s p p s Stopband above condition, then one of the frequencies
Lowpass
0
Passband
needs to be changed to a new value so that
the condition is satisfied
Passband Stopband Passband Stopband Passband
Bandpass
p2
o p10
p1 o p2
s2
s1 s1
s2
49 50
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
Passband
No change in passbands and
Passband
shorter rightmost transition band
Stopband
51
p1
s1
s2
p2 52
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
9
Analog Bandstop Filter Design Analog Bandstop Filter Design
Note: The condition o2 =
p1
p2 =
s1
s2
(1) Increase p1 to
s1
s2 /
p1 can also be satisfied by increasing p2
larger passband and shorter which is not acceptable as the high-
leftmost transition band frequency passband is decreased from the
desired value
(2) Decrease s1 to
p1
p2 / s1
Alternately, the condition can be satisfied
No change in passbands and by decreasing s 2 which is not acceptable
shorter leftmost transition band as the stopband is decreased
55 56
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
10
Digital Filter Design Digital Filter Specifications
Usually, either the magnitude and/or the
Objective - Determination of a realizable
phase (delay) response is specified for the
transfer function G(z) approximating a
design of digital filter for most applications
given frequency response specification is an
important step in the development of a In some situations, the unit sample response
digital filter or the step response may be specified
If an IIR filter is desired, G(z) should be a In most practical applications, the problem
stable real rational function of interest is the development of a realizable
approximation to a given magnitude
Digital filter design is the process of
response specification
deriving the transfer function G(z)
1 2
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1
Digital Filter Specifications
Digital Filter Specifications
p - passband edge frequency
s - stopband edge frequency Specifications are often given in terms of
j
p - peak ripple value in the passband loss function A () = 20 log10 G (e ) in
s - peak ripple value in the stopband dB
Since G (e j ) is a periodic function of , Peak passband ripple
and G (e j ) of a real-coefficient digital p = 20 log10 (1 p ) dB
filter is an even function of Minimum stopband attenuation
As a result, filter specifications are given s = 20 log10 ( s ) dB
only for the frequency range 0
7 8
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
2
Selection of Filter Type
Digital Filter Specifications The transfer function H(z) meeting the
frequency response specifications should be
Example - Let Fp = 7 kHz, Fs = 3 kHz, and a causal transfer function
FT = 25 kHz For IIR digital filter design, the IIR transfer
Then function is a real rational function of z 1:
2(7 103 ) p0 + p1z 1 + p2 z 2 + L + pM z M
p = = 0.56 H ( z) = , MN
25 103 d 0 + d1z 1 + d 2 z 2 + L + d N z N
2(3 103 )
s = = 0.24 H(z) must be a stable transfer function and
25 103 must be of lowest order N for reduced
13 14 computational complexity
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
3
Digital Filter Design: Digital Filter Design:
Basic Approaches Basic Approaches
An analog transfer function to be denoted as Basic idea behind the conversion of H a (s )
into G ( z ) is to apply a mapping from the
P ( s)
H a ( s) = a s-domain to the z-domain so that essential
Da ( s ) properties of the analog frequency response
where the subscript a specifically are preserved
indicates the analog domain Thus mapping function should be such that
A digital transfer function derived from H a ( s ) Imaginary ( j ) axis in the s-plane be
shall be denoted as mapped onto the unit circle of the z-plane
P( z )
G( z) = A stable analog transfer function be mapped
D( z ) into a stable digital transfer function
19 20
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
4
Bilinear Transformation
Inverse bilinear transformation for T = 2 is Bilinear Transformation
z = 1+ s
1 s Mapping of s-plane into the z-plane
For s = o + jo
(1 + o ) + jo 2 (1 + o ) + o
2 2
z= z =
(1 o ) jo (1 o ) 2 + o2
Thus, o = 0 z = 1
o < 0 z < 1
o > 0 z > 1
25 26
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
5
IIR Digital Filter Design Using
Bilinear Transformation IIR Digital Filter Design Using
Example - Consider Bilinear Transformation
c Rearranging terms we get
H a ( s) =
s + c 1
G ( z ) = 1 1 + z 1
Applying bilinear transformation to the above 2 1 z
we get the transfer function of a first-order where
digital lowpass Butterworth filter
1 c 1 tan(c / 2)
= =
c (1 + z 1 ) 1 + c 1 + tan(c / 2)
G ( z ) = H a ( s ) s =1 z 1 =
1+ z 1
(1 z 1 ) + c (1 + z 1 )
31 32
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
IIR Digital Filter Design Using IIR Digital Filter Design Using
Bilinear Transformation Bilinear Transformation
Example - Consider the second-order analog Then G ( z ) = H a ( s ) s =1 z 1
s 2 + o2 (1 + o ) 2(1 o ) z 1 + (1 + o2 ) z 2
2 2
H a ( s) = 2 =
s + B s + o2 (1 + o2 + B) 2(1 o2 ) z 1 + (1 + o2 B ) z 2
1 2
for which H a ( jo ) = 0 1+ 1 2 z + z
=
2 1 2 (1 + ) z 1 + z 2
H a ( j 0) = H a ( j) = 1
o is called the notch frequency 1 + o2 B 1 tan( Bw / 2)
where = =
If H a ( j 2 ) = H a ( j1 ) = 1 / 2 then 1 + o2 + B 1 + tan( Bw / 2)
B = 2 1 is the 3-dB notch bandwidth 1 o2
33 34 = = cos o
Copyright 2005, S. K. Mitra 1 + o2 Copyright 2005, S. K. Mitra
IIR Digital Filter Design Using IIR Digital Filter Design Using
Bilinear Transformation Bilinear Transformation
Example - Design a 2nd-order digital notch Thus
filter operating at a sampling rate of 400 Hz 0.954965 1.1226287 z 1 + 0.954965 z 2
with a notch frequency at 60 Hz, 3-dB notch G( z) =
bandwidth of 6 Hz 1 1.1226287 z 1 + 0.90993 z 2
The gain and phase responses are shown below
Thus o = 2(60 / 400) = 0.3 2
-10
Gain, dB
= 0.587785 -40
0 50 100 150 200
-2
0 50 100 150 200
35 36 Frequency, Hz Frequency, Hz
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
6
IIR Lowpass Digital Filter Design IIR Lowpass Digital Filter Design
Using Bilinear Transformation Using Bilinear Transformation
Example - Design a lowpass Butterworth Prewarping we get
digital filter with p = 0.25, s = 0.55 , p = tan( p / 2) = tan(0.25 / 2) = 0.4142136
p 0.5 dB, and s 15 dB s = tan(s / 2) = tan(0.55 / 2) = 1.1708496
Thus The inverse transition ratio is
2 = 0.1220185 A2 = 31.622777 1 s
= = 2.8266809
If G (e j 0 ) = 1 this implies k p
20 log10 G (e j 0.25 ) 0.5 The inverse discrimination ratio is
20 log10 G (e j 0.55 ) 15 1 A2 1
= = 15.841979
k1
37 38
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
IIR Lowpass Digital Filter Design IIR Lowpass Digital Filter Design
Using Bilinear Transformation Using Bilinear Transformation
We then get
log10 (1 / k1 ) c = 1.419915 ( p ) = 0.588148
Thus N= = 2.6586997
log10 (1 / k )
3rd-order lowpass Butterworth transfer
We choose N = 3 function for c = 1 is
To determine c we use Han ( s ) =
1
( s + 1)( s 2 + s + 1)
2 1 1
H a ( j p ) = = Denormalizing to get c = 0.588148 we
1 + ( p / c ) 2N
1 + 2
arrive at
Ha ( s ) = Han
s
39 40 0.588148
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
0.8 -10
(2) Convert frequency specifications of H D (s )
into that of prototype analog lowpass filter
Magnitude
Gain, dB
0.6
-20
0.4 H LP (s )
-30
0.2
0 -40
(3) Design analog lowpass filter H LP (s )
41 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 42
/ /
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
7
Design of IIR Highpass,
Highpass, Bandpass,
Bandpass, Design of IIR Highpass,
Highpass, Bandpass,
Bandpass,
and Bandstop Digital Filters and Bandstop Digital Filters
(4) Convert H LP (s ) into H D (s ) using Second Approach -
inverse frequency transformation used in (1) Prewarp digital frequency specifications
Step 2 of desired digital filter GD (z ) to arrive at
(5) Design desired digital filter GD (z ) by frequency specifications of analog filter H D (s )
applying bilinear transformation to H D (s ) of same type
(2) Convert frequency specifications of H D (s )
into that of prototype analog lowpass filter
H LP (s )
43 44
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
IIR Highpass Digital Filter Design IIR Highpass Digital Filter Design
Prewarping these frequencies we get MATLAB code fragments used for the design
p = tan( p / 2) = 1.9626105
[N, Wn] = cheb1ord(1, 1.9626105, 1, 32, s)
s = tan(s / 2) = 1.0 [B, A] = cheby1(N, 1, Wn, s);
For the prototype analog lowpass filter choose [BT, AT] = lp2hp(B, A, 1.9626105);
p =1 [num, den] = bilinear(BT, AT, 0.5);
Using = p p we get s = 1.962105 0
-10
-20
-30
s = 1.926105 , p = 1dB, s = 32 dB -40
-50
0 0.2 0.4 0.6 0.8 1
47 48 /
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
8
IIR Bandpass Digital Filter Design IIR Bandpass Digital Filter Design
Design of a Butterworth IIR digital bandpass Width of passband Bw = p2 p1 = 0.777771
filter
o2 = p1 p 2 = 1.393733
Specifications: p1 = 0.45 , p 2 = 0.65 ,
s1 s 2 = 1.23010325 o2
s1 = 0.3, s 2 = 0.75, p = 1 dB, s = 40 dB
We therefore modify s1 so that
s1and
Prewarping we get s2
exhibit geometric symmetry with
p1 = tan( p1 / 2) = 0.8540807 respect to o2
p 2 = tan( p 2 / 2) = 1.6318517 We set s1 = 0.5773031
s1 = tan(s1 / 2) = 0.5095254 For the prototype analog lowpass filter we
choose p = 1
s 2 = tan(s 2 / 2) = 2.41421356
49 50
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
IIR Bandpass Digital Filter Design IIR Bandpass Digital Filter Design
MATLAB code fragments used for the design
Using = p o we get
2 2
Bw [N, Wn] = buttord(1, 2.3617627, 1, 40, s)
[B, A] = butter(N, Wn, s);
1.393733 0.3332788 [BT, AT] = lp2bp(B, A, 1.1805647, 0.777771);
s = = 2.3617627
0.5773031 0.777771 [num, den] = bilinear(BT, AT, 0.5);
Specifications of prototype analog 0
p = 1 , s = 2.3617627 , p = 1 dB,
-20
-30
s = 40 dB -40
-50
0 0.2 0.4 0.6 0.8 1
51 52 /
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
IIR Bandstop Digital Filter Design IIR Bandstop Digital Filter Design
Design of an elliptic IIR digital bandstop filter We therefore modify p1so that
p1and
p2
Specifications: s1 = 0.45 , s 2 = 0.65 , exhibit geometric symmetry with respect to
p1 = 0.3, p 2 = 0.75 , p = 1 dB, s = 40 dB o2
Prewarping we get We set p1 = 0.577303
s1 = 0.8540806, s 2 = 1.6318517, For the prototype analog lowpass filter we
p1 = 0.5095254,
p 2 = 2.4142136 choose s = 1
B
Width of stopband Bw = s2
s1 = 0.777771 Using = s 2 w 2 we get
o
o2 = s 2
s1 = 1.393733 0.5095254 0.777771
p = = 0.4234126
p 2 p1 = 1.230103
o2 1.393733 0.3332787
53 54
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
9
IIR Bandstop Digital Filter Design
MATLAB code fragments used for the design
[N, Wn] = ellipord(0.4234126, 1, 1, 40, s);
[B, A] = ellip(N, 1, 40, Wn, s);
[BT, AT] = lp2bs(B, A, 1.1805647, 0.777771);
[num, den] = bilinear(BT, AT, 0.5);
0
-10
Gain, dB
-20
-30
-40
-50
0 0.2 0.4 0.6 0.8 1
55 /
Copyright 2005, S. K. Mitra
10
Least Integral-Squared Error
Least Integral-Squared Error
Design of FIR Filters
Let H d (e j ) denote the desired frequency
Design of FIR Filters
response In general, H d (e j ) is piecewise constant
Since H d (e j ) is a periodic function of with sharp transitions between bands
with a period 2, it can be expressed as a In which case, {hd [n]} is of infinite length
Fourier series and noncausal
H d (e j ) = hd [n]e jn Objective - Find a finite-duration {ht [n]}
where n = of length 2M+1 whose DTFT H t (e j )
1
j jn
approximates the desired DTFT H d (e j ) in
hd [n] = H d (e )e d, n some sense
2
1 2
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
h[n] = ht [n M ] c 0 c
The causal FIR filter h[n] has the same Ideal highpass filter -
magnitude response as ht [n] and its phase HHP (e j )
1 c , n=0
response has a linear phase shift of M
radians with respect to that of ht [n]
1
hHP [n] =
sin( n)
nc , n 0
5 6
c 0 c
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1
Impulse Responses of Ideal
Impulse Responses of Ideal
Filters
Filters
Ideal bandstop filter -
Ideal bandpass filter - HBS (e j )
HBP (e j )
1
1
c2 c1 c1 c2
c2 c1 c1 c2
j, < < 0
H HT (e j ) =
A5
A1
A4
k 1 k , j , 0 < <
A2
A3
0 1 2 3 4 k = 1, 2,K, L
0, for n even
L sin( n) hHT [n] =
hML [n] = ( Al Al +1) nL 2/ n, for n odd
l =1
9 10
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
0, n=0 1
N = 60
Magnitude
hDIF [ n] = cos n
n , n 0 0.5
0
0 0.2 0.4 0.6 0.8 1
11 12 /
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
2
Gibbs Phenomenon Gibbs Phenomenon
As can be seen, as the length of the lowpass Gibbs phenomenon can be explained by
filter is increased, the number of ripples in treating the truncation operation as an
both passband and stopband increases, with windowing operation:
a corresponding decrease in the ripple ht [n] = hd [n] w[ n]
widths In the frequency domain
Height of the largest ripples remain the
H t ( e j ) = j j ( )
1
same independent of length 2 H d (e ) ( e ) d
where H t (e j ) and (e j ) are the DTFTs
Similar oscillatory behavior observed in the
magnitude responses of the truncated
of ht [n] and w[n] , respectively
13 versions of other types of ideal filters 14
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
Gibbs Phenomenon
Gibbs Phenomenon
Thus H t (e j ) is obtained by a periodic
continuous convolution of H d (e j ) with If (e j ) is a very narrow pulse centered at
(e j ) = 0 (ideally a delta function) compared to
variations in H d (e j ), then H t (e j ) will
approximate H d (e j ) very closely
Length 2M+1 of w[n] should be very large
On the other hand, length 2M+1 of ht [n]
should be as small as possible to reduce
computational complexity
15 16
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
wR [n] =
30
0, otherwise 20
M = 10 main lobe
Amplitude
3
Gibbs Phenomenon Gibbs Phenomenon
Main lobe of R (e j ) characterized by its Rectangular window has an abrupt transition
width 4 /( 2 M + 1) defined by first zero to zero outside the range M n M , which
crossings on both sides of = 0
results in Gibbs phenomenon in H t (e j )
As M increases, width of main lobe
decreases as desired Gibbs phenomenon can be reduced either:
Area under each lobe remains constant (1) Using a window that tapers smoothly to
while width of each lobe decreases with an zero at each end, or
increase in M (2) Providing a smooth transition from
Ripples in H t (e j ) around the point of passband to stopband in the magnitude
discontinuity occur more closely but with specifications
no decrease in amplitude as M increases
19 20
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
4
Fixed Window Functions Fixed Window Functions
Using a tapered window causes the height Plots of magnitudes of the DTFTs of these
of the sidelobes to diminish, with a windows for M = 25 are shown below:
Rectangular window Hann window
corresponding increase in the main lobe 0 0
Gain, dB
Gain, dB
-60 -60
Hann:
w[n] = 0.5 + 0.5 cos( 2 n ), M n M
-80 -80
-100
2M + 1
-100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
/ /
Hamming window Blackman window
Hamming:
w[n] = 0.54 + 0.46 cos( 2 n ), M n M
0 0
-20 -20
2M + 1 -40 -40
Gain, dB
Gain, dB
Blackman: -60 -60
1 2M + 1 2M + 1 2
-100
0 0.2 0.4
/
0.6 0.8 1
-100
0 0.2 0.4
/
0.6 0.8 1
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
Observe H t (e j (c + ) ) + H t (e j (c ) ) 1
Width of transition band
Thus, H t (e jc ) 0.5
= s p < ML
Passband and stopband ripples are the same
5 6
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1
Fixed Window Functions Fixed Window Functions
To ensure a fast transition from passband to In the case of rectangular, Hann, Hamming,
stopband, window should have a very small and Blackman windows, the value of ripple
main lobe width does not depend on filter length or cutoff
To reduce the passband and stopband ripple frequency c , and is essentially constant
, the area under the sidelobes should be In addition,
very small c
M
Unfortunately, these two requirements are where c is a constant for most practical
contradictory purposes
7 8
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
-50 -50
associated with an increase in the width of
-100 -100 the transition band
0 0.2 0.4
/
0.6 0.8 1 0 0.2 0.4
/
0.6 0.8 1
A decrease in the sidelobe amplitude results
Lowpass Filter Designed Using Blackman window
0
in an increase in the stopband attenuation
Gain, dB
-50
-100
2
Adjustable Window Functions Adjustable Window Functions
Dolph-Chebyshev Window - Dolph-Chebyshev window can be designed
w[n] = 1 [1 + 2 Tk ( cos k ) cos 2nk ],
M with any specified relative sidelobe level
2M + 1 k =1 2M + 1 2M + 1 while the main lobe width adjusted by
M nM choosing length appropriately
where amplitude of sidelobe
= Filter order is estimated using
main lobe amplitude 2.056 s 16.4
= cosh( 1 cosh 1 1 ) N=
2M 2.85( )
and
cos(l cos 1 x ), x 1 where is the normalized transition
Tl ( x) = 1 bandwidth, e.g, for a lowpass filter
cosh(l cosh x), x > 1 = s p
13 14
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
-40
smallest main lobe width compared to other
-60 windows resulting in filters with the
-80
0 0.2 0.4 0.6 0.8 1
smallest transition band
/
15 16
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
3
FIR Filter Design Example FIR Filter Design Example
Specifications: p = 0.3 , s = 0.5 , sin(0.4 n)
Hence ht [ n] = n w[n], 12 n 12
s = 40 dB
where w[n] is the n-th coefficient of a
Thus c = ( p + s ) / 2 = 0.4
length-25 Kaiser window with = 3.3953
s = 10 s / 20 = 0.01 Kaiser Window Lowpass filter designed with Kaiser window
-20 -20
32
N= = 22.2886
Gain, dB
Gain, dB
2.285(0.2)
-40 -40
-60 -60
19 20
Copyright 2005, S. K. Mitra Copyright 2005, S. K. Mitra
1 P = 1, N = 40
P = 2, N = 60
0.8
Magnitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1
/
23
Copyright 2005, S. K. Mitra
4
Greg Berchin
[dsp TIPS&TRICKS]
Y
ou have just been assigned taining poles and zeros (infinite response least-squares sense, as close as possible
to a new project at work, filters), only zeros (finite response fil- to satisfying all three equations. The
in which the objective is ters), or only poles (autoregressive net- solution is then given by
to replace an existing ana- works). The algorithm uses nothing
5 2 7
log system with a func- more esoteric than basic linear algebra. 6 4 x
= 9 or
tionally equivalent digital system. Your Before we can see how the technique y
1 1 5
job is to design a digital filter that works, we need to review some basic lin-
matches the magnitude and phase ear algebra and matrix concepts.
1
response of the existing systems analog 5 2 T 5 2
x
filter over a broad frequency range. You BACKGROUND 6 4 6 4
are running out of ideas. The bilinear First let us recall that, in order to y
1 1 1 1
transform and impulse invariance uniquely solve a system of equations, we T
methods provide poor matches to the need as many equations as unknowns. 5 2 7
6 4 9 for THIS case:
analog filter response, particularly at For example, the single equation with p_inv(X) =
high frequencies. Fast convolution one unknown 5x = 7 has the unique 1 1 5
[inv(X'X)][X']
requires more computational resources solution x = 7/5. But the single equa- 0.3716
,
than you have and creates more tion with two unknowns 5x + 2y = 7 2.8491
input/output latency than you can toler- has multiple solutions x = (7 2y )/5
ate. What will you do? that depend on the unspecified y-value. If where T denotes the matrix transpose. Of
In this article, we describe an obscure another equation, 6x + 4y = 9, is course, the mathematical derivation of
but simple and powerful method for added to the equation above, there are the matrix inverse and pseudoinverse,
designing a digital filter that approxi- unique solutions for both x and y that and the definition of least-squares, can
mates an arbitrary magnitude and phase can be found algebraically or by matrix be found in any basic linear algebra text
response. If applied to the problem inversion (denoted in the following by a [1]. And while our more mathematically
above, it can create a filter roughly com- 1 superscript): inclined readers will point out that there
parable in computational burden and are better ways than this to compute the
latency to that created by the bilinear 5 2 x 7 pseudoinverse, this method is adequate
=
transform method, with fidelity 6 4 y 9 for our example.
approaching that of fast convolution. In 1 You may also remember that filter
x 5 2 7
addition, the method described here can = specifications are commonly expressed in
y 6 4 9
also be applied to a wide variety of other 1 1 terms of passband width and flatness,
16 7
system identification tasks. = 38 5 transition band width, and stopband
32 9
The filter design method we present 16 7 9 attenuation. There may also be some gen-
8 16
is called frequency-domain least-squares = . eral specifications about phase response
21 45
(FDLS) [1][3]. The FDLS algorithm 16 + 32
produces a transfer function that approx-
DSP Tips and Tricks introduces prac-
imates an arbitrary frequency response. Let us consider what happens if we
tical design and implementation sig-
The input to the algorithm is a set of add another equation, x + y = 5, to the
nal processing algorithms that you
magnitude and phase values at a large pair that we already have above (we will
may wish to incorporate into your
number (typically thousands) of arbitrary see later why we might want to do this). designs. We encourage readers to
frequencies between 0 Hz and half the There are no values of x and y that satis- submit their contributions to
sampling rate. The algorithms output is fy all three equations simultaneously. To Associate Editors Rick Lyons
a set of transfer function coefficients. address this case, matrix algebra provides (r.lyons@ieee.org) or Britt Rorabaugh
The FDLS algorithm is quite flexible in the pseudoinverse, which determines (dspboss@aol.com).
that it can create transfer functions con- the values of x and y that come, in the
or time-domain performance, but the Let us conclude our background sec- ues of which are not yet known. We also
exact magnitude and phase responses are tion with a comment on what a frequen- know that the relationship between
usually left to the designers discretion. cy response value means. In a simple input u and output y at any sample time
However, an important exception occurs example, if the frequency response of a can be inferred from the frequency
when a digital filter is to be used to emu- system at a frequency 1 is given in response value A at frequency .
late an analog filter. This is traditionally a magnitude/phase form as A1 1 , the Combining these two ideas, we obtain
very difficult problem, because analog output amplitude will be A1 times the one equation in D + N + 1 unknowns
systems are described by Laplace trans- input amplitude and the output phase
forms using integration and differentia- will be shifted an angle 1 relative to the y1 (0) = [y1 (1) . . . y1 (D)
tion, whereas digital systems are input phase when a steady-state sine a
1
described by z-transforms using delay. wave of frequency 1 is applied to the ..
Since the conversion between them is system. For instance, if the input to the .
aD
nonlinear, the response of an analog sys- system described above at time k is u1 (0) . . . u1 (N )]
b0 .
tem can only be approximated by a digital u1 (k) = cos(k1 ts ), where ts is the sam-
.
system and vice-versa. pling period (equal to one over the sam- ..
Let us assume that the transfer func- pling frequency), then the output will be bN
tion of our digital filter (i.e., the mathe- y1 (k) = A1 cos(k1 ts + 1 ) . The input
matical description of the relationship and output values at any sample time (Note that the current-sample index k
between the filters input and output) is can be determined in a similar manner. has been set to zero.) If we repeat using
in a standard textbook form [2] given by For example, the input sample value N A2 2 at a different frequency 2 , we
samples in the past was obtain a second equation in D + N + 1
Y(z ) b0 + b1 z 1 + + bN z N u1 (k N) = cos ((k N )1 ts ) and the unknowns as shown in (a) at the bottom
= ,
U(z ) 1 + a1 z 1 + + aD z D output sample value D samples in the of the page. And if we repeat at many
past was y1 (k D) = A1 cos ((k D) more different frequencies M than we
where U(z ) is the z-transform of the input 1 ts + 1 ). For our purposes, since k have unknowns D + N + 1, we know
signal, Y(z ) is the z-transform of the out- represents the current sample time, its from our review of linear algebra that the
put signal, and the a and b factors are real- value can conveniently be set to zero. pseudoinverse will compute values for
valued coefficients. Furthermore, we the set of coefficients a1 . . . aD and
assume that the filter is causal, meaning FDLS FILTER APPROXIMATION b0 . . . bN that come as close as possible
that its response to an input does not begin Based on our review of the pseudoin- to solving all of the equations, which is
until after the input is applied. Under these verse, transfer function, and frequency exactly what we need to design our filter.
assumptions, the time-domain difference response, we know that the output is a So now we can write (b), shown at the
equation that implements our filter is combination of present and past input bottom of the page. We can denote the
and output values, each scaled by a set of y1 (0) . . . yM (0) column vector above as
y(k) = a1 y(k 1) aD y(k D) b or a coefficients (respectively), the val- Y, the matrix as X, and the a1 . . . bN col-
+ b0 u(k) + + bN u(k N ),
a
where the a and b coefficients are exactly 1
..
the same as in the transfer function .
above, k is the time index, u(k) and y(k) y1 (0) y1 (1) . . . y1 (D) u1 (0) . . . u1 (N)
aD .
= (a)
are the current values of the input and y2 (0) y2 (1) . . . y2 (D) u2 (0) . . . u2 (N) b
0
output (respectively), u(k N ) was the .
..
input value N samples in the past, and
bN
y(k D) was the output value D samples
in the past. We can write the equation
above in matrix form as
a
1
..
y(k) = [y(k 1) . . . y(k D) y1 (0) y1 (1) . . . y1 (D) u1 (0) ... u1 (N) .
a y2 (0) y2 (1) . . . y2 (D) u2 (0) ... u2 (N)
aD
1
.. = .. .. .. ..
b0 .
.. . . . . .
. .
yM (0) yM (1) . . . yM (D) uM (0) . . . uM (N) ..
aD
u(k) . . . u(k N )]
b0 .
bN
. (b)
..
bN
Magnitude (dB)
20
(X T X )1 X T Y . 30
The following material provides additional examples of the FDLS algorithm described in the
January 2007 IEEE Signal Processing magazine DSP Tips & Tricks column article "Precise Filter
Design" by Greg Berchin.
Algebraic Example
Recall the FDLS matrix expression
a1
y1 (0) y1 ( 1) K y1 ( D ) u1 (0) K u1 ( N ) M
y (0) y ( 1) K y ( D ) u (0) K u ( N ) a
2 = 2 2 2 2 D ,
M M M M M b0
y M (0) y M ( 1) K y M ( D ) u M (0) K u M ( N ) M
bN
which we wrote as Y = X.
Each individual element in the Y column vector is of the form Amcos(m), and each
element in the X matrix is of the form A1cos(k1ts + 1) or cos(k1ts). Because all of these
elements are of the form of a product (Amplitude)[cos(angle)], each element in Y and X is equal
to a constant.
Now if, say, D = 10 and N = 9, then:
y1(0) = A1cos(1)
is the first element of the Y column vector and
Numerical Example
Heres an example of the above expressions using actual numbers. Suppose we
need to approximate the transfer function coefficients for the system whose frequency
magnitude and phase response is that shown in Figure E1. Assume that our discrete-
system sample rate is 1000 Hz, thus ts = 103 seconds, and N = D = 2. Also assume
M = 8 and we have the eight A1 -to- A8 magnitude sample values and the eight 1 -to- 8
phase samples, shown as dots in Figure E1, available to us as input values to the FDLS
algorithm.
M=8
m = 2 . fm :
1.5
A5
1 = 2(0.0)
1 2 = 2(19.69)
Linear
f4 = 51.18 Hz
4
5
Phase (radians)
2
1 Desired phase response
(b)
0
8
2
0 100 200 300 400 500
Frequency
Fig E1
where the fm vector is in Hz, the mts vector is in radians, and 1 m 8. The first two
elements of the Y vector are:
A1cos(1) 0.2172
A2cos(2) 0.2065
A3cos(3) 0.1695
Y = A4cos(4) = 0.0162
A5cos(5) 0.9390
A6cos(6) 0.6605
A7cos(7) 0.3488
A8cos(8) 0.3095
The two elements of the "y1" part of the first row of the X vector are:
The two elements of the "y8" part of the eighth row of the X vector are:
The three elements of the "u8" part of the eighth row of the X matrix are:
u8(0) = cos(0) = 1
u8(1) = cos(8ts) = cos(2.449) = 0.7696
u8(2) = cos(28ts) = cos(4.898) = 0.1845.
0.2172 0.2172 1.00 1.0000 1.0000
0.2045 0.994 1.00 0.9924 0.9696
0.1639 0.1502 1.00 0.9753 0.9025
= 0.0147 0.0117 1.00 0.9487 0.8002 .
0.5007 0.0059 1.00 0.939 0.7370
0.6564 0.5378 1.00 0.9129 0.6667
0.2812 0.0928 1.00 0.7851 0.2328
0.2376 0.0562 1.00 0.7696 0.1845
Given the above Y vector and the X matrix, the FDLS algorithm computes the 2nd-order
(N = D = 2) transfer function coefficients vector M=8 as
1.8439
0.9842
M=8 = 0.3033 .
0.5762
0.3034
u(k) y(k)
z 1 0.3033
1.8439 0.5762
z 1
0.9842 0.3034
Fig E2
The frequency-domain performance of the filter are the solid red curves shown in Figure E3.
There we see that the M=8 coefficients provide an accurate approximation to the desired
frequency response in Figure E1.
0
Magnitude (dB)
(a) 20
Desired magnitude response
Actual magnitude response
40
0 100 200 300 400 500
Frequency
4
Phase (radians)
2
Desired phase response
(b)
Actual phase response
0
2
0 100 200 300 400 500
Frequency
Fig E3