% m-file for simulating integrator+time delay example
% controlled with a PI controller
% Example 3.3 lecture notes
clear all

k=1; tau=1;

itun=2;
if itun == 1
  Kp=1/(2*k*tau); Ti=8*tau;   % 1) SIMC settings for a PI controller
elseif itun == 2
    Kp=1/(2*k*tau); Ti=4*tau;
elseif itun == 3
  Kp=1/(2*k*tau); Ti=6*tau;   % 3) Setting deduced in lect. notes
end

% Using MATLAB functions
s=tf('s');
%hp=k*(1-tau*s)/s;           % Process stransfer function
hp=k*(1-tau*s/2)/((1+tau*s/2)*s); % Pade approx
hc=Kp*(1+Ti*s)/(Ti*s);      % PI controller transfer function

h0=series(hc,hp);           % Define product, h0=hc*hp

h_yr=feedback(h0,1);        % Define: y/r=h0/(1+h0)
figure(1)
step(h_yr)                  % Unit step in, r, at time 0.

%h_yv=feedback(hp,-hc,+1);   % Define: y/v=hp/(1+hc*hp)
h_yv=feedback(hp,hc);
figure(2)
step(h_yv)
