MATLAB codes
MATLAB codes
Design a 6th order Butterworth filter with cutoff frequency 300 Hz for which data sampled at 1000
Hz for low pass, high pass, band pass & band stop filter using fv tool.
Code 1 (Butter):
close all;
clear all;
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
[h,w]=freqz(b,a);
[b2,a2] = butter(6,fc/(fs/2),'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = butter(3,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = butter(3,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter')
Elliptic Filter:
Design a 6th-order low pass, high pass, band pass & band stop elliptic filter with 5 dB of pass-
band ripple, 40 dB of stop-band attenuation, and a pass-band edge frequency of 300 Hz, which,
for data sampled at 1000 Hz, corresponds to rad/sample using fv tool.
Code 2:
[b,a] = ellip(6,5,40,0.6);
[h,w]= freqz(b,a);
[b2,a2] = ellip(6,5,40,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = ellip(3,5,50,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = ellip(3,5,50,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend(' ellip')
Code 3:
fc = 300;
fs = 1000;
[b,a] = cheby1(6,10,0.6);
[h,w]=freqz(b,a);
[b2,a2] = cheby1(6,10,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(3,5,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby1(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('cheby1')
Code 4:
clc
close all
clear all
fc = 300;
fs = 1000;
[b,a] = cheby2(6,10,0.6);
[h,w]=freqz(b,a);
[b2,a2] = cheby2(6,10,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby2(3,5,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);figue(1);
plot(w/pi,20*log(abs(h)));
figue(2);
plot(w2/pi,20*log(abs(h2)));
figue(3);
plot(w3/pi,20*log(abs(h3)));
figue(4);
plot(w4/pi,20*log(abs(h4)));
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('cheby2')
Design a 6th-order low pass for Butterworth, Elliptic, Chebyshev Type I & Chebyshev Type II
filter with 10 dB of passband ripple and a passband edge frequency of 300 Hz, which, for data
sampled at 1000 Hz, corresponds to rad/sample using fv tool.
Code 5:
clc
clear all
close all
n=6;
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
[h,w]=freqz(b,a);
[b2,a2] = ellip(6,5,40,0.6);
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(6,10,0.6);
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(6,10,0.6);
[h4,w4]=freqz(b4,a4);
plot(w/pi,20*log(abs(h)));
hold on
plot(w2/pi,20*log(abs(h2)));
plot(w3/pi,20*log(abs(h3)));
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter','ellip','cheby1','cheby2')
Design a 6th-order band pass for Butterworth, Elliptic, Chebyshev Type I & Chebyshev Type II
filter with 10 dB of passband ripple and a passband edge frequency of 300 Hz, which, for data
sampled at 1000 Hz, corresponds to rad/sample using fv tool.
Code 6:
clc
clear all
close all
n=6;
fc = 300;
fs = 1000;
[b,a] = butter(3,[0.2 0.6],'bandpass');
[h,w]=freqz(b,a);
[b2,a2] = ellip(3,5,50,[0.2 0.6],'bandpass');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(3,5,[0.2 0.6],'bandpass');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
plot(w/pi,20*log(abs(h)));
hold on
plot(w2/pi,20*log(abs(h2)));
plot(w3/pi,20*log(abs(h3)));
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter','ellip','cheby1','cheby2')