% frequency response of LTI systems
%
% @Kefu Xue, Ph.D., Apr. 2001
%
% 6a) frequency response and Bode plot
%
% H(s)=(s+10)/((s+100)(s+5)(s+20))
%
wr=0.1;% frequency resolution
w=0.01:wr:10000; %0.01 to 10000 radian/second
wlog=log10(w); %log base 10 frequency axis
s=j*w;
H=(s+10)./((s+100).*(s+20).*(s+5));
M=abs(H);
Phi=angle(H);
%
% using dB and log10 scale in frequency
%
Mdb=20*log10(M);% in dB
Adeg=180*Phi/pi;% in degree
figure;subplot(2,1,1);plot(wlog,Mdb);title('magnitude frequency response');
ylabel('dB');xlabel('10^( ^) radian/second');
subplot(2,1,2);plot(wlog,Adeg);title('phase frquency response');
ylabel('degree');xlabel('10^( ^) radian/second');
pause
%
% 6b) H(s)=10^4s(s+20)/((s+200)(s^2+85s+3600))
%
H=10^4*s.*(s+20)./((s+200).*(s.^2+85*s+3600));
M=abs(H);
Phi=angle(H);
Mdb=20*log10(M);% in dB
Adeg=180*Phi/pi;% in degree
figure;subplot(2,1,1);plot(wlog,Mdb);title('magnitude frequency response');
ylabel('dB');xlabel('10^( ^) radian/second');
subplot(2,1,2);plot(wlog,Adeg);title('phase frquency response');
ylabel('degree');xlabel('10^( ^) radian/second');
pause
%
wr=1;
w=0.1:wr:100000; %0.01 to 100000 radian/second
wlog=log10(w); %log base 10 frequency axis
s=j*w;
r1=100;
r2=10000;
c1=10^-5;
c2=5*c1;
wc1=(r1+r2)/(r1*r2*c1);
wc2=wc1/5;
g=r2/(r1+r2);
H1=g./(s/wc1+1);
H2=g./(s/wc2+1);
figure;subplot(2,1,1);plot(wlog,abs(H1),'r',wlog,abs(H2),'b');
legend('c=10uF','c=50uF');
title('magnitude frequency response');
ylabel('Linear scale');xlabel('10^( ^) radian/second');
subplot(2,1,2);plot(wlog,angle(H1),'r',wlog,angle(H2));
legend('c=10uF','c=50uF');
title('phase frquency response');
ylabel('radian');xlabel('10^( ^) radian/second');

pause
close all
