%% Analysis of Systems with Time Delays
%% Model closed-loop system

s = tf('s');
P = 5*exp(-3.4*s)/(s+1);
C = 0.1 * (1 + 1/(5*s));
T = feedback(P*C,1);

%
%% Plot step response

stepplot(T)

%
%% Model more complex closed-loop system

F = 0.3/(s+4);
P.InputName = 'u';  
P.OutputName = 'y';
C.InputName = 'e';  
C.OutputName = 'uc';
F.InputName = 'r';  
F.OutputName = 'uf';
Sum1 = sumblk('e','r','y','+-');    % e = r-y
Sum2 = sumblk('u','uf','uc','++');  % u = uf+uc
Tff = connect(P,C,F,Sum1,Sum2,'r','y');

%
%% Compare step responses

stepplot(T,Tff)
legend('No feedforward','Feedforward')

%
%% Gain ripple illustration

s = tf('s');
G = exp(-5*s)/(s+1);
T = feedback(G,.5);
bodemag(T)

%
%% Gain oscillations illustration

G = 1 + 0.5 * exp(-3*s);
bodemag(G)

%
%% Jagged step response illustration

G = exp(-s) * (0.8*s^2+s+2)/(s^2+s);
T = feedback(G,1);
stepplot(T)

%
%% Chaotic response illustration

G = 1/(s+1) + exp(-4*s);
T = feedback(1,G);
stepplot(T,150)

% Copyright 2015 The MathWorks, Inc.