Loading in 2 Seconds...
Loading in 2 Seconds...
University of Manchester School of Computer Science Comp30291 Digital Media Processing 200910 Section 4 ‘Design of FIR digital filters’. x[n]. . z 1. z 1. z 1. z 1. a M. a M1. a 0. a 1. y[n]. 4.1.Introduction
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
School of Computer Science
Comp30291
Digital Media Processing 200910
Section 4
‘Design of FIR digital filters’
Comp30291: Section 4
...
z1
z1
z1
z1
aM
aM1
a0
a1
y[n]
4.1.Introduction
FIR digital filter of order M implemented by programming the signalflowgraph shown below. Its difference equation is:
y[n] = a0x[n] + a1x[n1] + a2x[n2] + ... + aMx[nM]
Comp30291: Section 4
z1
z1
z1
z1
z1
z1
z1
z1
z1
z1
a0
a10
a1
a3
a4
a5
a6
a7
a8
a9
a2
+
+
+
+
+
+
+
+
+
+
y[n]
10th order FIR digital filterComp30291: Section 4
Background, objective & methodology
Comp30291: Section 4
Comp30291: Section 4
= tan2(b,a) = angle(a + j.b) : range  to
Comp30291: Section 4
Comp30291: Section 4

0
()

Gain & phase response graphs with ve frequenciesAs G() = G(),gainresponse is always symmetric about =0
As () = (),phaseresponse is always antisymmetric about = 0
Comp30291: Section 4
1

/3
/3
0
4.2. Design of an FIR lowpass filter
Assume we require lowpass filter whose gainresponse approximates the ideal 'brickwall' gainresponse:
If we take phaseresponse () = 0 for all ,
the required target frequencyresponse is:
Comp30291: Section 4
By inverse DTFT, required impulseresponse is:
Comp30291: Section 4
Comp30291: Section 4
sinc(x)
1
Main ‘lobe’
‘Ripples’
x
1
3
2
1
2
3
4
‘Zerocrossings’ at x =1, 2, 3, etc.
Comp30291: Section 4
clear all; close all; clc;
x = [10: 0.1 : 10];
y = sinc(x);
figure(1); plot(x,y); grid on;
title('sinc function');
xlabel( 'x'); ylabel('sinc(x)');
legend('sinc(x)', 'Location','Best');
axis([10 10 0.3 1]);
Comp30291: Section 4
‘Main lobe’
‘Zerocrossings’ at x =1, 2, 3, etc
‘Ripples’
Comp30291: Section 4
Impulseresponse for this ideal (brickwall) lowpass filter
Comp30291: Section 4
n=[20:20]; h = (1/3)*sinc(n/3);
figure(1); stem(n,h,'.:'); grid on;
title('h[n] = (1/3) sinc(n/3)');
xlabel( 'n'); ylabel('h[n]');
legend('(1/3)sinc(n/3)', 'Location','Best');
axis([20 20 0.1 0.35]);
for n=20:20,
disp(sprintf('n:%2d, h[n]: %6.3f' ,n,h(n+21)));
end;
Comp30291: Section 4
Comp30291: Section 4
To produce a realisable impulseresponse {h[n]}:
Assume M is order of required filter & that M is even.
(2) Delay resulting sequence by M/2 samples to ensure that the first nonzero sample occurs at n = 0.
Step (1) is ‘truncation’ or ‘windowing’ applied symmetrically about n=0.
Comp30291: Section 4
Causal & finite impulseresponse
Comp30291: Section 4
1
z1
z1
z
z1
a4
a3
a1
a0
a2
0.14
0.28
0.33
0.28
0.14
+
y[n]
FIR filter realisation (M=4)
( Note:4th order FIR filter has 4 delays & 5 multipliers ).
Comp30291: Section 4
21 dB
Gain dropsto  dB
/3 Fs/6
FC
Fs/2
Straight line
Jumpsby 180O
Plot gain & phase responses of 4th order FIR filter
Comp30291: Section 4
n=[20:20];
h = (1/3)*sinc(n/3);
M=4; % FIR filter order
Fs = 8000; % Sampling freq (Hz)
for n=M/2 : M/2
a(n + M/2 + 1) = h(n+21);
end;
figure(1); freqz(a,1,200,Fs);
Comp30291: Section 4
6dB
0
21 dB
20
Gain dropsto  dB
Magnitude (dB)
40
Fs/2
60
0
500
1000
1500
2000
2500
3000
3500
4000
/3 Fs/6
FC
Frequency (Hz)
Gainresponse of 4th order FIR filter (zoomed)
Comp30291: Section 4
2
300O
200
100
Fs/2
/2
F Hz
0
1000
FC
2000
3000
4000
Phaselag response of 4th order FIR filter
Comp30291: Section 4

()

