%Procedure for the design of Butterworth %lowpass filter %Changable parameters------ clc;clear; wp=10;ws=20;Gp=-2;Gs=-20; %-------------------------- %step-1:Determine the order of the filter,n P1=-Gs/10;P2=-Gp/10;Wsp=ws/wp; nc=log((10^P1 -1)/(10^P2 -1))/(2*log(Wsp)); n=ceil(nc); %step-2:Dertermine the cuttoff frequency,wc %(options that satisfy PB or SB) Wc=wp/(10^P2 -1)^(1/(2*n)); %Wc=ws/(10^P1 -1)^(1/(2*n)); %step-3:Determination of the normalize tsfc H(s) s=zeros(1,n); for k=1:n A=(2*k-1+n)/(2*n); Sk=cos(A*pi)+j*sin(A*pi); s(k)=Sk; end %s=s.'; num1=[0 1];den1=poly(s); %step-4:Determine the final filter tsfc H(s) num2=[0 Wc^n];den2=poly([Wc.*s]); fprintf('Filter Order is n=%i\n',n); fprintf('Cutoff Frequency is Wc=%.4f\n',Wc); disp('Poles of the transfer function are');s.' fprintf('The normalize %ith-order transfer function is',n); printsys(abs(num1),abs(den1)); disp('The transfer function with s replaced by s/Wc is'); printsys(abs(num2),abs(den2)); %step-5:Amplitude reponse of the filter %w=0:0.01:40; [mag,phase,w]=bode(abs(num2),abs(den2)); figure(1);subplot(211);plot(w,mag);grid; axis([0 5*Wc 0 1]); subplot(212);plot(w,phase);grid; figure(2);bode(abs(num2),abs(den2));grid on;