Butterworth, Chebyshev I/II and Elliptic filters in MATLAB

by Forrest Sheng Bao http://fsbao.net

% Copyleft (C) Forrest Sheng Bao 1984-2009 http://fsbao.net
% with Dept. of Electrical and Computer Engineering and Dept. of Computer Science, Texas Tech University, Lubbock, Texas, USA
%
% This program shows the order and frequency/phase properties of four different kinds of filters, Butterworth, Chebyshev Type I, Chebyshev Type II and Elliptic.
% The filter is expected to have a cutoff frequency at 200 Hz with attenuation 40 db/octave. The sampling frequency is 2000 Hz.
%
% This program is a free software.
% It is licensed in GNU GENERAL PUBLIC LICENSE (GPL) v3 or later.
% So this program comes with ABSOLUTELY NO WARRANTY.
%
% You have the rights to freely COPY, MODIFY and REDISTRIBUTE this program under the terms of GNU GPL v3 or later, including KEEP the modified
% and/or redistributed code in GNU GPL v3 or later.
%
% If you do not know what GNU GPL is, please visit http://www.gnu.org/copyleft/gpl.html

close all
clear all

cutoff = 200;
Fs = 2000;
wp = cutoff/(Fs/2);
ws = 400/(Fs/2);
rp = 3;
rs = 43;
for i=1:4
if i == 1
[order, wn] = buttord(wp, ws, rp, rs);
sprintf('the min. order of Butterworth filter is %d', order)
[b,a] = butter(order,wn);
figure()
freqz(b,a,512,Fs)
title('Butterworth filter, attenuation = 40 db/octave, cutoff=200')
elseif i==2
[order, wn] = cheb1ord(wp, ws, rp, rs);
sprintf('the min. order of Chebyshev Type 1 filter is %d', order)
[b,a] = cheby1(order,rp,wn);
figure()
freqz(b,a,512,Fs)
title('Chebyshev Type I filter, attenuation = 40 db/octave, cutoff=200')
elseif i==3
[order, wn] = cheb2ord(wp, ws, rp, rs);
sprintf('the min. order of Chebyshev Type II filter is %d', order)
[b,a] = cheby2(order,rp,wn);
figure()
freqz(b,a,512,Fs)
title('Chebyshev Type II filter, attenuation = 40 db/octave, cutoff=200')
elseif i==4
[order, wn] = ellipord(wp, ws, rp, rs);
sprintf('the min. order of elliptic filter is %d', order)
[b,a] = ellip(order,rp,rs,wn);
figure()
freqz(b,a,512,Fs)
title('Elliptic filter, attenuation = 40 db/octave, cutoff=200')
else
disp('error')
end
end
ans =

the min. order of Butterworth filter is 7

ans =

the min. order of Chebyshev Type 1 filter is 4

ans =

the min. order of Chebyshev Type II filter is 4

ans =

the min. order of elliptic filter is 3

Plot images are omitted here. Please run the code to get them.

No comments: