Sunteți pe pagina 1din 6

PROGRAM FOR BUTTERWORTH LOW PASS FILTER

close all;clc;clear all;


alphap=04;
alphas=30;
fp=400;
fs=800;
F=2000;
omp=2*fp/F;oms=2*fs/F;
[n,wn]=buttord(omp,oms,alphap,alphas);
[b,a]=butter(n,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(om/pi,m);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(om/pi,an);grid;
ylabel('phase in radians');
xlabel('normalised frequency');

PROGRAM FOR BUTTERWORTH HIGH PASS FILTER


close all;clc;clear all;
alphap=04;
alphas=30;
fp=400;
fs=800;
F=2000;
omp=2*fp/F;oms=2*fs/F;
[n,wn]=buttord(omp,oms,alphap,alphas);
[b,a]=butter(n,wn,'HIGH');
w=0:.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);plot(om/pi,m);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(om/pi,an);grid;

ylabel('phase in radians');
xlabel('normalised frequency');

PROGRAM FOR BUTTERWORTH BAND STOP FILTER


close all;clc;clear all;
ap=2;
as=20;
ws=[.2*pi,.4*pi];
wp=[.1*pi,.5*pi];
[n,wn]=buttord(wp/pi,ws/pi,ap,as);
[b,a]=butter(n,wn,'stop');
wi=0:.01:pi;
[h,w]=freqz(b,a,wi,'whole');
m=20*log10(abs(h));
phase=angle(h);
subplot(2,1,1);plot(w/pi,m);grid;
ylabel('magnitude in db');xlabel('normalised frequency');
subplot(2,1,2);plot(w/pi,phase);grid;
ylabel('phase in radians');
xlabel('normalised frequency');

PROGRAM FOR BUTTERWORTH BAND PASS FILTER


close all;clc;clear all;
alphap=12;
alphas=40;
wp=[.2*pi,.4*pi];
ws=[.1*pi,.5*pi];
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
[b,a]=butter(n,wn,'bandpass');
w=0:.01:pi;
[ph,m]=freqz(b,a,w);
g=20*log10(abs(ph));
an=angle(ph);
subplot(2,1,1);plot(m/pi,g);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(m/pi,an);grid;

ylabel('phase in radians');
xlabel('normalised frequency');

Program for cheby1 low pass filter


clear all;
alp=20;
als=50;
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,alp,als);
[b,a]=cheby1(n,alp,wn);
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
a=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(ph/pi,a);grid;
ylabel('phase in radians');
xlabel('normalised frequency');

Program for cheby1 high pass filter


clear all;
alp=20;
als=50;
cop=0.2*pi;
cos=0.3*pi;
[n,wn]=cheb1ord(cop/pi,cos/pi,alp,als);
[b,a]=cheby1(n,alp,wn,'high');
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('gain in db');xlabel('normalised frequency');

subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('phase in radians');
xlabel('normalised frequency');

Program for cheby1 bandstop filter


clear all;
alp=20;
als=60;
wp=[.2*pi,.4*pi];
ws=[.1*pi,.5*pi];
[n,wn]=cheb1ord(wp/pi,ws/pi,alp,als);
[b,a]=cheby1(n,alp,wn,'stop');
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
a=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(ph/pi,a);grid;
ylabel('phase in radians');
xlabel('normalised frequency');

Program for cheby1 bandstop filter


clear all;
alp=20;
als=40;
wp=[.2*pi,.4*pi];
ws=[.1*pi,.5*pi];
[n,wn]=cheb1ord(wp/pi,ws/pi,alp,als);
[b,a]=cheby1(n,alp,wn,'bandpass');
w=0:.01:pi;
[ph,m]=freqz(b,a,w);
g=20*log10(abs(ph));
an=angle(ph);
subplot(2,1,1);plot(m/pi,g);grid;
ylabel('gain in db');xlabel('normalised frequency');
subplot(2,1,2);plot(m/pi,an);grid;

ylabel('phase in radians');
xlabel('normalised frequency');

Hamming And Blackman Window


clear all;
wc = 0.5 *pi;
N=25;
b=fir1(N,wc/pi,hamming(N+1));
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi, abs(h));
hold on
b=fir1(N,wc/pi,blackman(N+1));
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi,abs(h),'-');
ylabel('Magnitude');
xlabel('Normalised Frequency');
hold off

Hamming And Rectangular Window


clear all;
wc=.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha + eps))/(pi *(n-alpha + eps));
wr = boxcar(N);
hn = hd*wr;
w=0:0.01:pi;
h=freqz(hn,1,w);

plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd*wh;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-'); grid;
ylabel('Magnitude'); xlabel('Normalised Frequency');
hold off

Kaiser Window
format long;
kw=kaiser(61,4.5333514);
b=fir1(60,.3,kw);
[h,omega]=freqz(b,1,512);
mag=20*log10(abs(h));
plot(omega/pi,mag);grid;
xlabel('Normalised Frequency');
ylabel('gain in db');

S-ar putea să vă placă și