0% found this document useful (0 votes)
56 views4 pages

Lab 67

The document contains code for designing and analyzing four types of Butterworth filters: high pass, low pass, band pass, and band stop. The code uses MATLAB functions like buttord, butter, and freqz to design the filters based on user-specified parameters like passband/stopband frequencies and ripples. It then generates plots of the magnitude and phase response of each designed filter.

Uploaded by

Somesh roy
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)
56 views4 pages

Lab 67

The document contains code for designing and analyzing four types of Butterworth filters: high pass, low pass, band pass, and band stop. The code uses MATLAB functions like buttord, butter, and freqz to design the filters based on user-specified parameters like passband/stopband frequencies and ripples. It then generates plots of the magnitude and phase response of each designed filter.

Uploaded by

Somesh roy
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/ 4

High Pass Filter

1. %Butterworth High Pass Filter


2. clc;
3. close all;
4. clear all;
5. format long;
6. rp=input('enter the passband ripple:(default:0.2)');
7. rs=input('enter the stopband ripple:(default:40)');
8. wp=input('enter the passband frequency:(default:2000)');
9. ws=input('enter the stopband frequency:(default:3500)');
10. fs=input('enter the sampling frequency:(default:8000)');
11. w1=2*wp/fs;
12. w2=2*ws/fs;
13. [n,wn]=buttord(w1,w2,rp,rs,'s');
14. [z,p,k]= butter(n,wn);
15. [b,a]=butter(n,wn,'high','s');
16. w=0:0.01:pi;
17. [h,om]=freqs(b,a,w);
18. m=20*log10(abs(h));
19. an=angle(h);
20. subplot(2,1,1);
21. plot(om/pi,m);
22. ylabel('gain in db--------->');
23. xlabel('(a) normalized freq------>');
24. subplot(2,1,2);
25. plot(om/pi,an);
26. ylabel('phase in db--------->');
27. xlabel('(b) normalized freq------>');
Low Pass Filter

1. %Butterworth low Pass Filter


2. clc;
3. close all;
4. clear all;
5. format long;
6. rp=input('enter the passband ripple:(default:0.15)');
7. rs=input('enter the stopband ripple:(default:60)');
8. wp=input('enter the passband frequency:(default:1500)');
9. ws=input('enter the stopband frequency:(default:3000)');
10. fs=input('enter the sampling frequency:(default:7000)');
11. w1=2*wp/fs;
12. w2=2*ws/fs;
13. [n,wn]=buttord(w1,w2,rp,rs,'s');
14. [z,p,k]= butter(n,wn);
15. [b,a]=butter(n,wn,'s');
16. w=0:0.01:pi;
17. [h,om]=freqs(b,a,w);
18. m=20*log10(abs(h));
19. an=angle(h);
20. subplot(2,1,1);
21. plot(om/pi,m);
22. ylabel('gain in db--------->');
23. xlabel('(a) normalized freq------>');
24. subplot(2,1,2);
25. plot(om/pi,an);
26. ylabel('phase in db--------->');
27. xlabel('(b) normalized freq------>')
Band Pass Filter

1. clear all
2. alphap=2; %passband attenuation in dB
3. alphas=20; %stopband attenuation in dB
4. wp=[.2*pi,.4*pi]; % passband freq. in radians
5. ws=[.1*pi,.5*pi]; % stopband freq. in radians
6. %to find cutoff freq. and order of the filter
7. [n,wn]=buttord(wp/pi,ws/pi,alphap,alphas); %syatem function of the filter
8.
9.
10. [b,a]=butter(n,wn);
11. w=0:.01:pi;
12. [h,ph]=freqz(b,a,w);
13. m=20*log10(abs(h));
14. an=angle(h);
15. subplot(2,1,1);plot(ph/pi,m);grid;
16. ylabel('Gain in dB');
17. xlabel('NORMALISED FREQUENCY');
18. subplot(2,1,2);plot(ph/pi,an);grid
19. ylabel('phase in radians');
20. xlabel('noramlised frequency');
Band Stop Filter

1. clear all
2. alphap=2; %passband attenuation in dB
3. alphas=20; %stopband attenuation in dB
4. wp=[.2*pi,.4*pi]; % passband freq. in radians
5. ws=[.1*pi,.5*pi]; % stopband freq. in radians
6. %to find cutoff freq. and order of the filter
7. [n,wn]=buttord(wp/pi,ws/pi,alphap,alphas); %syatem function of the filter
8. [b,a]=butter(n,wn,'STOP');
9. w=0:.01:pi;
10.
11.
12. [h,ph]=freqz(b,a,w);
13. m=20*log(abs(h));
14. an=angle(h);
15. subplot(2,1,1);plot(ph/pi,m);grid;
16. ylabel('Gain in dB');
17. xlabel('NORMALISED FREQUENCY')
18. subplot(2,1,2);plot(ph/pi,an);grid
19. ylabel('phase in radians');
20. xlabel('noramlised frequency')

You might also like