AutotunerPID Toolkit Previous page   Next Page

bodePIDcompare

PURPOSE ^

Comparison of Bode Diagrams with different autotuning method.

SYNOPSIS ^

function bodePIDcompare(num,den,tau)

DESCRIPTION ^

BODEPIDCOMPARE Comparison of Bode Diagrams with different autotuning
   methods
   
   The function is typically called through the GUI in AutotunerPID.mdl
   and provides a graphical comparison of four different autotuning
   methods (STEP/ZN(OL), STEP/KT, STEP/IMC, RELAY/ZN(CL)) in frequency
   domain. 
   By default the parameter Ms is set to 2 in KT methods, while the
   parameter lambda is set 1/5 of the settling time of the plant.
   
   
   BODEPIDCOMPARE(NUM,DEN,TAU) performs the comparative analysis directly
   considering the plant described by the transfer function
              NUM(s)
      P(s) = -------- * exp(-TAU*s)
              DEN(s)

   See also STEPPID

   Author:    William Spinelli (wspinell@elet.polimi.it)
   Copyright  2004 W.Spinelli
   $Revision: 1.0 $  $Date: 2004/02/27 12:00:00 $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bodePIDcompare(num,den,tau)
0002 %BODEPIDCOMPARE  Comparison of Bode Diagrams with different autotuning
0003 %   methods
0004 %
0005 %   The function is typically called through the GUI in AutotunerPID.mdl
0006 %   and provides a graphical comparison of four different autotuning
0007 %   methods (STEP/ZN(OL), STEP/KT, STEP/IMC, RELAY/ZN(CL)) in frequency
0008 %   domain.
0009 %   By default the parameter Ms is set to 2 in KT methods, while the
0010 %   parameter lambda is set 1/5 of the settling time of the plant.
0011 %
0012 %
0013 %   BODEPIDCOMPARE(NUM,DEN,TAU) performs the comparative analysis directly
0014 %   considering the plant described by the transfer function
0015 %              NUM(s)
0016 %      P(s) = -------- * exp(-TAU*s)
0017 %              DEN(s)
0018 %
0019 %   See also STEPPID
0020 %
0021 %   Author:    William Spinelli (wspinell@elet.polimi.it)
0022 %   Copyright  2004 W.Spinelli
0023 %   $Revision: 1.0 $  $Date: 2004/02/27 12:00:00 $
0024 
0025 global PIDPARAMETERS
0026 
0027 % Bode diagram of the real plant model
0028 P = tf(num,den,'IODelay',tau);
0029 [m,f,w] = bode(P);
0030 w = logspace(log10(w(1)),log10(w(end)),512);
0031 s = j*w;
0032 
0033 % compute step response
0034 [y,t] = step(P);
0035 Ts = min(real(abs(pole(P))))/50;
0036 [y,t] = step(P,0:Ts:t(end));
0037 Tf = t(end);
0038 
0039 % identify a FOPDT model
0040 modelFOPDT = idareas(y,1,Ts);
0041 
0042 % identify the point of the frequency response with omega_n = -pi
0043 [Gm,Pm,Wcg,Wcp] = margin(P);
0044 modelPI.A = 2/Gm;
0045 modelPI.T = 2*pi/Wcg;
0046 
0047 % evaluate the frequency response of the plant
0048 P = squeeze(freqresp(P,w)).';
0049 
0050 % Create new figure
0051 Lfig = figure(...
0052    'Name',               'Bode diagram - Open loop function',...
0053    'NumberTitle',        'off',...
0054    'MenuBar',            'figure');
0055 Ffig = figure(...
0056    'Name',               'Bode diagram - Complementary sensitivity',...
0057    'NumberTitle',        'off',...
0058    'MenuBar',            'figure');
0059 Sfig = figure(...
0060    'Name',               'Bode diagram - Sensitivity',...
0061    'NumberTitle',        'off',...
0062    'MenuBar',            'figure');
0063 
0064 % Bode diagrams with different autotuner
0065 % Ziegler & Nichols with Step identification
0066 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'ZN (OL)',[],'PID');
0067 Rff = K*(b+1./(Ti*s));
0068 Rfb = K*(1+1./(Ti*s)+(Td*s)./(1+Td*s/N));
0069 L = Rfb.*P;
0070 F = (Rff.*P)./(ones(1,length(P))+(Rfb.*P));
0071 S = 1./(ones(1,length(P))+(Rfb.*P));
0072 figure(Lfig)
0073 subplot(211), semilogx(w,20*log10(abs(L)),'b')
0074 subplot(212), semilogx(w,unwrap(angle(L))/pi*180,'b')
0075 figure(Ffig)
0076 subplot(211), semilogx(w,20*log10(abs(F)),'b')
0077 subplot(212), semilogx(w,unwrap(angle(F))/pi*180,'b')
0078 figure(Sfig)
0079 subplot(211), semilogx(w,20*log10(abs(S)),'b')
0080 subplot(212), semilogx(w,unwrap(angle(S))/pi*180,'b')
0081 
0082 % Kappa-Tau with Ms = 2
0083 % in order to obtain better performance
0084 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'KT',2,'PID');
0085 Rff = K*(b+1./(Ti*s));
0086 Rfb = K*(1+1./(Ti*s)+(Td*s)./(1+Td*s/N));
0087 L = Rfb.*P;
0088 F = (Rff.*P)./(ones(1,length(P))+(Rfb.*P));
0089 S = 1./(ones(1,length(P))+(Rfb.*P));
0090 figure(Lfig)
0091 subplot(211), hold on, semilogx(w,20*log10(abs(L)),'r')
0092 subplot(212), hold on, semilogx(w,unwrap(angle(L))/pi*180,'r')
0093 figure(Ffig)
0094 subplot(211), hold on, semilogx(w,20*log10(abs(F)),'r')
0095 subplot(212), hold on, semilogx(w,unwrap(angle(F))/pi*180,'r')
0096 figure(Sfig)
0097 subplot(211), hold on, semilogx(w,20*log10(abs(S)),'r')
0098 subplot(212), hold on, semilogx(w,unwrap(angle(S))/pi*180,'r')
0099 
0100 % Internal Model Control with lambda = Tf/5
0101 % this means that the closed loop model is made five time faster than the
0102 % original (open loop model)
0103 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'IMC',Tf/5,'PID');
0104 Rff = K*(b+1./(Ti*s));
0105 Rfb = K*(1+1./(Ti*s)+(Td*s)./(1+Td*s/N));
0106 L = Rfb.*P;
0107 F = (Rff.*P)./(ones(1,length(P))+(Rfb.*P));
0108 S = 1./(ones(1,length(P))+(Rfb.*P));
0109 figure(Lfig)
0110 subplot(211), hold on, semilogx(w,20*log10(abs(L)),'g')
0111 subplot(212), hold on, semilogx(w,unwrap(angle(L))/pi*180,'g')
0112 figure(Ffig)
0113 subplot(211), hold on, semilogx(w,20*log10(abs(F)),'g')
0114 subplot(212), hold on, semilogx(w,unwrap(angle(F))/pi*180,'g')
0115 figure(Sfig)
0116 subplot(211), hold on, semilogx(w,20*log10(abs(S)),'g')
0117 subplot(212), hold on, semilogx(w,unwrap(angle(S))/pi*180,'g')
0118 
0119 % Ziegler & Nichols with Relay identification
0120 [K,Ti,Td,N,b] = pid_tuning(modelPI,'ZN (CL)',[],'PID');
0121 Rff = K*(b+1./(Ti*s));
0122 Rfb = K*(1+1./(Ti*s)+(Td*s)./(1+Td*s/N));
0123 L = Rfb.*P;
0124 F = (Rff.*P)./(ones(1,length(P))+(Rfb.*P));
0125 S = 1./(ones(1,length(P))+(Rfb.*P));
0126 
0127 figure(Lfig)
0128 subplot(211), semilogx(w,20*log10(abs(L)),'m')
0129 set(gca,'Position', [0.1514 0.4858 0.7536 0.3916],...
0130    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0131    'FontSize',8,...
0132    'XTickLabel',[])
0133 title('Bode Diagram - Open loop function',...
0134    'Color',[0 0 0],'FontSize',8)
0135 ylabel('Magnitude (dB)',...
0136    'Color',[0 0 0],'FontSize',8)
0137 legend('STEP + ZN(OL)','STEP + KT','STEP + IMC','RELAY + ZN(CL)',4)
0138 subplot(212), semilogx(w,unwrap(angle(L))/pi*180,'m')
0139 set(gca,'Position',[0.1514 0.1100 0.7536 0.3472],...
0140    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0141    'FontSize',8)
0142 ylabel('Phase (deg)',...
0143    'Color',[0 0 0],'FontSize',8)
0144 xlabel('Frequency (rad/sec)',...
0145     'Color',[0 0 0],'FontSize',8)
0146 
0147 figure(Ffig)
0148 subplot(211), semilogx(w,20*log10(abs(F)),'m')
0149 set(gca,'Position', [0.1514 0.4858 0.7536 0.3916],...
0150    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0151    'FontSize',8,...
0152    'XTickLabel',[])
0153 title('Bode Diagram - Complementary sensitivity function',...
0154    'Color',[0 0 0],'FontSize',8)
0155 ylabel('Magnitude (dB)',...
0156    'Color',[0 0 0],'FontSize',8)
0157 legend('STEP + ZN(OL)','STEP + KT','STEP + IMC','RELAY + ZN(CL)',4)
0158 subplot(212), semilogx(w,unwrap(angle(F))/pi*180,'m')
0159 set(gca,'Position',[0.1514 0.1100 0.7536 0.3472],...
0160    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0161    'FontSize',8)
0162 ylabel('Phase (deg)',...
0163    'Color',[0 0 0],'FontSize',8)
0164 xlabel('Frequency (rad/sec)',...
0165     'Color',[0 0 0],'FontSize',8)
0166 
0167 figure(Sfig)
0168 subplot(211), semilogx(w,20*log10(abs(S)),'m')
0169 set(gca,'Position', [0.1514 0.4858 0.7536 0.3916],...
0170    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0171    'FontSize',8,...
0172    'XTickLabel',[])
0173 title('Bode Diagram - Sensitivity function',...
0174    'Color',[0 0 0],'FontSize',8)
0175 ylabel('Magnitude (dB)',...
0176    'Color',[0 0 0],'FontSize',8)
0177 legend('STEP + ZN(OL)','STEP + KT','STEP + IMC','RELAY + ZN(CL)',4)
0178 subplot(212), semilogx(w,unwrap(angle(S))/pi*180,'m')
0179 set(gca,'Position',[0.1514 0.1100 0.7536 0.3472],...
0180    'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0181    'FontSize',8)
0182 ylabel('Phase (deg)',...
0183    'Color',[0 0 0],'FontSize',8)
0184 xlabel('Frequency (rad/sec)',...
0185    'Color',[0 0 0],'FontSize',8)

Previous page  autogui butterdesign Next page

Generated on Wed 17-Mar-2004 09:29:44 by m2html © 2003