Why do we not get a zero phaseresponse?Only passband part is shown here
Comp30291: Section 4
Comp30291: Section 4
c = fir1(4, 0.33, rectwin(5), 'noscale');
freqz(c, 1, 500, Fs);
Comp30291: Section 4
Gain & phase responses of 4th order FIR filter by MATLAB
Comp30291: Section 4
Effect of truncating {h[n]} to M/2 & delaying by M/2 samples
Comp30291: Section 4
Can we improve lowpass filter by increasing order to ten?
Comp30291: Section 4
z1
z1
z1
z1
z1
z1
z1
z1
z1
z1
0
.07
.07
.28
.28
0.14
0
.055
0.14
.33
.055
+
+
+
+
+
+
+
+
+
+
y[n]
10th order FIR digital lowpass filter(/3 rect)When coeffs are symmetric, the filter is linear phase.
Comp30291: Section 4
For 10th order lowpass filter with C = /3:
Comp30291: Section 4
Gain & phase responses of 20th order lowpass FIR filter with C = /3
Comp30291: Section 4
Gain & phase responses of 60th order lowpass FIR filter with C = /3
Comp30291: Section 4
Gain & phase of 100th order lowpass FIR filter with C = /3
Comp30291: Section 4
Gainresponse of 10th order lowpass FIR filter with WC = /3
Comp30291: Section 4
Gain response of 20th order lowpass FIR filter with WC = /3
Comp30291: Section 4
Effect of increasing order on gain & phase responses
Comp30291: Section 4
n
M/2
M/2
4.3. Windowing
By truncating {h[n]} for ideal filter, we effectively multiplied {h[n]} by a rectangular window sequence {rM+1[n]} to produce {h[n]} where
Comp30291: Section 4
Effect of rectangular window on freqresponse
Comp30291: Section 4
DTFT of rectwindow {rM+1[n]} with M=20
Comp30291: Section 4
M = 20;
W = 3.2 : 0.001 : 3.2;
if W==0, R=M+1;
else R=sin((M+1)*W/2)./sin(W/2);
end;
figure(1); plot(W,R); grid on;
title(sprintf('Dirichlet K of order %d ', M));
axis([3.2 3.2 M*0.3 M+2]);
xlabel('radians/sample'); ylabel('R');
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
n
M/2
M/2
4.4. Nonrectangular windows
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
Effect of nonrectangular windows
Comp30291: Section 4
WM+1(ej) = 0.5RM+1(ej) + 0.25RM+1(ej(/(1+M/2))) + 0.25RM+1(ej(+/(1+M/2)))
Comp30291: Section 4
HWM+1(ej) = 0.54RM+1(ej) + 0.23RM+1(ej(/(1+M/2))) + 0.23RM+1(ej(+/(1+M/2)))
Comp30291: Section 4
clear all; close all; clc
M=20;
W = 3.2:0.001: 3.2; W=W+0.0000001; % Sorry
R=sin((M+1)*W/2)./sin(W/2);
W1=Wpi/(1+M/2); W2=W+pi/(1+M/2);
R1=sin((M+1)*W1/2)./sin(W1/2); R2=sin((M+1)*W2/2)./sin(W2/2);
Hann=0.5*R + 0.25*R1+0.25*R2;
figure(1); plot(W,Hann,W,R); grid on;
title(sprintf('DTFT of Hann & Rect windows, order %d ', M));
axis([3.2 3.2 M*0.3 (M+2)]);
xlabel('radians/sample'); ylabel(‘DTFT');
legend('Hann','Rect','Location','Best');
Comp30291: Section 4
Comparing DTFT of Rect & Hann windows
Comp30291: Section 4
Comp30291: Section 4
Area under curve /3 to +/3 when =0
WM+1(ej)
DTFT of Hann window
2
/3
/3
radians/sample
Comp30291: Section 4
Area under curve /3 to +/3 when =/3
WM+1(ej)
DTFT of Hann window
0
2/3
radians/sample
Comp30291: Section 4
Area under curve /3 to +/3 when =/2
WM+1(ej)
DTFT of Hann window
0.1
radians/sample
/6
5/6
Comp30291: Section 4
0
radians/sample
=2/3Area under curve /3 to +/3 when =2/3
WM+1(ej)
/3
Comp30291: Section 4
Comp30291: Section 4
Applying 4th order Hann window
Comp30291: Section 4
1
z1
z1
z
z1
a4
a3
a1
a0
a2
0.04
0.21
0.33
0.21
0.04
+
y[n]
Resulting ‘Hannwindowed’ FIR filter of order 4:
Its gainresponse is shown on next slide.
Comp30291: Section 4
Gainresp from MATLAB: 4th order (Hann)
Comp30291: Section 4
Effect of increasing order to 10
clear all;
M=10
for n= M/2 : M/2
w = 0.5 *(1+cos(n*pi/(1+M/2)) );
c(1+n+M/2) = (1/3)*sinc(n/3)*w;
end;
Fs = 8000; freqz(c,1,500,Fs);
axis([0 4000 60 0]);
Comp30291: Section 4
z1
z1
z1
z1
z1
z1
z1
z1
z1
z1
0
.017
.017
.257
.257
0.1
0
.004
0.1
.333
.004
+
+
+
+
+
+
+
+
+
+
y[n]
10th order FIR lowpass (/3, Hann)Since coeffs are symmetric, filter is exactly linear phase.
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
z1
z1
z1
z1
z1
z1
z1
z1
z1
z1
0
.01
.01
.25
.25
0.1
0
.005
0.1
.33
.005
+
+
+
+
+
+
+
+
+
+
y[n]
10th order FIR lowpass (/3, Hamming)Again, coeffs are symmetric so filter is exactly linear phase.
Comp30291: Section 4
Comp30291: Section 4
Effect of windowing on freqresponse of FIR digital filter
Comp30291: Section 4
Tenth order FIR filter with C = /3 ( Hann window )
Comp30291: Section 4
20th order FIR filter with C = /3 (Hann window)
Comp30291: Section 4
60th order FIR filter with C = /3 (Hann window)
Comp30291: Section 4
Tenth order FIR filter with C = /3 ( Hann window )
Comp30291: Section 4
20th order FIR filter with C = /3 (Hann window)
Comp30291: Section 4
Effect of Hann window on first stopband ripple
Comp30291: Section 4
Comp30291: Section 4
Order 60 FIR LPF c/o /3 designed with Kaiser window (=5)
Comp30291: Section 4
Order 60 FIR LPF c/o /3 designed with Hamming window
Comp30291: Section 4
Order 60 FIR LPF c/o /3 designed with Kaiser window (=8)
Comp30291: Section 4
Order 100 FIR LPF (/3) designed with Kaiser window (=8)
Comp30291: Section 4
100th order FIR LPF (/3) designed with Hamming window
Comp30291: Section 4
Order 100 FIR LPF (/3) designed with Kaiser window (=10)
Comp30291: Section 4
clear all;
beta = 5; N=60;
kw = kaiser(N+1,beta);
hw=hamming(N+1);
a=fir1(N, 0.33, rectwin(N+1), 'noscale');
for n=1:N+1
akw(n)=a(n)*kw(n); ahw(n) = a(n)*hw(n);
end;
figure(1); freqz(akw); grid on;
figure(2); freqz(ahw); grid on;
Comp30291: Section 4
Plot of Kaiser window (beta = 10)
Comp30291: Section 4
4.6. Highpass, bandpass & bandstop linear phase FIR filters
Comp30291: Section 4
FIR bandpass filter (/4 to /2)
Comp30291: Section 4
Comp30291: Section 4
Comp30291: Section 4
4.7. Summary of ‘windowing method’
Comp30291: Section 4
Properties of resulting FIR digital filter
Comp30291: Section 4
Demonstrate thatan FIR filter whose impulseresponse is symmetric is linear phase.
Comp30291: Section 4
4.9. Remez Exchange Algorithm method
Comp30291: Section 4
Gain of 40th order FIR lowpass filter designed by ‘Remez’
Comp30291: Section 4
4.10. Fixed point implementatn of FIR digital filters
Comp30291: Section 4
Fixed point implementation (cont)
Comp30291: Section 4
4th order lowpass filter using integer arithmetic only
A = [35 212 341 212 35] ;
x = [0 0 0 0 0 ] ;
while 1
x(1) = input( 'X = ');
Y = A(1)*x(1);
for k = 5 : 1: 2
Y = Y + A(k)*x(k);
x(k) = x(k1);
end;
Y = round( Y/1024); %Arith rightshift 10 places
disp([' Y = ' num2str(Y)]);
end;
Comp30291: Section 4
4.11. Advantages of FIR filters compared with IIR
Comp30291: Section 4
Comp30291: Section 4
1. Design a 100th order FIR lowpass digital filter with cutoff atfS/4 with & without a Hann window. Use MATLAB to compare gain responses obtained.
2. Design 10th order FIR bandpass filter with cutoff frequencies at /4 &/2.
3. Write MATLAB program for one of these filters using integer arithmetic only.
4. Design a 4th order FIR highpass filter with cutoff at /3.
5. Do all FIR filters have exactly linear phase responses?
6. Explain why IIR digital filters cannot have exactly linear phase responses.
7. Explain why it is impossible to implement an ideal ‘brickwall’ LPF.
8. Show that ( ) = k corresponds to a delay of k samples.
9. Rearrange even order linear phase FIR filter to reduce no. of multipliers.
10. Do FIR filters have passband ripples as well as stopband ripples?
11. Explain why FIR filters have stopband ripples where IIR filters do not.
12. Explain why the gain of an FIR low pass filter with 0 dB gain at zero frequency reduces to 6 dB at its cutoff frequency.
Comp30291: Section 4
If h[n] symmetric & IIR it must be noncausal
n
M
Questions 10 & 610. Yes but you can hardly see them.
6. For linear phase, impulseresponse must be symmetric about some value of n, say n=M. If it is an IIR it goes on for ever as n .
So it must go on for ever backwards as n .
Would have to be nonzero for values on n<0; i.e. noncausal.
Comp30291: Section 4