Exercise 1 1a) Try help kaiserord to get started. Beware that the

Johannes J. Struijk, 2010 ch. 10
Exercise 1
1a)
Try help kaiserord to get started.
Beware that the Kaiser window method only gives an approximate solution. You may
have to increase N by 1 or 2 if the specifications are not perfectly met.
The MatLab code:
F = [50 70];
% First frequency band (pass) is 0-20,
% second band (stop) is 70-250
A = [1 0];
% defining the bands as pass and stop respectively
DEV = [0.11 0.01] % -1 dB and –40 dB, the FIR filter will use the
% smallest of the two for both bands! This means
% that the pass band will be overdimensioned.
Fs = 500;
% sample frequency
[N,wn,beta,type] = kaiserord(F,A,DEV,Fs);
b = fir1(N,wn, kaiser(N+1,beta),’noscale’);
1b)
freqz(b,1);
See figure below.
Magnitude (dB)
50
0
-50
-100
-150
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
Phase (degrees)
0
-500
-1000
-1500
Zooming in at ws=70/250=0.28 shows that the attenuation is 40 dB.
Zooming in at wp=50/250=0.2 shows that the attenuation is much less than the
allowed -1 dB (<0.1 dB).
The filter thus easily meets the requirements.
You can use the filter to filter the signal FIRECG.txt by:
y = filter(b,1,FIRECG(:,leadnr));
For example: FIRECG(:,2));
plot(y)
hold
plot(FIRECG(:,2),'r')
where leadnr is 1, 2, …8
Johannes J. Struijk, 2010 ch. 10
And you will see the time delay, and that some of the high frequency noise has
become less.
You can try with other (lower) cut off frequencies as well to see where you get a clear
distortion of the signal.
1c)
The type of filter can easily be obtained by looking at the impulse response:
impz(b,1);
Impulse Response
0.3
0.25
Amplitude
0.2
0.15
0.1
0.05
0
-0.05
0
10
20
30
n (samples)
40
50
The impulse response has even symmetry, and N=56.
The filter is thus of type I.
Exercise 2
2a)
[n,fo,mo,w] = remezord( [20 30], [0 1], [0.01 0.11], 250 );
b = remez(n,fo,mo,w);
2b)
Zooming in on the transfer function at w=0.08 and w=0.12 shows that the –40dB and
1 dB ripple requirements are fulfilled exactly.
Johannes J. Struijk, 2010 ch. 10
Magnitude (dB)
50
0
-50
-100
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
Phase (degrees)
1000
0
-1000
-2000
-3000
2c)
impz(b,1);
The impulse response has even symmetry with 0<n<M (M=34).
This is thus a type I filter.
Note also in the plot of the transfer function that H(z)0 at f=0 and H(z) 0 at f=Fs/2.
Exercise 3
3a)
[N,wn,beta,type] = kaiserord( [20 30], [0 1], [0.01 0.11], 250 );
b = fir1(N,wn,’high’,kaiser(N+1,beta),’noscale’);
freqz(b,1);
Magnitude (dB)
50
0
-50
-100
-150
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
Phase (degrees)
2000
0
-2000
-4000
impz(b,1);
Gives symmetric impulse response.
N=56
Johannes J. Struijk, 2010 ch. 10
3b)
Filter order
Stopband ripple
Passband ripple
Parks-McClellan
M = 34
equiripple
equiripple
Kaiser
M = 56
not equiripple
not equiripple, much better
than the specifications
Remez (Parks-McClellan) thus meets the specifications with a much lower filter order
than Kaiser. This is because the Kaiser window filter is always better than the
specifications, except for a single point where it meets exactly the specs. Remez uses
the allowed ripple over the whole passband and the whole stopband.