0% found this document useful (0 votes)
39 views

AIM Apparatus: Fir Filters

The document describes designing FIR and IIR filters using MATLAB. It presents the code to design low pass and high pass filters for both FIR and IIR cases. For FIR filters, the code takes user input for passband ripple, stopband ripple, frequencies and designs the filter using fir1. For IIR filters, it similarly takes user input, uses buttord to design the filter order and type, and designs the filter using butter. It then plots the magnitude and phase response of the designed filters.

Uploaded by

Divya Santoshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

AIM Apparatus: Fir Filters

The document describes designing FIR and IIR filters using MATLAB. It presents the code to design low pass and high pass filters for both FIR and IIR cases. For FIR filters, the code takes user input for passband ripple, stopband ripple, frequencies and designs the filter using fir1. For IIR filters, it similarly takes user input, uses buttord to design the filter order and type, and designs the filter using butter. It then plots the magnitude and phase response of the designed filters.

Uploaded by

Divya Santoshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Expt no : Date:

FIR FILTERS

AIM: To design FIR fiters.
APPARATUS:1.MATLAB r2009b software.
2.PC.
THEORY:
PROGRAM:
clc;
close all;
clear all;
display(enter the filter choice);
display(1.low pass filter.);
display(2.high pass filter.);
fc=input(enter the choice of the filter:);
if(fc>2||fc<1)
display(wrong statement);
end
rp=input(enter pass band ripples:);
rs=input(enter stop band ripples:);
fp=input(enter passband frequency:);
fs=input(enter stopband frequency:);
f=input(enter sampling frequency :);
wp=2*fp/f;
ws=2*fs/f;
n=ceil(-20*log(sqrt((rp-rs))-13/14.6*((fs-fp)/f));
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=rectwin(n);
if(fc=1)
b=fir1(n,wp);
elseif(fc==2)
b=fir1(n,wp,high);
end
[h,m]=freqz(b);
m1=20*log(abs(h));
subplot(2,1,1);
plot(m/pi,m1);
xlabel(normalised frequency);
ylabel(gain);
title(magnitude response);
p=angle(h);
subplot(2,1,2);
plot(m/pi,p);
xlabel(normalised frequency);
ylabel(phase);
title(phase response);

RESULT:



Expt no : Date:
IIR FILTERS

AIM: To design IIR fiter using butterworth windowing technique.
APPARATUS:1.MATLAB r2009b software.
2.PC.
THEORY:
PROGRAM:
clc;
close all;
clear all;
display(enter the filter choice);
display(1.analog filter.);
display(2.digital filter.);
ft=input(enter the choice of the filter:);
if(ft>2||ft<1)
display(wrong statement);
end
display(enter the filter type:);
display(1.low pass filter.);
display(2.high pass filter.);
fc=input(enter the choice of the filter type:);
if(fc>2||fc<1)
display(wrong statement);
end
rp=input(enter pass band ripples:);
rs=input(enter stop band ripples:);
fp=input(enter passband frequency:);
fs=input(enter stopband frequency:);
f=input(enter sampling frequency :);
wp=2*fp/f;
ws=2*fs/f;
if(ft==1)
if(fc==1)
[n,wc]=buttord(wp,ws,rp,rs,s);
[b,a]=butter(n,wc,low,s);
else
[n,wc]=buttord(wp,ws,rp,rs,s);
[b,a]=butter(n,wc,high,s);
end
elseif(ft==2)
if(fc==1)
[n,wc]=buttord(wp,ws,rp,rs,s);
[b,a]=butter(n,wc,low,s);
else
[n,wc]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wc,high);
end
end
if(ft==1)
[h,m]=freqs(b,a);
else
[h,m]=freqz(b,a);
end
m1=20*log(abs(h));
a1=angle(h);
subplot(2,1,1);
plot(m/pi,m1);
xlabel(normalised frequency);
ylabel(gain);
title(magnitude response);
a1=angle(h);
subplot(2,1,2);
plot(m/pi,a1);
xlabel(normalised frequency);
ylabel(phase);
title(phase response);

RESULT:

You might also like