FIR FILTER DESIGN
Assignment 05
(Part A) Design with frequency sampling
© H. Jleed: 2018 ~
There two methods for FIR Design
• (A) Design with frequency sampling
• (B) Design with window functions
© H. Jleed: 2018 ~
FIR filter design
© H. Jleed: 2018 ~
Types of Linear phase filters
© H. Jleed: 2018 ~
The main lobe as narrow as possible.
The problem is not the height of the side lobes. The matter is
how you accumulate the area as you integrate through it.
© H. Jleed: 2018 ~
Design FIR (Type I)
wo=0.3*pi; % Passband edge
len=23; % Length of filter
pass_len=fix(wo*len/(2*pi))+1; % Passband
length
Ad=[ones(1,pass_len),zeros(1,len-
2*pass_len+1),ones(1,pass_len-1)];
stem((1:len)/len,Ad);
xlabel('normalized frequency');
ylabel('Amplitude');
title('ideal filter')
M=(len-1)/2; % Type 1
k=0:(len-1);
pd=exp(2*pi*j*(-M)*k/len);
Hd=Ad.*pd;
h=real(ifft(Hd));
h2=imag(ifft(Hd));
figure; stem(h);hold on;
stem(h2, 'r');
legend('real','imaginary'); xlabel(‘n');
Illustration of (a) &(b)
n Shifted by M
© H. Jleed: 2018 ~
cont
[resp,omeg]=freqz(h);
figure;
subplot(211);plot(omeg,abs(resp));grid;
title('Magnitude Response');
subplot(212); plot(omeg,angle(resp), 'r.-');
hold on;
plot(omeg,unwrap(angle(resp))); title('Phase
Response');
hold
off;legend('wraped','unwraped','location','be
st')
figure;
plot(omeg,abs(resp)); title('Magnitude
Response');
hold on; plot(omeg,unwrap(angle(resp))/10,
'k'); title('Phase Response');
M=11
© H. Jleed: 2018 ~
F) Now design an even length filter of length 22, using the same approach as in a). Find the resulting impulse response h[n], and the magnitude
and phase frequency response of this filter h[n]. Note that an symmetric even-length linear-phase FIR filter always have a zero at (type 2 or 4)
Type IV
Ad=[ones(1,pass_len),zeros(1,len-2*pass_len+1),-1*ones(1,pass_len-1)]; % Must use negative type4!!!
The ideal Filter:
h=real(ifft(Hd))+1i.*imag(ifft(Hd));
© H. Jleed: 2018 ~
Now Follow these steps to complete all the assignment
© H. Jleed: 2018 ~
FIR FILTER DESIGN
Assignment 05
(Part B) Design with window functions
© H. Jleed: 2018 ~
h) Design a length-23 linear-phase FIR low-pass filter with a passband edge of .
radians/sample using a window approach. Do not use a frequency sampling technique as in
a). Use the windowing approach with the following windows: rectangular, Hanning,
Hamming and Kaiser with Find the frequency response of the resulting filters,
and compare with the filter found in a).
3.00
6
b1=fir1(len,wn,rectwin(N+1)); b2=fir1(len,wn,hann(N+1));
b3=fir1(len,wn,hamming(N+1)); b4=fir1(len,wn,kaiser(N+1,beta));
The cut-off frequency “wn” must be
normalized between 0 < Wn < 1.0,
0 5 10 15 20 25-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
Am
plit
ude
n samples
Windowed Coeffecients
rectangular
Hanning
Hamming
Kaiser
0 0.5 1 1.5 2 2.5 3 3.5-140
-120
-100
-80
-60
-40
-20
0
20
dB
rad/sec
Magnitude response
rectangular
Hanning
Hamming
Kaiser
© H. Jleed: 2018 ~
remez has been changed with firpm
(i) Design a length-23 linear-phase FIR low-pass filter with a passband edge of
radians/sample and a stopband edge of radians/sample, using the
remez Matlab function (you can also use the remezord function). What is the
particular characteristic of the magnitude of the filter frequency response ? How
does the frequency response compare with the responses from b) and h) ?
3.00 35.00
Hint: see this example.https://www.mathworks.com/help/signal/ug/fir-filter-design.html
>>b = firpm(N,f,a)f: is a vector of pairs of normalized frequency points, specified in the range between 0 and 1
a: is a vector containing the desired amplitudes at the points specified in f
© H. Jleed: 2018 ~
j) Transform one of the low-pass filters that you have designed in this assignment
to a band-pass filter. Hint : use the frequency shifting property or the modulation
property of the Fourier transform.
[ ] [ ]. jn
BPb n b n e use: = /2
Modulation of filters
© H. Jleed: 2018 ~
[ ];p sdev
[n,fo,ao,w] = firpmord(f, a, dev, fs);
f = [fp fc];a = [1 0];
Compute FIR Order
b = firpm(n,fo,ao,w);
© H. Jleed: 2018 ~
Finish the lab and submit your report
© H. Jleed: 2018 ~