%% Time-Delay Approximation in Continuous-Time Closed-Loop Model
%% Construct closed-loop model

s = tf('s');
G = (s+1)/(s^2+.68*s+1)*exp(-4.2*s);
C = pid(0.06,0.15,0.006);
Tcl = feedback(G*C,1);

%
%% Examine internal delay

Tcl.InternalDelay

%
%% First-order approximation

Tnd1 = pade(Tcl,1);

%
%% Compare frequency responses

h = bodeoptions;
h.PhaseMatching = 'on';
bodeplot(Tcl,'-b',Tnd1,'-.r',{.1,10},h);
legend('Exact delay','First-Order Pade','Location','SouthWest');

%
%% Compare time-domain responses

stepplot(Tcl,'-b',Tnd1,'-.r');
legend('Exact delay','First-Order Pade','Location','SouthEast');

%
%% Increase approximation order

Tnd3 = pade(Tcl,3);

%
%% Compare new frequency response

bodeplot(Tcl,'-b',Tnd3,'-.r',Tnd1,'--k',{.1,10},h);
legend('Exact delay','Third-Order Pade','First-Order Pade',...
       'Location','SouthWest');

% Copyright 2015 The MathWorks, Inc.