Documentation Center 
How to create models that include time delays.
Use the following model properties to represent time delays in linear systems.
InputDelay, OutputDelay — Time delays at system inputs or outputs
ioDelay, InternalDelay — Time delays that are internal to the system
In discretetime models, these properties are constrained to integer values that represent delays expressed as integer multiples of the sampling time. To approximate discretetime models with delays that are a fractional multiple of the sampling time, use thiran.
This example shows how to create a first order plus dead time model using the InputDelay or OutputDelay properties of tf.
To create the following firstorder transfer function with a 2.1 s time delay:
enter:
G = tf(1,[1 10],'InputDelay',2.1)
where InputDelay specifies the delay at the input of the transfer function.
Tip You can use InputDelay with zpk the same way as with tf: G = zpk([],10,1,'InputDelay',2.1) 
For SISO transfer functions, a delay at the input is equivalent to a delay at the output. Therefore, the following command creates the same transfer function:
G = tf(1,[1 10],'OutputDelay',2.1)
Use dot notation to examine or change the value of a time delay. For example, change the time delay to 3.2 as follows:
G.OutputDelay = 3.2;
To see the current value, enter:
G.OutputDelay ans = 3.2000
This example shows how to create statespace models with delays at the inputs and outputs, using the InputDelay or OutputDelay properties of ss.
Create a statespace model describing the following oneinput, twooutput system:
This system has an input delay of 1.5. The first output has an output delay of 0.7, and the second output is not delayed.
Note: In contrast to SISO transfer functions, input delays are not equivalent to output delays for statespace models. Shifting a delay from input to output in a statespace model requires introducing a time shift in the model states. For example, in the model of this example, defining T = t – 1.5 and X(T) = x(T + 1.5) results in the following equivalent system:
All of the time delays are on the outputs, but the new state variable X is timeshifted relative to the original state variable x. Therefore, if your states have physical meaning, or if you have known state initial conditions, consider carefully before shifting time delays between inputs and outputs. 
To create this system:
Define the statespace matrices.
A = 2; B = 3; C = [1;1]; D = 0;
Create the model.
G = ss(A,B,C,D,'InputDelay',1.5,'OutputDelay',[0.7;0])
G is a ss model.
Tip Use delayss to create statespace models with more general combinations of input, output, and state delays, of the form:

This example shows how to create a MIMO transfer function with different transport delays for each inputoutput (I/O) pair.
Create the MIMO transfer function:
Time delays in MIMO systems can be specific to each I/O pair, as in this example. You cannot use InputDelay and OutputDelay to model I/Ospecific transport delays. Instead, use ioDelay to specify the transport delay across each I/O pair.
To create this MIMO transfer function:
Create a transfer function model for the variable s.
s = tf('s');
Use the variable s to specify the transfer functions of H without the time delays.
H = [2/s (s+1)/(s+10); 10 (s1)/(s+5)];
Specify the ioDelay property of H as an array of values corresponding to the transport delay for each I/O pair.
H.ioDelay = [0.1 0.3; 0 0.2];
H is a twoinput, twooutput tf model. Each I/O pair in H has the time delay specified by the corresponding entry in tau.
This example shows how internal delays arise when you interconnect models that have input, output, or transport time delays.
Create a model of the following control architecture:
G is the plant model, which has an input delay. C is a proportionalintegral (PI) controller.
To create a model representing the closedloop response of this system:
Create the plant G and the controller C.
G = tf(1,[1 10],'InputDelay',2.1); C = pid(0.5,2.3);
C has a proportional gain of 0.5 and an integral gain of 2.3.
Use feedback to compute the closedloop response from r to y.
T = feedback(C*G,1);
The time delay in T is not an input delay as it is in G. Because the time delay is internal to the closedloop system, the software returns T as an ss model with an internal time delay of 2.1 seconds.
Note: In addition to feedback, any system interconnection function (including parallel and series) can give rise to internal delays. 
T is an exact representation of the closedloop response, not an approximation. To access the internal delay value, enter:
T.InternalDelay
A step plot of T confirms the presence of the time delay:
step(T)
The internal time delay is stored in the InternalDelay property of T. Use dot notation to access InternalDelay. For example, to change the internal delay to 3.5 seconds, enter:
T.InternalDelay = 3.5
You cannot modify the number of internal delays because they are structural properties of the model.
This example shows how to create a discretetime transfer function with a time delay.
Specify time delays for discretetime models in the same way as for continuoustime models, except for discretetime models, delay values must be integer multiples of the sampling time. For example, create the following firstorder transfer function, with a sampling time of T_{s} = 0.1 s:
H = tf(2,[1 0.95],0.1,'InputDelay',25)
Setting InputDelay to 25 results in a delay of 25 sampling periods.
Tip Use thiran to approximate discretetime models with delays that are a fractional multiple of the sampling time. 
Many control design algorithms cannot handle time delays directly. For example, techniques such as root locus, LQG, and pole placement do not work properly if time delays are present. A common technique is to replace delays with allpass filters that approximate the delays.
To approximate time delays in continuoustime models, use the pade command to compute a Padé approximation. The Padé approximation is valid only at low frequencies, and provides better frequencydomain approximation than timedomain approximation. It is therefore important to compare the true and approximate responses to choose the right approximation order and check the approximation validity.
For discretetime models, use absorbDelay to convert a time delay to factors of 1/z where the time delay is an integer multiple of the sampling time. Use thiran to approximate fractional time delays.
This example shows how to approximate delays in a continuoustime openloop system using pade.
Padé approximation is helpful when using analysis or design tools that do not support time delays.
Create sample openloop system with an output delay.
s = tf('s');
P = exp(2.6*s)/(s^2+0.9*s+1);
P is a secondorder transfer function (tf) object with a time delay.
Compute the firstorder Padé approximation of P.
Pnd1 = pade(P,1)
Pnd1 = s + 0.7692  s^3 + 1.669 s^2 + 1.692 s + 0.7692 Continuoustime transfer function.
This command replaces all time delays in P with a firstorder approximation. Therefore, Pnd1 is a thirdorder transfer function with no delays.
Compare the frequency response of the original and approximate models using bodeplot.
h = bodeoptions; h.PhaseMatching = 'on'; bodeplot(P,'b',Pnd1,'.r',{0.1,10},h) legend('Exact delay','FirstOrder Pade','Location','SouthWest')
The magnitude of P and Pnd1 match exactly. However, the phase of Pnd1 deviates from the phase of P beyond approximately 1 rad/s.
Increase the Padé approximation order to extend the frequency band in which the phase approximation is good.
Pnd3 = pade(P,3);
Compare the frequency response of P, Pnd1 and Pnd3.
bodeplot(P,'b',Pnd3,'.r',Pnd1,':k',{0.1 10},h) legend('Exact delay','ThirdOrder Pade','FirstOrder Pade',... 'Location','SouthWest')
The phase approximation error is reduced by using a thirdorder Padé approximation.
Compare the time domain responses of the original and approximated systems using stepplot.
stepplot(P,'b',Pnd3,'.r',Pnd1,':k') legend('Exact delay','ThirdOrder Pade','FirstOrder Pade',... 'Location','Southeast')
Using the Padé approximation introduces a nonminimum phase artifact ("wrong way" effect) in the initial transient response. The effect is quite pronounced in the firstorder approximation, which dips significantly below zero before changing direction. The effect is reduced in the higherorder approximation, which far more closely matches the exact system's response.
This example shows how to approximate delays in a continuoustime closedloop system with internal delays, using pade.
Padé approximation is helpful when using analysis or design tools that do not support time delays.
Create sample continuoustime closedloop system with an internal delay.
Construct a model Tcl of the closedloop transfer function from r to y.
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 the internal delay of Tcl.
Tcl.InternalDelay
ans = 4.2000
Compute the firstorder Padé approximation of Tcl.
Tnd1 = pade(Tcl,1);
Tnd1 is a statespace (ss) model with no delays.
Compare the frequency response of the original and approximate models.
h = bodeoptions; h.PhaseMatching = 'on'; bodeplot(Tcl,'b',Tnd1,'.r',{.1,10},h); legend('Exact delay','FirstOrder Pade','Location','SouthWest');
The magnitude and phase approximation errors are significant beyond 1 rad/s.
Compare the time domain response of Tcl and Tnd1 using stepplot.
stepplot(Tcl,'b',Tnd1,'.r'); legend('Exact delay','FirstOrder Pade','Location','SouthEast');
Using the Padé approximation introduces a nonminimum phase artifact ("wrong way" effect) in the initial transient response.
Increase the Padé approximation order to see if this will extend the frequency with good phase and magnitude approximation.
Tnd3 = pade(Tcl,3);
Observe the behavior of the thirdorder Padé approximation of Tcl. Compare the frequency response of Tcl and Tnd3.
bodeplot(Tcl,'b',Tnd3,'.r',Tnd1,'k',{.1,10},h); legend('Exact delay','ThirdOrder Pade','FirstOrder Pade',... 'Location','SouthWest');
The magnitude and phase approximation errors are reduced when a thirdorder Padé approximation is used.
Increasing the Padé approximation order extends the frequency band where the approximation is good. However, too high an approximation order may result in numerical issues and possibly unstable poles. Therefore, avoid Padé approximations with order N>10.
This example shows how to specify different Padé approximation orders to approximate internal and output delays in a continuoustime openloop system.
Load sample continuoustime openloop system that contains internal and output time delays.
load PadeApproximation1 sys;
sys is a secondorder continuoustime ss model with internal delay 3.4 s and output delay 1.5 s.
Use pade to compute a thirdorder approximation of the internal delay and a firstorder approximation of the output delay.
P13 = pade(sys,inf,1,3);
The three input arguments following sys specify the approximation orders of any input, output, and internal delays of sys, respectively. inf specifies that a delay is not to be approximated. The approximation orders for the output and internal delays are one and three respectively.
P13 is a sixthorder continuoustime ss model with no delays.
(Optional) For comparison, approximate only the internal delay of sys, leaving the output delay intact.
P3 = pade(sys,inf,inf,3);
P3 is a fifthorder continuoustime ss model with an output delay of 1.5 s. The internal delay is approximated and absorbed into the statespace matrices.
(Optional) Compare the frequency response of the exact and approximated systems. sys, P13, P3.
h = bodeoptions; h.PhaseMatching = 'on'; bode(sys,'b',P13,'r.',P3,'k',h,{.01,10}); legend('Exact Output and Internal Time Delays',... 'Pade Approximation  Firstorder Output, ... Thirdorder Internal Delays',... 'Pade Approximation  Thirdorder Internal Delay',... 'location','SouthWest')
This example shows how to convert a time delay in a discretetime model to factors of 1/z using absorbDelay.
In a discretetime model, a time delay of one sampling interval is equivalent to a factor of 1/z (a pole at z = 0) in the model. Therefore, time delays stored in the InputDelay, OutputDelay, or ioDelay properties of a discretetime model can be rewritten in the model dynamics by rewriting them as poles at z = 0. However, the additional poles increase the order of the system. Particularly for large time delays, this can yield systems of very high order, leading to long computation times or numerical inaccuracies.
To illustrate how to eliminate time delays in a discretetime closedloop model, and to observe the effects of doing so, create the following closedloop system:
where G is a firstorder discretetime system with an input delay, and C is a PI controller.
G = ss(0.9,0.125,0.08,0,'Ts',0.01,'InputDelay',7); C = pid(6,90,0,0,'Ts',0.01); T = feedback(C*G,1);
Examine the order and internal delay of T.
order(T) T.InternalDelay
ans = 2 ans = 7
T is a secondorder statespace model with an internal delay of 7 time steps.
Use absorbDelay to replace the internal delay by z^{7}.
Tnd = absorbDelay(T);
Examine the internal delay of Tnd.
Tnd.InternalDelay
ans = Empty matrix: 0by1
Tnd has no internal delay, and the step response of Tnd exactly matches that of T:
step(T,Tnd)
However, Tnd is a ninthorder model, due to the seven extra poles introduced by absorbing the sevenunit delay into the model.
order(Tnd)
ans = 9
Use the thiran command to approximate a time delay that is a fractional multiple of the sampling time as a Thiran allpass filter.
For a time delay of tau and a sampling time of Ts, the syntax thiran(tau,Ts) creates a discretetime transfer function that is the product of two terms:
A term representing the integer portion of the time delay as a pure line delay, (1/z)^{N}, where N = ceil(tau/Ts).
A term approximating the fractional portion of the time delay (tau  NTs) as a Thiran allpass filter.
Discretizing a Padé approximation does not guarantee good phase matching between the continuoustime delay and its discrete approximation. Using thiran to generate a discretetime approximation of a continuoustime delay can yield much better phase matching. For example, the following figure shows the phase delay of a 10.2second time delay discretized with a sample time of 1 s, approximated in three ways:
a firstorder Padé approximation, discretized using the tustin method of c2d
an 11thorder Padé approximation, discretized using the tustin method of c2d
an 11thorder Thiran filter
The Thiran filter yields the closest approximation of the 10.2second delay.
See the thiran reference page for more information about Thiran filters.
This example shows that absorbing time delays into frequency response data can cause undesirable phase wrapping at high frequencies.
When you collect frequency response data for a system that includes time delays, you can absorb the time delay into the frequency response as a phase shift. Alternatively, if you are able to separate time delays from your measured frequency response, you can represent the delays using the InputDelay, OutputDelay, or ioDelay properties of the frd model object. The latter approach can give better numerical results, as this example illustrates.
The frd model fsys includes a transport delay of 2 s. Load the model into the MATLAB^{®} workspace and inspect the time delay with the following commands:
load frddelayexample fsys fsys.ioDelay
A Bode plot of fsys shows the effect of the transport delay:
bodeplot(fsys)
The transport delay ioDelay = 2 introduces a rapid accumulation of phase with increasing frequency.
The absorbDelay command absorbs all time delays directly into the frequency response, resulting in an frd model with ioDelay = 0:
fsys2 = absorbDelay(fsys); fsys2.ioDelay
Comparing the two ways of representing the delay shows that absorbing the delay into the frequency response causes phasewrapping.
bode(fsys,fsys2)
Phase wrapping can introduce numerical inaccuracy at high frequencies or where the frequency grid is sparse. For that reason, if your system takes the form e–τsG(s), you might get better results by measuring frequency response data for G(s) and using InputDelay, OutputDelay, or ioDelay to model the time delay τ.
Using the InputDelay, OutputDelay, and ioDelay properties, you can model simple processes with transport delays. However, these properties cannot model more complex situations, such as feedback loops with delays. In addition to the InputDelay and OutputDelay properties, statespace (ss) models have an InternalDelay property. This property lets you model the interconnection of systems with input, output, or transport delays, including feedback loops with delays. You can use InternalDelay property to accurately model and analyze arbitrary linear systems with delays. Internal delays can arise from the following:
Concatenating statespace models with input and output delays
Feeding back a delayed signal
Converting MIMO tf or zpk models with transport delays to statespace form
Using internal time delays, you can do the following:
In continuous time, generate approximatefree time and frequency simulations, because delays do not have to be replaced by a Padé approximation. In continuous time, this allows for more accurate analysis of systems with long delays.
In discrete time, keep delays separate from other system dynamics, because delays are not replaced with poles at z = 0, which boosts efficiency of time and frequency simulations for discretetime systems with long delays.
Use most Control System Toolbox™ functions.
Test advanced control strategies for delayed systems. For example, you can implement and test an accurate model of a Smith predictor. See the example Control of Processes with Long Dead Time: The Smith Predictor Control of Processes with Long Dead Time: The Smith Predictor .
This example illustrates why input, output, and transport delays not enough to model all types of delays that can arise in dynamic systems. Consider the simple feedback loop with a 2 s. delay:
The closedloop transfer function is
The delay term in the numerator can be represented as an output delay. However, the delay term in the denominator cannot. In order to model the effect of the delay on the feedback loop, the InternalDelay property is needed to keep track of internal coupling between delays and ordinary dynamics.
Typically, you do not create statespace models with internal delays directly, by specifying the A, B, C, and D matrices together with a set of internal delays. Rather, such models arise when you interconnect models having delays. There is no limitation on how many delays are involved and how the models are connected. For an example of creating an internal delay by closing a feedback loop, see Closing Feedback Loops with Time Delays.
When you work with models having internal delays, be aware of the following behavior:
When a model interconnection gives rise to internal delays, the software returns an ss model regardless of the interconnected model types. This occurs because only ss supports internal delays.
The software fully supports feedback loops. You can wrap a feedback loop around any system with delays.
When displaying the A, B, C, and D matrices, the software sets all delays to zero (creating a zeroorder Padé approximation). This approximation occurs for the display only, and not for calculations using the model.
For some systems, setting delays to zero creates singular algebraic loops, which result in either improper or illdefined, zerodelay approximations. For these systems:
Entering sys returns only sizes for the matrices of a system named sys.
Entering sys.a produces an error.
The limited display and the error do not imply a problem with the model sys itself.
Statespace objects use generalized statespace equations to keep track of internal delays. Conceptually, such models consist of two interconnected parts:
An ordinary statespace model H(s) with an augmented I/O set
A bank of internal delays.
The corresponding statespace equations are:
You need not bother with this internal representation to use the tools. If, however, you want to extract H or the matrices A,B1,B2, ,... , you can use getDelayModel, For the example:
P = 5*exp(3.4*s)/(s+1); C = 0.1 * (1 + 1/(5*s)); T = feedback(ss(P*C),1); [H,tau] = getDelayModel(T,'lft'); size(H)
Note that H is a twoinput, twooutput model whereas T is SISO. The inverse operation (combining H and tau to construct T) is performed by setDelayModel.
The following commands support internal delays for both continuous and discretetime systems:
All interconnection functions
Time domain response functions—except for impulse and initial
Frequency domain functions—except for norm
Limitations on Functions that Support Internal Time Delays. The following commands support internal delays for both continuous and discretetime systems and have certain limitations:
allmargin, margin—Uses interpolation, therefore these commands are only as precise as the fineness of the specified grid.
pole, zero—Returns poles and zeros of the system with all delays set to zero.
ssdata, get—If an SS model has internal delays, these commands return the A, B, C, and D matrices of the system with all internal delays set to zero. Use getDelayModel to access the internal statespace representation of models with internal delays.
The following commands do not support internal time delays:
Timedomain analysis—initial and initialplot
Compensator design—rlocus, lqg, lqry, lqrd, kalman, kalmd, lqgreg, lqgtrack, lqi, and augstate.
To use these functions on a system with internal delays, use pade to approximate the internal delays. See TimeDelay Approximation.
[1] P. Gahinet and L.F. Shampine, "Software for Modeling and Analysis of Linear Systems with Delays," Proc. American Control Conf., Boston, 2004, pp. 56005605
[2] L.F. Shampine and P. Gahinet, Delaydifferentialalgebraic Equations in Control Theory, Applied Numerical Mathematics, 56 (2006), pp. 574588