Digital Signal Processing Lab Report 11 Fa19-Bee-106
Digital Signal Processing Lab Report 11 Fa19-Bee-106
FA18-BEE-046
LAB # 11: To follow the design of Linear Phase FIR filters based on
Windows using MATLAB
Objectives:
The main objective of this lab is to understand the FIR filters and to construct FIR filters based
on Windows.
Requirements:
Software:
MATLAB
Methodology:
In this lab, I first understood about the FIR filters and made my concepts clear about these types
of filters.
After that, I learned about the linear phase method to construct a FIR filter which are based on
windows.
In order to perform a window design, we have to choose a proper ideal frequency selective filter
and then truncate (or window) its impulse response to obtain a linear-phase and causal FIR filter.
The main task is to select the method for which we must select the appropriate window function
and the ideal filter.
We have an ideal frequency-selective H d (ejw), which has a unity magnitude gain and linear-phase
characteristics over its pass band, and zero response over its stop band. So, we have
where wc, is also called the cut-off frequency, and 𝛼 is called the sample delay. The impulse
response of this filter is of infinite duration and is given by
So to obtain a FIR filter from h d(n), we have to truncate(or window) hd(n) on both sides so we
can obtain a causal and linear-phase FIR filter h(n) of length M, we must have
This operation is called "windowing." In general, h(n) can be thought of as being formed by the
product of hd(n) and a window function w(n) as follows:
Depending on how we define the window function, we can obtain different window designs
techniques some of which are:
FA18-BEE-046
1. Rectangular Window
2. Bartlett Window
3. Hanning Window
4. Hamming Window
5. Blackman Window
After learning about the specifications of these windows, we went through some formulas and
design equations that helped us to perform the task assigned to us.
Pre-Lab Task
Task 1:
Solution:
%Lab13 Pre Lab
clc
clear all
close all
ord = 16;%order of filter
wn = 0.6;%window function
bw1=fir1(ord,wn,'high',hamming(ord+1)); %high pass filters with different
windows
bw2=fir1(ord,wn,'high',hann(ord+1));
bw3=fir1(ord,wn,'high',bartlett(ord+1));
bw4=fir1(ord,wn,'high',blackman(ord+1));
bw5=fir1(ord,wn,'high',rectwin(ord+1));
fvtool(bw1,1,bw2,1,bw3,1,bw4,1,bw5,1);% plotting of magnitude response
legend('hamming','hann','bartlett','blaackman','rectwin')% to create
descriptive labels
FA18-BEE-046
Lab Task
Task 1:
Solution:
%AHMAR ARSHAD
%FA19-BEE-106
%Lab 13
%Lab Task 1
function hd = ideal_lp(wc,M);
% Ideal Low Pass filter computation
% --------------------------------
% [hd] = ideal_lp(wc,M)
% hd = ideal impulse response between 0 to M-1 % wc = cutoff frequency in
radians
% M = length of the ideal filter
%
alpha = (M-1)/2;
n = [0:1:(M-1)];
m = n - alpha +eps;
hd = sin(wc*m) ./ (pi*m);
clc;
clear all;
close all;
wp = 0.2*pi;
ws = 0.3*pi;
tr_width = ws - wp
%filter order=M
M = ceil(6.6*pi/tr_width) + 1
n=[0:1:M-1];
wc = (ws+wp)/2
FA18-BEE-046
hd = ideal_lp(wc,M);
%By hamming window
w_ham = (hamming(M))';
h = hd .* w_ham;
delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1))) % Passband Ripple
As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation
% plots
stem(n,h);title('Actual Impulse Response')
xlabel('n');
ylabel('h(n)')
figure;
freqz(h,[1]);
title('frequency response')
Task 2:
Solution:
%AHMAR ARSHAD
%FA19-BEE-106
%Lab # 13
%Lab Task # 2
clc;
clear all;
close all;
%Pass Band frequencies
fp1=4500000; %(5-0.5)MHz
fp2=5500000; %(5+0.5)MHz
%Band Stop frequencies
fs1=4300000 ; %(5-0.7)MHz
fs2=5700000; %(5-0.7)MHz
FA18-BEE-046
%As = 15 for R<=15
%As = 50 for 16<=R<=25
%As = 70 for for 26<=R<=35
%Normalized frequencies
ws1 =(2*fs1)/fs;
wp1 = (2*fp1)/fs;
wp2 = (2*fp2)/fs;
ws2 = (2*fs2)/fs;
tr_width = min((wp1-ws1),(ws2-wp2))
M = ceil(11*pi/tr_width) + 1 % M is window length so filter order is M-1
n=[0:1:M-1];
wc1 = (ws1+wp1)/2;
wc2 = (wp2+ws2)/2;
hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
% Plot
stem(h);
title('Actual Impulse Response')
axis([0 M-1 -0.11 0.11]);
xlabel('n');
ylabel('h(n)')
figure;
freqz(h,[1]);
title('Magnitude Response in dB');
grid;
xlabel('frequency in pi units');
ylabel('dB')
axis([0 1 -200 10]);
Function code:
function hd = ideal_lp(wc1,M);
alpha = (M-1)/2;
n = [0:1:(M-1)];
m = n - alpha +eps;
hd = sin(wc1*m) ./ (pi*m);
function hd = ideal_lp(wc2,M);
alpha = (M-1)/2;
n = [0:1:(M-1)];
m = n - alpha +eps;
hd = sin(wc2*m) ./ (pi*m);
FA18-BEE-046
FA18-BEE-046
i) Explain with reason which filter type you would prefer based on the specification
A rectangular window type filter would be preferred based on the specification that the stop band
attenuation is 21. The minimum stop band attenuation for rectangular window is 21 while the rest of the
windows have a higher minimum stop band attenuation.
FA18-BEE-046
ii) Compute the normalized passband and stopband frequencies for filter
Stopband:
f s1 =4.3 MHz
f s 2=5.7 MHz
fs=46 MHz
Normalized frequencies:
f s1
w s 1=2× =0.1869
fs
f s2
w s 2=2× =0.2478
fs
Passband:
f p1=4.5 MHz
f p2 =5.5 MHz
Normalized frequencies:
f p1
w p1 =2× =0.1956
fs
f p2
w p 2=2× =0.2391
fs
iii) Compute the order and impulse response of the desired filter.
The order of the filter is determined by:
N= M-1
N= 3976-1
N=3975
iv) Show the results that the designed filter meets the specification.
From the given specifications and the outputs, we can say that the designed filter meets the specifications.
FA18-BEE-046