Professional Documents
Culture Documents
Lecture – 10 Objectives
FIR Filter
To learn and understand
design procedure of FIR filter.
the frequency response, and
Design its properties of FIR filter.
In the case of IIR filters a linear phase in the pass band is not
achievable. Hence we will consider magnitude-only
specifications.
0
c
High pass filter:
H()
H()
0
H() 0
c
0
c
IUB Dr. Abdur Razzak 4
Frequency response of ideal filters (contd..) ECR 305_L10
0
0 c1 0
c1 c2
0
c2
IUB Dr. Abdur Razzak 5
Filter specifications ECR 305_L10
H
dB scale 20 log10 0
H max
This approach is the most popular one in practice and is used for both FIR
and IIR filters. To illustrate these specifications, we will consider a
lowpass filter design as an example.
IUB Dr. Abdur Razzak 6
Absolute specifications ECR 305_L10
1 1
R p 20 log 10 0 0
1 1
2
As 20 log 10 0 1
1 1
Solution:
1 1 2
R p 20 log 10 As 20 log 10
1 1 1 1
1 1 2
0.25 20 log 10 50 20 log 10
1 1 1 0.0144
1 1
10
0.125
1 1 2 1.014410 50 / 20
1 0.0144 0.0032
Solution:
1 1 1 0.01
R p 20 log 10 20 log 10 0.1737 dB
1 1 1 0.01
2 0.001
As 20 log 10 20 log 10 60 dB
1 1 1 0.01
Solution: 2
Transfer
H
n 0
hn e jn 1 e j e j 2
function
e j e j 1 e j 1 2 cos e j
1 c sin c n
2 c
1 e j e jn d
n
sin f c n
fc f c sinc f c n
f c n
IUB Dr. Abdur Razzak 17
Window design techniques (contd..) ECR 305_L10
1, 0 n M 1
wn
0, otherwise
hn hn n wn
hd n , 0 n M 1
0, otherwise
H H d W
1
2
W e j H d e j d
Bartlett window:
2n M 1
M 1 , 0n
2
wn 2 2n , M 1
n M 1
M 1 2
0, otherwise
Hann window:
2n 0 n M 1
0.5 1 cos ,
wn M 1
0, otherwise
Hamming window:
2n 0 n M 1
0.54 0.46 cos ,
wn M 1
otherwise
0,
Blackman window:
2n 4n 0 n M 1
0.42 0.5 cos
wn
0.08 cos ,
M 1 M 1 otherwise
0 ,
Kaiser window:
2n
2
I 0 1 1
M 1
wn , 0 n M 1
I o
x / 2
2
k
I 0 x 1
k 0 k!
Transition width: s p
As 7.95
Filter length: M 1
2.285
0.1102 As 8.7 , As 50
parameter: 0.5842 As 21 0.4
0.07886 A 21, 21 A 50
s s
Low-pass: c = 0.25 N = 50
High-pass: c = 0.25 N = 50
Basic idea: Given the ideal lowpass filter Hd(), choose the
filter length M and then sample Hd() at M equispaced
frequencies between 0 and 2.
Similar steps apply to other frequency-selective filters.
Furthermore, this idea can also be extended for approximating
arbitrary frequency-domain specifications.
There are two design approaches:
In the first approach we use the basic idea literally and provide no
constraints on the approximation error; that is, we accept whatever error
we get from the design. This approach is called a naive design method.
In the second approach we try to minimize error in the stopband by
varying values of the transition band samples. It results in a much better
design called an optimum design method.
IUB Dr. Abdur Razzak 33
Frequency sampling technique (contd..) ECR305_L10
The last two techniques-namely, the window design and the frequency
sampling design were easy to understand and implement. However,
they have some disadvantages.
Finally, the approximation error that is, the difference between the ideal
response and the actual response is not uniformly distributed over the
band intervals. It is higher near the band edges and smaller in the regions
away from band edges.
Filters that have this property are called equiripple filters because
the approximation error is uniformly distributed in both the pass-
band and the stop-band. This results in lower-order filters.
IUB Dr. Abdur Razzak 36
Optimal equiripple design technique (contd..) ECR 305_L10
MATLAB
Examples
Solution:
hne 1 e e
2
j jn j j 2
H e
Transfer n 0
function
e e 1 e 1 2 cos e
j j j j
Magnitude &
H e j 1 2 cos , 0
phase is
corresponding , 0 2 / 3
phase response H e j
piecewise linear
, 2 / 3
function hd = ideal_lp(wc,M);
alpha = (M-1)/2;
n = 0:M-1;
m = n-alpha;
fc = wc/pi;
hd = fc*sinc(fc*m);
p = 0.2 s = 0.3
Rp = 0.25 dB As = 50 dB
Solution:
% Definition % Plotting
wp = 0.2*pi; ws = 0.3*pi; tr_width = ws-wp;
M = ceil(6.6*pi/tr_width)+1;
n = 0:M-1;
wc = (ws+wp)/2; % Ideal LPF cutoff frequency subplot(2,1,1)
stem(n,w_ham);
% Calculation grid
% Impulse response title('Hamming Window');
hd = ideal_lp(wc,M); xlabel('n','fontsize',15);
w_ham = (hamming(M))'; ylabel('w(n)','fontsize',15);
h = hd.*w_ham;
subplot(2,1,2)
% Frequency response plot(w/pi,db);
[H w] = freqz(h,[1],1000,'whole'); grid
H = (H(1:501))'; w = (w(1:501))'; title('Magnitude response in dB');
mag = abs(H); xlabel('Frequency in pi units');
db = 20*log10((mag+eps)/max(mag)); ylabel('Decibels','fontsize',15);
p = 0.2 s = 0.3
Rp = 0.25 dB As = 50 dB
Solution:
% Definition % Plotting
wp = 0.2*pi; ws = 0.3*pi;
tr_width = ws-wp; As = 50;
M = ceil((As-7.95)/(2.285*tr_width)+1)+1
n = 0:M-1; subplot(2,1,1)
wc = (ws+wp)/2; % Ideal LPF cutoff frequency stem(n,w_kai);
beta = 0.1102*(As-8.7) grid
title(‘Kaiser Window');
% Calculation xlabel('n','fontsize',15);
% Impulse response ylabel('w(n)','fontsize',15);
hd = ideal_lp(wc,M); w_kai = (kaiser(M,beta))';
h = hd.*w_kai; subplot(2,1,2)
plot(w/pi,db);
% Frequency response grid
[H w] = freqz(h,[1],1000,'whole'); title('Magnitude response in dB');
H = (H(1:501))'; w = (w(1:501))'; mag = abs(H); xlabel('Frequency in pi units');
db = 20*log10((mag+eps)/max(mag)); ylabel('Decibels','fontsize',15);
s = 0.4 p = 0.5
Rp = 0.25 dB As = 50 dB
Solution:
0
c
0
c
0
% Definition % Plotting
ws = 0.2*pi; wp = 0.3*pi; tr_width = wp-ws;
M = ceil(6.6*pi/tr_width)+1
n = 0:M-1;
wc = (ws+wp)/2; % Ideal LPF cutoff frequency
subplot(2,1,1)
% Calculation stem(n,w_ham);
% Impulse response grid
hd = ideal_lp(pi,M)-ideal_lp(wc,M); title('Hamming Window');
w_ham = (hamming(M))'; xlabel('n','fontsize',15);
h = hd.*w_ham; ylabel('w(n)','fontsize',15);
c = 0.2 Rp = 0.25 dB As = 50 dB
Solution:
Solution:
0
0
2/3
IUB Dr. Abdur Razzak 59
MATLAB example 7.11 (contd..) ECR 305_L10
% Definition % Plotting
M = 45; As = 60; n = 0:M-1;
beta = 0.1102*(As-8.7)
wc1 = pi/3; wc2 = 2*pi/3;
subplot(2,1,1)
% Calculation stem(n,w_kai);
% Impulse response grid
hd = ideal_lp(pi,M)-ideal_lp(wc2,M) title('Kaiser Window','fontsize',15);
+ ideal_lp(wc1,M); xlabel('n','fontsize',15);
w_kai = (kaiser(M,beta))'; ylabel('w(n)','fontsize',15);
h = hd.*w_kai;
To design FIR filters using the Kaiser window, the SP toolbox provides the
function kaiserord which estimates window parameters that can be used in the
firl function.
Lowpass: c = 0.25 N = 50
Highpass: c = 0.25 N = 50
% Plotting
plot(w/pi,db1,w/pi,db2); grid
legend('lowpass','highpass','fontsize',15)
title('Magnitude response in dB','fontsize',15);
xlabel('Frequency in pi units','fontsize',15);
ylabel('Decibels','fontsize',15); axis([0 1 -100 20]);
% Plotting
plot(w/pi,dbb,w/pi,dbs,'r'); grid
legend('bandpass','stopband');
title('Magnitude response in dB','fontsize',15);
xlabel('Frequency in pi units','fontsize',15);
ylabel('Decibels','fontsize',15); axis([0 1 -80 20])
It should be noted that the fir2 does not implement the classic optimum
frequency sampling method.
IUB Dr. Abdur Razzak 70
MATLAB example 7.86 ECR 305_L10
[h] = firpm (N, f , m) designs an Nth-order (note that the length of the
filter is M = N + 1) FIR digital filter whose frequency response is
specified by the arrays f and m. The filter coefficients (or the impulse
response) are returned in array h of length M. The array f contains band-
edge frequencies in units of , that is, 0.0 < f < 1.0. These frequencies
must be in increasing order, starting with 0.0 and ending with 1.0. The
array m contains the desired magnitude response at frequencies specified
in f. The lengths of f and m arrays must be same and must be an even
number. The weighting function used in each band is equal to unity, which
means that the tolerances (i’s) in every band are the same.
IIR Filter
Design
IUB Dr. Abdur Razzak 78