You are on page 1of 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;

alphap=12. ylabel('phase in radians').wn.'whole').'bandpass'). PROGRAM FOR BUTTERWORTH BAND PASS FILTER close all.1.2). subplot(2.w]=freqz(b. [n.wi. [b. ws=[. xlabel('normalised frequency').clc.plot(m/pi.phase). wp=[.1.ws/pi.. w=0:.clear all.an).alphas). as=20.1).wn]=buttord(wp/pi. ap=2. an=angle(ph).1..as). wp=[. [h.wn.01:pi. [ph. [n. subplot(2. phase=angle(h). g=20*log10(abs(ph)).1*pi..g).clear all.xlabel('normalised frequency').a]=butter(n.2*pi. ylabel('magnitude in db').ws/pi.2*pi. xlabel('normalised frequency').grid.wn]=buttord(wp/pi.ap.1).4*pi].5*pi].1. alphas=40. PROGRAM FOR BUTTERWORTH BAND STOP FILTER close all.'stop'). wi=0:.grid.alphap. m=20*log10(abs(h)).4*pi]. [b.1*pi.plot(m/pi.5*pi].grid. ws=[.2).ylabel('phase in radians').xlabel('normalised frequency'). .a. ylabel('gain in db').plot(w/pi.w).clc. subplot(2.01:pi.m).m]=freqz(b.plot(w/pi. subplot(2.a]=butter(n.a.grid..

subplot(2. .a]=cheby1(n.ph]=freqz(b. als=50.alp. [h.wn). als=50. a=angle(h). ylabel('phase in radians'). [n.a. wp=0. subplot(2. ylabel('gain in db').cos/pi.1).1. Program for cheby1 high pass filter clear all. ylabel('gain in db'). ws=0.'high').als).wn]=cheb1ord(cop/pi.1.grid.2*pi.als).wn.w). [h.xlabel('normalised frequency').a.01:pi.1). alp=20.a]=cheby1(n.wn]=cheb1ord(wp/pi. xlabel('normalised frequency').3*pi. m=20*log10(abs(h)). [b. xlabel('normalised frequency').alp. alp=20. subplot(2. cos=0.01:pi. cop=0. w=0:. [n. [b.ws/pi.grid.3*pi. an=angle(h).alp.ph]=freqz(b. m=20*log10(abs(h)).xlabel('normalised frequency').alp.1.m).2).plot(ph/pi.m). Program for cheby1 low pass filter clear all.plot(ph/pi.2*pi.ylabel('phase in radians').w).plot(ph/pi.a).grid. w=0:.

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

xlabel('normalised frequency'). h=freqz(b. w=0:. hn = hd*wr. h=freqz(b. hd=sin(wc*(n-alpha + eps))/(pi *(n-alpha + eps)).001. wc = 0. b=fir1(N. w=0:.blackman(N+1)).w).hamming(N+1)).w). xlabel('Normalised Frequency'). N=25.ylabel('phase in radians'). w=0:0.01:pi.wc/pi.1.01:pi. wc=.01:pi.wc/pi. plot(w/pi. hold off Hamming And Rectangular Window clear all.abs(h). n=0:1:N-1. plot(w/pi.5*pi.'-'). hold on b=fir1(N. . h=freqz(hn. N=25.1. eps=0.1.w).5 *pi. wr = boxcar(N). abs(h)). alpha=(N-1)/2. ylabel('Magnitude'). Hamming And Blackman Window clear all.

.abs(h)).abs(h). xlabel('Normalised Frequency').'-').1. xlabel('Normalised Frequency').1. h=freqz(hn. hold on wh=hamming(N).w).5333514). grid.512). plot(w/pi.omega]=freqz(b.01:pi. ylabel('Magnitude'). b=fir1(60. hn=hd*wh. ylabel('gain in db'). mag=20*log10(abs(h)).3.grid. w=0:0. [h. hold off Kaiser Window format long.4. . kw=kaiser(61.kw).mag).plot(w/pi. plot(omega/pi.