AIM Apparatus: Fir Filters
AIM Apparatus: Fir Filters
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: