Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

COMSATS UNIVERSITY ISLAMABAD

Principles of Communication Systems

Lab Report No 02

Filter Designing in MATLAB: Low Pass, High Pass, Band-Pass and


Band-Stop
Semester & Section

BEE-5B

Submitted by:

M Muzammil Nadeem
FA17-BEE-051

Submitted to:

Sir Dr. Moazzam Islam Tiwana

Submission Date:

September 23, 2019


Objectives
At the end of this lab, student should be able to design the basic filters: Low Pass, High Pass, Band-Pass and Band-
Stop using MATLAB/SIMULINK.
Pre Lab
An ideal filter will have an amplitude response that is unity (or at a fixed gain) for the frequencies of interest (called
the pass band) and zero everywhere else (called the stop band). The frequency at which the response changes
from passband to stopband is referred to as the cutoff frequency. The five parameters of a practical filter are
defined in Figure 1, opposite.
• The cutoff frequency (Fc) is the frequency at which the filter response leaves the error band (or the −3 dB
point for a Butterworth response filter).
• The stop band frequency (Fs) is the frequency at which the minimum attenuation in the stopband is
reached.
• The pass band ripple (Amax) is the variation (error band) in the pass band response.
• The minimum pass band attenuation (Amin) defines the minimum signal attenuation within the stop band.
• The steepness of the filter is defined as the order (M) of the filter. M is also the number of poles in the
transfer function. A pole is a root of the denominator of the transfer function. Conversely, a zero is a root
of the numerator of the transfer function.

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 .

Filter designing using FDA tool:


FDA tool is the filter design and analysis tool in MATLAB which is used for the design and analysis of FIR or IIR filters.
It may be opened by simply typing the following command in MATLAB command window:
>>fdatool
Alternatively, it may also be opened by following the method given below:

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 is the self-explanatory diagram of FDA tool interface:

Following are some of the parameters considered during filter design process in FDA tool:

• fstop – Start of stop band


• fpass – End of pass band
• Apass – Magnitude (dB) by which pass band frequencies will be attenuated
• Astop – Magnitude (dB) by which stop band frequencies will be attenuated
• fs – Sampling frequency of the filter
– Must be greater than twice the max filter frequency
• Order – Order of the filter

Think of order as the measure of how much processing power our digital filter will require to be implemented.
Hence,

1. Sharper the cutoff, higher the order


2. Higher the fs (not fstop), higher the order

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:

HIGH 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.

You might also like