0% found this document useful (0 votes)
34 views

Aim: To Design An Analog Butterworth Low Pass Filter. Source Code

The document discusses designing analog Butterworth, Chebyshev type-1, and high/low pass filters using MATLAB code. It provides the source code to design low pass, band pass, and high pass filters for each type, requesting user input for passband ripple, stopband ripple, frequencies, and sampling frequency. The code calculates filter coefficients and plots the magnitude and phase responses.

Uploaded by

Bharat
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)
34 views

Aim: To Design An Analog Butterworth Low Pass Filter. Source Code

The document discusses designing analog Butterworth, Chebyshev type-1, and high/low pass filters using MATLAB code. It provides the source code to design low pass, band pass, and high pass filters for each type, requesting user input for passband ripple, stopband ripple, frequencies, and sampling frequency. The code calculates filter coefficients and plots the magnitude and phase responses.

Uploaded by

Bharat
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/ 12

BUTTERWORTH FILTERS

Aim: To design an analog butterworth low pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n,wn] = buttord(w1,w2,rp,rs,'s');
[z,p,k] = butter(n,wn);
[b,a] = zp2tf(z,p,k);
[b,a] = butter(n,wn,'s');
w = 0:0.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Amplitude Response');
ylabel('Gain in dB ---->');
xlabel('Normalised frequency ---->');
grid on;
subplot(2,1,2);
plot(om/pi,an);
title('Phase Response');
xlabel('Normalised frequency ---->');
ylabel('Phase in radians ---->');
grid on;

Result:

Enter the passband ripple = 0.15


Enter the stopband ripple = 60
Enter the passband frequency = 1500
Enter the stopband frequency = 3000
Enter the sampling frequency = 7000
Aim: To design an analog butterworth band pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n] = buttord(w1,w2,rp,rs);
wn = [w1 w2];
[b,a] = butter(n,wn,'bandpass','s');
w = 0:.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
title('Magnitude Response');
grid on;
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalised Frequency ---->');
ylabel('Phase in Radians ---->');
title('Phase Response');
grid on;

Result:

Enter the passband ripple = 0.3


Enter the stopband ripple = 30
Enter the passband frequency = 1000
Enter the stopband frequency = 2000
Enter the sampling frequency = 6000
Aim: To design an analog butterworth high pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n,wn] = buttord(w1,w2,rp,rs,'s');
[b,a] = butter(n,wn,'high','s');
w = 0:0.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB ---->');
xlabel('Normalised frequency ---->');
title('Amplitude Response');
grid on;
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalised frequency ---->');
ylabel('Phase in radians ---->');
title('Phase Response');
grid on;

Result:

Enter the passband ripple = 0.2


Enter the stopband ripple = 40
Enter the passband frequency = 2000
Enter the stopband frequency = 3500
Enter the sampling frequency = 8000
CHEBYSHEV FILTERS

Aim: To design an analog chebyshev type-1 low pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n,wn] = cheb1ord(w1,w2,rp,rs,'s');
[b,a] = cheby1(n,rp,wn,'s');
w = 0:0.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Magnitude Response');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
subplot(2,1,2);
plot(om/pi,an);
title('Phase Response');
xlabel('Normalised Frequency ---->');
ylabel('Phase in radians ---->');
grid on;

Result:

Enter the passband ripple = 0.2


Enter the stopband ripple = 40
Enter the passband frequency = 1300
Enter the stopband frequency = 1600
Enter the sampling frequency = 8000
Aim: To design an analog chebyshev type-1 band pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n] = cheb1ord(w1,w2,rp,rs,'s');
wn = [w1 w2];
[b,a] = cheby1(n,rp,wn,'bandpass','s');
w = 0:0.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
subplot(2,1,1);
plot(om/pi,m);
title('Magnitude Response');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
subplot(2,1,2);
plot(om/pi,an);
title('Phase Response');
xlabel('Normalised Frequency ---->');
ylabel('Phase in radians ---->');
grid on;

Result:

Enter the passband ripple = 0.2


Enter the stopband ripple = 40
Enter the passband frequency = 1500
Enter the stopband frequency = 2000
Enter the sampling frequency = 6000
Aim: To design an analog chebyshev type-1 high pass filter.

Source code:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
wp = input('Enter the passband frequency = ');
ws = input('Enter the stopband frequency = ');
fs = input('Enter the sampling frequency = ');
w1 = 2*wp/fs;
w2 = 2*ws/fs;
[n,wn] = cheb1ord(w1,w2,rp,rs,'s');
[b,a] = cheby1(n,rp,wn,'high','s');
w = 0:0.01:pi;
[h,om] = freqs(b,a,w);
m = 20*log10(abs(h));
an = angle(h);
subplot(2,1,1);
plot(om/pi,m);
subplot(2,1,1);
plot(om/pi,m);
title('Magnitude Response');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
subplot(2,1,2);
plot(om/pi,an);
title('Phase Response');
xlabel('Normalised Frequency ---->');
ylabel('Phase in radians ---->');
grid on;

Result:

Enter the passband ripple = 0.2


Enter the stopband ripple = 20
Enter the passband frequency = 1300
Enter the stopband frequency = 2000
Enter the sampling frequency = 8000

You might also like