% ex33_laplace2.m
% Purpose: 
% -Illustrate Example 3.3
% -Alternative m-file for the responses
clear all % Clear memory to avoid possible "conflicts"

s=tf('s'); % Define symbolically the Laplace operator s

% Chemical Reactor linearized Process model
K=2/125; T1=1/125; T2=T1; tau=1/250;
% Using approx: e^(-tau*s)=1-tau*s
hp=K*(1-tau*s)/((1+T1*s)*(1+T2*s));

% The PI controller:
% -1st order model approx, hp=K*(1-tau*s)/(1+T*s)
% -using the half rule for model reduction
T=T1+T2/2;
tau=tau+T2/2;
% SIMC PI-controller settings
Kp=T/(2*K*tau)
Ti=min(T,8*tau)

hc=Kp*(1+Ti*s)/(Ti*s);

% The loop transfer function
h0=hc*hp;

% Set-point response from r to y
h_yr=h0/(1+h0);
figure(1), step(h_yr), grid
title('Set-point response: Unit step response from r to y')

% Disturbance response from v to y
h_yv=hp/(1+h0);
figure(2), step(h_yv), grid
title('Disturbance load response: Unit step response from v to y')
