%
% Figure 17.8
%
yo = 200;
%
uo = 2;
%
tau1 = 20;
tau2 = 150;
dt = 1;
gain = 25;
%
y = yo;
yd = yo + 5;
yhat1 = 0;
yhat2 = 0;
u = uo;
yy = [];
uu = [];
%
kp = 0.40;
%
for i = 1:200,
   e = yd - y;
   u = uo + kp * e;
   uu = [ uu; u ];
   uhat = u - uo;
   yhat1 = yhat1 * ( tau1 - dt ) / tau1 + ...
            uhat * dt / tau1;
   yhat2 = yhat2 * ( tau2 - dt ) / tau2 + ...
            yhat1 * gain * dt / tau2;
   y = yhat2 + yo;
   yy = [ yy; y ];
end;
%
plot( [ yy ] );
set( gca, 'fontsize', 16 );
axis( [ 0 200 199 207.5 ] );
xlabel( 'Time in minutes' );
ylabel( 'Sensor signal' );
hold on;
%
ki = 0.005;
esum = 0;
%
y = yo;
yd = yo + 5;
yhat1 = 0;
yhat2 = 0;
u = uo;
yy = [];
uu = [];
%
for i = 1:200,
   e = yd - y;
   esum = esum + e * dt;
   u = uo + kp * e + ki * esum;
   uu = [ uu; u ];
   uhat = u - uo;
   yhat1 = yhat1 * ( tau1 - dt ) / tau1 + ...
            uhat * dt / tau1;
   yhat2 = yhat2 * ( tau2 - dt ) / tau2 + ...
            yhat1 * gain * dt / tau2;
   y = yhat2 + yo;
   yy = [ yy; y ];
end;
%
plot( [ yy ] );
hold off;
%
h = line( [ 0 200 ], [ 205 205 ] );
set( h, 'linestyle', '--', 'color', 'k' );
arrow( [ 150 206 ], [ 170 205.2 ] );
h = text( 100, 206, 'PI control' );
set( h, 'fontsize', 16 );
arrow( [ 150 203.5 ], [ 170 204.5 ] );
h = text( 100, 203.5, 'P control' );
set( h, 'fontsize', 16 );
%
print -f1 -deps2 fig17-8.eps
%

