aminit;					% initialize MATLAB

%Simulation of PID control
%Notice that it is necessary to introduce filtering of the
%derivative, because Matlab will refuse pure derivative control
t=0:0.1:20;one=ones(size(t)); zero=0*one;
den=conv([1 1],[1 2 1]);
P=tf(1,den);
y=[];u=[];
for kd=[0 1 2 4],
   Tf=kd/3/10;
   C=tf([kd 2.5 1.5],conv([Tf 1],[1 0]));
   [y0,t]=step(P*C/(1+P*C),t);
   [u0,t]=step(C/(1+P*C),t);
   y=[y,y0];u=[u u0];
end

figure(1); clf;

subplot(331)
plot(t,one,'k-', 'LineWidth', AM_ref_linewidth); hold on;
pl=plot(t,y(:,1),'b-',t,y(:,2),'b-',t,y(:,3),'b-',t,y(:,4),'b-');
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 20 0 1.725]); 
%xlabel('x'); 
ylabel('y')

arcarrow([5.5 1.5], [2.5 0.7], 15)
amtext(2.5, 0.6, 'kd');

subplot(334)
plot(t,zero,'k-', 'LineWidth', AM_ref_linewidth); hold on;
pl=plot(t,u(:,1),'b-',t,u(:,2),'b-',t,u(:,3),'b-',t,u(:,4),'b-');
%set(gca,'Ytick',[0 1 2])
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 20 -2 5]); 
xlabel('x');ylabel('u');

arcarrow([8 2.5], [6.5 0.2], 15)
amtext(6, -0.6, 'kd');


amprint('pidcon.eps');
