Lab Report 2
Lab Report 2
Lab Report 2
Lab Report No 02
BEE-5B
Submitted by:
M Muzammil Nadeem
FA17-BEE-051
Submitted to:
Submission Date:
A filter shapes the frequency spectrum of the input signal, according to the magnitude of the transfer function.
The phase characteristics of the signal are also modified as it passes through the filter. Filters can be classified into
a number of categories based on which frequency bands are passed through and which frequency bands are
stopped. Figures below show ideal responses of various filters
Filter transfer function:
The filter transfer function can be written as the ratio of two polynomials:
The degree of the denominator, N, is the filter order. For the filter to be stable, N≥M. The numerator and denominator
coefficients are real numbers. The polynomials in the numerator and denominator can be factored and T(s) can be
expressed in the form:
Where, the Z’s are the zeroes and the P’s are the poles of the filter .
1. Go to MATLAB ‘Start’
2. Point to Toolboxes
3. Point to Filter Design in the sub menu
4. Click on Filter Design & Analysis Tool (fdatool)
Following are some of the parameters considered during filter design process in FDA tool:
Think of order as the measure of how much processing power our digital filter will require to be implemented.
Hence,
In-lab
Task 1
Design the low pass filter for the cut-off frequency 250Hz. Plot the filter response.
x=0.7sin(2π300t)+0.2sin(2π50t);
MATLAB code:
clear all;
close all
clc;
fs=1000;
T=1/fs;
L=fs;
t=(0:L-1)*T;
x=0.7.*sin(2.*pi.*300.*t)+0.2.*sin(2.*pi.*50.*t);
figure();
plot(t,x)
title('signal');
xlabel('time(seconds)');
NFFT=2^nextpow2(L);
X=fft(x,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2+1 );
figure();
plot(f,abs(X(1:NFFT/2+1)));
title('single sided signal');
xlabel('frequency(Hz)');
ylabel('|x(F)|');
d=fdesign.lowpass(200,250,50,100,fs);
Hd=design(d,'equiripple');
fvtool(Hd);
LP=filter(Hd,x);
figure();
plot(LP);
NFFT=2^nextpow2(L);
LPF=fft(LP,NFFT)/L;
f=fs/2.*linspace(0,1,NFFT/2+1);
figure();
plot(f,abs(LPF(1:NFFT/2+1)));
title('single sided spectrum');
xlabel('Frequency(Hz)');
ylabel('LP filtered frequency amplitude');
Task 2
Design the high pass filter for the cut-off frequency 170Hz. Plot the filter response.
MATLAB code:
clear all;
close all
clc;
fs=1000;
T=1/fs;
L=fs;
t=(0:L-1)*T;
x=0.7.*sin(2.*pi.*300.*t)+0.2.*sin(2.*pi.*50.*t)
figure();
plot(t,x)
title('signal');
xlabel('time(seconds)');
NFFT=2^nextpow2(L);
X=fft(x,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2+1 );
figure();
plot(f,abs(X(1:NFFT/2+1)));
title('single sided signal')
xlabel('frequency(Hz)')
ylabel('|x(F)')
d=fdesign.highpass(100,170,50,100,fs);
Hd=design(d,'equiripple')
fvtool(Hd);
LP=filter(Hd,x);
figure();
plot(LP);
NFFT=2^nextpow2(L);
LPF=fft(LP,NFFT)/L;
f=fs/2.*linspace(0,1,NFFT/2+1);
figure();
plot(f,abs(LPF(1:NFFT/2+1)));
title('single sided spectrum')
xlabel('Frequency(Hz)');
ylabel('LP filtered frequency amplitude')
Task 3
Design the Band-Pass filter for the frequency range 250-550Hz. Plot the filter response.
MATLAB code:
clear all;
close all
clc;
fs=2000;
T=1/fs;
L=fs;
t=(0:L-1)*T;
x=0.7.*sin(2.*pi.*300.*t)+0.2.*sin(2.*pi.*50.*t);
figure();
plot(t,x)
title('signal');
xlabel('time(seconds)');
NFFT=2^nextpow2(L)
X=fft(x,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2+1 );
figure();
plot(f,abs(X(1:NFFT/2+1)));
title('single sided signal');
xlabel('frequency(Hz)');
ylabel('|x(F)');
d=fdesign.bandpass(200,250,550,600,50,10,100,fs);
Hd=design(d,'equiripple');
fvtool(Hd);
LP=filter(Hd,x);
figure();
plot(LP);
NFFT=2^nextpow2(L);
LPF=fft(LP,NFFT)/L;
f=fs/2.*linspace(0,1,NFFT/2+1);
figure();
plot(f,abs(LPF(1:NFFT/2+1)));
title('single sided spectrum');
xlabel('Frequency(Hz)');
ylabel('LP filtered frequency amplitude');
Task 4
Design the Band-Stop filter for the frequency range, 250-550Hz. Plot the filter response.
MATLAB code:
clear all;
close all
clc;
fs=2000;
T=1/fs;
L=fs;
t=(0:L-1)*T;
x=(0.7).*sin(2.*pi.*300.*t)+(0.2).*sin(2.*pi.*50.*t);
figure();
plot(t,x)
title('signal');
xlabel('time(seconds)');
NFFT=2^nextpow2(L);
X=fft(x,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2+1 );
figure();
plot(f,abs(X(1:NFFT/2+1)));
title('single sided signal');
xlabel('frequency(Hz)');
ylabel('|x(F)');
d=fdesign.bandstop(200,250,550,600,10,50,100,fs);
Hd=design(d,'equiripple');
fvtool(Hd);
LP=filter(Hd,x);
figure();
plot(LP);
NFFT=2^nextpow2(L);
LPF=(fft(LP,NFFT))/L;
f=(fs/2).*linspace(0,1,NFFT/2+1);
figure();
plot(f,abs(LPF(1:NFFT/2+1)));
title('single sided spectrum');
xlabel('Frequency(Hz)');
ylabel('LP filtered frequency amplitude');
Task 5
Design and analyse the above filters (task 1-4) using FDA-Tool
LOW PASS FILTER:
BAND-PASS FILTER:
BAND-STOP FILTER:
Critical Analysis:
In this lab I have learnt about the different types of filter and how to design filters using the
MATLAB/SIMULINK (fda tool). In this lab I have designed four type of filters. Low pass filter which allow only
low frequency to pass. High pass filter which allows only high frequencies and block the low frequencies.
Band pass filter which allow a specific band of frequencies while band stop filters stop a specific band of
frequencies. In this lab I have used the fdesign.filtername command in MATLAB code to design the desire
filter with specifics frequencies. I have also used the FDA tool to design the filter it is easier to design a filter
using the FDA then by MATLAB code we simply have to add parameters and select filter type in FDA tool and
then click design the FDA will automatically provide the desire filter wave graph.