Perancangan Filter FIR
Perancangan Filter FIR
2/77
Filter design
– Need to decide :
• Type of filter
• Tolerances
• Sampling frequency
3/77
Filter specifications
– Important parameters
p peak passband deviation (or ripples)
r stopband deviation
4/77
ILPF
Fig. 7-3.
5/77
FIR coefficient calculation
N
y (n) h(k ) x(n k )
k 0
N
H ( z ) h(k ) z k
k 0
6/77
The window method of calculating FIR filter coefficients
– Step 1 : specify the desired frequency response of filter, H I ( )
– Step 2 : obtain the impulse response, hI (n) , of desired filter by
evaluating the inverse Fourier transform
– Step 3 : select a window function and then determine the number of
coefficients using the appropriate relationship between the filter
length and the transition width, f
– Step 4 : obtain values of w(n) for chosen window function and the
values h( n) hI (n) w(n)
of the actual FIR coefficient, , by multiplying by
h(n) hI (n) w(n) (7-
26)
7/77
Window method
Design of FIR filter using window method
– Frequency response of filter, H I ( )
– Impulse response, hI (n)
1
hI (n)
2
H I ( )e j n d (7-
19)
2 f c sin(nc )
, n 0, - n
= n c
(7-
2 fc , n 0 20)
8/77
Table 7.2 Summary of ideal impulse responses for standard frequency selective filters
hI (n)
hI (n) hI (n)
9/77
Fig. 7-4.
(The frequency scale is normalized by T = 1)
10/77
Truncation for FIR
h(n) hI (n) w(n) "windowing"
– Rectangular window
1 , n 0,1,..., N
w(n)
0 , elsewhere
11/77
Fig. 7-5.
12/77
Fig. 7-6.
13/77
Fig. 7-7.
14/77
Some common window functions
– Hamming window
F 3.32 / N (7-
22)
where N is filter order and
F is normalized transition width
15/77
– Properties of common window functions
Fig. 7-8. Window functions: (a) Rectangular, (b) Hamming, (c) Blackman
16/77
Table 7.3 Summary of important features of common window functions
17/77
– Kaiser window
• Trade-off transition width against ripple
– using a ripple control parameter,
2 n N
2
I0 1
N
w n , 0 n N (7-
I 0 23)
0 , elsewhere
2
L
( x / 2) k
I 0 ( x) 1
k 1 k !
A 7.95
N (7-
14.36f
25)
19/77
Example 7-2
– Obtain coefficients of FIR lowpass filter using
Hamming window
Passband cutoff frequency f p : 1.5kHz
Transition width f : 0.5kHz
Stopband attenuation 50dB
Sampling frequency f s : 8kHz
• Lowpass filter
sin nc
2
c f , n 0
hI n nc
2 fc , n 0
N
2 f c sin ( n )c
2 N
, n , 0 n N
N 2
hI (n) (n )c
2
N
2 fc , n
2
21/77
– Symmetrical function h(n)
» Calculation of h(0), h(1), , h(27)
» Using the symmetry property to obtain the other coefficients
2 0.21875
n 0 : hI (0) sin( 27 2 0.21875)
27 2 0.21875
0.00655
w(0) 0.54 0.46 cos(0) 0.08
h(0) hI (0) w(0) 0.00052398
2 0.21875
n 1 : hI (1) sin( 26 2 0.21875)
26 2 0.21875
0.011311
w(1) 0.54 0.46 cos(2 / 54)
0.08311
h(1) hI (1) w(1) 0.000940057
22/77
2 0.21875
n 2 : hI (2) sin( 25 2 0.21875) 0.00248397
25 2 0.21875
w(2) 0.54 0.46 cos(2 2 / 54)
0.092399
h(2) hI (2) w(2) 0.000229516
2 0.21875
n 26 : hI (26) sin( 12 0.21875)
12 0.21875
0.312936
w(26) 0.54 0.46 cos(2 26 / 54)
0.9968896
h(26) hI (26) w(26) 0.3112226
24/77
Example 7-3
– Obtain coefficients using Kaiser window
Stopband attenuation : 40dB
passband attenuation : 0.01dB
Transition region f : 500 Hz
Sampling frequency f s : 10kHz
Passband cutoff frequency f p : 1200 Hz
r p 0.00115
20 log(0.00115) 58.8dB
25/77
• Using Kaiser window
– The number of filter order N
A 7.95 58.8 7.95
N 70.82
14.36F 14.36(500 /10000)
N 71
– The ripple parameter
26/77
– Calculation of FIR coefficients
N
2 f c sin n c
2
hI (n) , 0 n N
N
n c
2
27/77
– Symmetrical function h(n)
» Calculation of h(0), h(1), , h(35)
» Using the symmetry property to obtain the other coefficients
2 0.145
n 0 : hI (0) sin( 35.5 2 0.145)
35.5 2 0.145
0.00717
2n N
2
I0 1
N I (0)
w(0) 0 0.023
I0 ( ) I 0 (5.52)
28/77
2 0.145
n 1: hI (1) sin( 34.5 2 0.145)
34.5 2 0.145
0.0001449
69
2
I 0 5.52 1
71 I (1.3)
w(1) 0 0.0337975
I 0 (5.52) I 0 (5.52)
29/77
2 0.145
n 2 : hI (2) sin( 34.5 2 0.145)
33.5 2 0.145
0.007415484
69
2
I 0 5.52 1
71 I (1.8266)
w(2) 0 0.04657999
I 0 (5.52) I 0 (5.52)
30/77
2 0.145
n 35 : hI (35) sin( 0.5 2 0.145)
0.5 2 0.145
0.280073974
1
2
I 0 5.52 1
71 I (5.51945)
w(35) 0 0.999503146
I 0 (5.52) I 0 (5.52)
31/77
Fig. 7-10.
32/77
33/77
The optimal method
Basic concepts
– Equiripple passband and stopband
E ( ) W ( )[ H I ( ) H ( )]
– Mathematically expressed as
min[max E ( ) ]
over the passbands and stopbands
34/77
Practical response
Ideal response
Fig. 7-11.
35/77
min[max E ( ) ]
equiripple passband and stopband of the resulting filter response,
with the ripple alternating in sign between equal amplitude levels
The minima and maxima are known as extrema.
For linear lowpass filters, for example, there are either m+1 or m+2
extrema,
m=(N+1)/2, type 1 filter
m= N/2, type 2 filter
36/77
Fig. 7-12. Extremal frequencies
37/77
– The procedure of optimal method
• Use the alternation theorem (Parks and McClellan) to find the optimum
set of extremal frequencies
• Determine the frequency response using the extremal frequencies
• Obtain the impulse response coefficients
38/77
Optimal FIR filer design
– Transfer function of lowpass filter
N
H ( z ) h(k ) z k (7-
k 0 28)
where h(n) h( n)
39/77
• Let f / 2 f s T / 2 be defined by normalized frequency, then
– Normalize as f p / f s f p , f r / f s f r
-> Normalized passband : 0, f p
-> Normalized stopband : f r , 0.5
1, 0 f fp (7-
H I ( f )
0, f r f 0.5 30)
• Weighting function
1
, 0 f fp
W f k (7-
1 , f r f 0.5 31)
40/77
a(k ) k 0,1, 2, , N / 2
min[max E ( f ) ]
N /2
H ( f ) H (e j 2 f
) a (k ) cos k 2 f (7-
k 0 32)
E ( f ) W ( f )[ H ( f ) H I ( f )] (7-
33)
41/77
– Alternation theorem
• Let F 0, f p f r , 0.5
• H ( f ) H I ( f ) is the unique best approximation if and only if E ( f ) is
equiripple at F and has at least m+2 extremal points in , that is, there
exists
f 0 f1 f l (l m 1)
such that
E ( f i ) E ( f i 1 ) e, i 0,1, , l 1 (7-
34)
where e max E( f )
f 0, f p & f r ,0.5
42/77
• From equations (7-33) and (7-34)
• Matrix form
43/77
– Summary
Step 1. Choose filter length as 2m+1
Step 2. Choose m+2 points of fi in F
Step 3. Calculate a(k ) and e using equation (7-36)
Step 4. Calculate E ( f ) using equation (7-29). If E ( f ) e , go to step 5,
otherwise go to step 6
Step 5. Determine
h(0)mlocal
a(0), minima
h(k ) a(or
k )maxima
/ 2 k points
1, 2, , m
Step 6. Obtain , ,
then the optimal filter Nis given by
H ( z ) h(k ) z k
k 0
44/77
Example 7-4
– Specification of desired filter
• Filter length : 3
• pT 1[rad], rT 1.2[rad] , k 2
N 2m 1 3
m 1 m 2 3
45/77
• From H I ( f 0 ) H I ( f1 ) 1, H I ( f 2 ) 0, W ( f 0 ) W ( f1 ) 1/ 2 and W ( f 2 ) 1
1 0.8776 2 a(0) 1
1 0.5403 2 a(1) 1
1 0.3624 1 e 0
46/77
• Choose a new set of fi
1 1.2
f 0 , f1 , f 2 0.5
2 2
H I ( f 0) 1, H I ( f1) H I ( f 2) 0, W ( f 0) 0.5, and W ( f1) W ( f 2) 1
1 0.5403 2 a(0) 1
1 0.3624 1 a(1) 0
1 1 1 e 0
( f ) 0.306
•Transfer of the optimalEfunction 0,1/ 2 and 1.2 / 2 , 0.5
H ( f ) 0.144 0.45cos 2 f (7-
38)
48/77
Optimal method using MATLAB
– Based on Parks-McClellan and Remez algorithm
– Calculation of coefficients for FIR filter using Remez
b remez(N,F, M )
b remez(N,F, M, WT )
49/77
Example 7-5
– Specification of desired filter
• Pass band : 0 – 1000Hz
• Transition band : 500Hz
• Filter length : 45
• Sampling frequency : 10,000Hz
– Normalized frequency band edges
F [0, 0.2, 0.3, 1]
– Magnitude response
M [1 1 0 0]
50/77
Table 7-4. Impulse response coefficients
51/77
Fig.7-14. Frequency response of filter
52/77
Example 7-6
– Specification of desired filter
• Pass band : 3kHz – 4kHz
• Transition band : 500Hz
• Pass band ripple : 1dB
• Rejection band attenuation : 25dB
• Sampling frequency : 20kHz
M [0 1 0]
53/77
• Estimation of filter length
– Pass and rejection band ripples
Ap
10 20 1 Ar
p Ap r 10 20
10 20 1
where A p and Ar are ripples of dB scale in pass and rejection band
54/77
Table 7-5. Impulse response coefficients of
filter
55/77
Fig. 7-15. Frequency response of filter
56/77
Frequency sampling method
Design of FIR filter
– Taking N samples of the frequency response at intervals of kFs / N ,
k 0,1, , N 1
– Filter coefficients h(n)
N1
1
h( n)
N
H
k 0
( k ) e j (2 / N ) nk
(7-
40)
57/77
– Linear phase filters with positive symmetrical impulse response
• For N even
N2 1
1
h( n) 2 H (k ) cos[2 k (n ) / N ] H (0) (7-
N k 1 41)
where ( N 1) / 2
• For N odd
– Upper limit in the summation is ( N 1) / 2
58/77
Fig. 7-16.
59/77
Example 7-7
1 N /2 1
(1) Show the h(n) 2 H (k ) cos[2 k (n ) / N ] H (0)
N k 1
• From equation (7-40)
N1
1
h( n)
N
H (k ) e
k 0
j 2 nk / N
N1
1
N
H (k ) e
k 0
j 2 k / N
e j 2 kn / N
N1
1
N
H (k ) e
k 0
j 2 ( n ) k / N
N1
1
N
H (k ) cos[2 k (n ) / N ] j sin[2 k (n ) / N ]
k 0
h(n) is real value N1
1
•
is symmetryN
H (k ) cos[2 k (n ) / N ]
k 0
h( n)
1 N /2 1
h(n) 2 H (k ) cos[2 k ( n ) / N ] H (0) (7-
N k 1 42)
60/77
(2) Design of FIR filter
• Specification of desired filter
– Pass band : 0 – 5kHz
– Sampling frequency : 18kHz
– Filter length :9
• Selection of frequency samples at intervals of kf s / N
1, k 0,1, 2
H (k )
0, k 3, 4
Table 7-6.
62/77
Comparison of the window, optimum
and frequency sampling methods
Optimal method
– Easy and efficient way of computing FIR filter coefficients
– Making filter with good amplitude response characteristics for reasonable
values of N
Window method
– In the absence of the optimal software or when the passband and stopband
ripples are equal, the window method represents a good choice
– Particularly simple method to apply and conceptually easy to understand
Frequency sampling method
– Filters with arbitrary amplitude-phase response can be easily designed
– Lack of precise control for the location of the bandedge frequencies or the
passband ripples
63/77