Sunday, October 16, 2011

IIR ELLIPTIC

% LPF
clc;
clear;
close all;
%LPF of cut off 500Hz
fp=500;
fs=600;
samp=2000;
ap=.5;
as=40;
wp=fp/(samp/2);
ws=fs/(samp/2);
[N,wn]=ellipord(wp,ws,ap,as);
[b,a]=ellip(N,ap, as,wn);
[H,W]=freqz(b,a,256);
plot(W/(2*pi),20*log10(abs(H)))
n=0:1/samp:1;
x=cos(2*pi*200*n)+cos(2*pi*700*n);
figure
subplot 211, plot(n,abs(fft(x)))
y=filter(b,a,x);
subplot 212, plot(n,abs(fft(y)))



% HPF
clc;
clear;
close all;
%HPF of cut off 500Hz
fs=500;
fp=600;
samp=2000;
ap=.5;
as=40;
wp=fp/(samp/2);
ws=fs/(samp/2);
[N,wn]=ellipord(wp,ws,ap,as);
[b,a]=ellip(N,ap, as,wn,'high');
[H,W]=freqz(b,a,256);
plot(W/(2*pi),20*log10(abs(H)))
n=0:1/samp:1;
x=cos(2*pi*200*n)+cos(2*pi*700*n);
figure
subplot 211, plot(n,abs(fft(x)))
y=filter(b,a,x);
subplot 212, plot(n,abs(fft(y)))




%BPF
clc;
clear;
close all;
%BPF of pass 400-600Hz
fs1=300;
fp1=400;
fp2=600;
fs2=700;
samp=2000;
ap=.5;
as=40;
wp=[fp1 fp2]/(samp/2);
ws=[fs1 fs2]/(samp/2);
[N,wn]=ellipord(wp,ws,ap,as);
[b,a]=ellip(N,ap, as,wn,'bandpass');
[H,W]=freqz(b,a,256);
plot(W/(2*pi),20*log10(abs(H)))
n=0:1/samp:1;
x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n);
figure
subplot 211, plot(n,abs(fft(x)))
y=filter(b,a,x);
subplot 212, plot(n,abs(fft(y)))



%BSF
clc;
clear;
close all;
%BSF of stop 400-600Hz
fp1=300;
fs1=400;
fs2=600;
fp2=700;
samp=2000;
ap=.5;
as=40;
wp=[fp1 fp2]/(samp/2);
ws=[fs1 fs2]/(samp/2);
[N,wn]=ellipord(wp,ws,ap,as);
[b,a]=ellip(N,ap, as,wn,'stop');
[H,W]=freqz(b,a,256);
plot(W/(2*pi),20*log10(abs(H)))
n=0:1/samp:1;
x=cos(2*pi*200*n)+cos(2*pi*500*n)+cos(2*pi*800*n);
figure
subplot 211, plot(n,abs(fft(x)))
y=filter(b,a,x);
subplot 212, plot(n,abs(fft(y)))

No comments: