Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Models with Time Delays

How to create models that include time delays.

Modeling 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 discrete-time models, these properties are constrained to integer values that represent delays expressed as integer multiples of the sampling time. To approximate discrete-time models with delays that are a fractional multiple of the sampling time, use thiran.

First Order Plus Dead Time Model

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 first-order 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

    Tip   An alternative way to create a model with a time delay is to specify the transfer function with the delay as an expression in s:

    1. Create a transfer function model for the variable s.

      s = tf('s');          
    2. Specify G(s) as an expression in s.

      G = exp(-2.1*s)/(s+10);

 More About

Input and Output Delay in State-Space Model

This example shows how to create state-space models with delays at the inputs and outputs, using the InputDelay or OutputDelay properties of ss.

Create a state-space model describing the following one-input, two-output 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 state-space models. Shifting a delay from input to output in a state-space 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 time-shifted 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:

  1. Define the state-space matrices.

    A = -2;
    B = 3;
    C = [1;-1];
    D = 0;
    
  2. 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 state-space models with more general combinations of input, output, and state delays, of the form:

 More About

Transport Delay in MIMO Transfer Function

This example shows how to create a MIMO transfer function with different transport delays for each input-output (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/O-specific transport delays. Instead, use ioDelay to specify the transport delay across each I/O pair.

To create this MIMO transfer function:

  1. Create a transfer function model for the variable s.

    s = tf('s');          
  2. Use the variable s to specify the transfer functions of H without the time delays.

    H = [2/s (s+1)/(s+10); 10 (s-1)/(s+5)];
    
  3. 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 two-input, two-output tf model. Each I/O pair in H has the time delay specified by the corresponding entry in tau.

Closing Feedback Loops with Time Delays

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 proportional-integral (PI) controller.

To create a model representing the closed-loop response of this system:

  1. 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.

  2. Use feedback to compute the closed-loop 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 closed-loop 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 closed-loop 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)

    Note:   Most analysis commands, such as step, bode and margin, support models with internal delays.

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.

 More About

Discrete-Time Transfer Function with Time Delay

This example shows how to create a discrete-time transfer function with a time delay.

Specify time delays for discrete-time models in the same way as for continuous-time models, except for discrete-time models, delay values must be integer multiples of the sampling time. For example, create the following first-order transfer function, with a sampling time of Ts = 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 discrete-time models with delays that are a fractional multiple of the sampling time.

Time-Delay Approximation

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 all-pass filters that approximate the delays.

To approximate time delays in continuous-time models, use the pade command to compute a Padé approximation. The Padé approximation is valid only at low frequencies, and provides better frequency-domain approximation than time-domain approximation. It is therefore important to compare the true and approximate responses to choose the right approximation order and check the approximation validity.

For discrete-time 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.

 Related Examples

Time-Delay Approximation in Continuous-Time Open-Loop Model

This example shows how to approximate delays in a continuous-time open-loop system using pade.

Padé approximation is helpful when using analysis or design tools that do not support time delays.

  1. Create sample open-loop system with an output delay.

    s = tf('s');
    P = exp(-2.6*s)/(s^2+0.9*s+1);
    

    P is a second-order transfer function (tf) object with a time delay.

  2. Compute the first-order Padé approximation of P.

    Pnd1 = pade(P,1)
    
    Pnd1 =
     
                 -s + 0.7692
      ----------------------------------
      s^3 + 1.669 s^2 + 1.692 s + 0.7692
     
    Continuous-time transfer function.
    
    

    This command replaces all time delays in P with a first-order approximation. Therefore, Pnd1 is a third-order transfer function with no delays.

  3. 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','First-Order 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.

  4. Increase the Padé approximation order to extend the frequency band in which the phase approximation is good.

    Pnd3 = pade(P,3);
    
  5. Compare the frequency response of P, Pnd1 and Pnd3.

    bodeplot(P,'-b',Pnd3,'-.r',Pnd1,':k',{0.1 10},h)
    legend('Exact delay','Third-Order Pade','First-Order Pade',...
           'Location','SouthWest')
    

    The phase approximation error is reduced by using a third-order Padé approximation.

  6. Compare the time domain responses of the original and approximated systems using stepplot.

    stepplot(P,'-b',Pnd3,'-.r',Pnd1,':k')
    legend('Exact delay','Third-Order Pade','First-Order 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 first-order approximation, which dips significantly below zero before changing direction. The effect is reduced in the higher-order approximation, which far more closely matches the exact system's response.

      Note:   Using too high an approximation order may result in numerical issues and possibly unstable poles. Therefore, avoid Padé approximations with order N>10.

Time-Delay Approximation in Continuous-Time Closed-Loop Model

This example shows how to approximate delays in a continuous-time closed-loop system with internal delays, using pade.

Padé approximation is helpful when using analysis or design tools that do not support time delays.

  1. Create sample continuous-time closed-loop system with an internal delay.

    Construct a model Tcl of the closed-loop 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
    
    
  2. Compute the first-order Padé approximation of Tcl.

    Tnd1 = pade(Tcl,1);
    

    Tnd1 is a state-space (ss) model with no delays.

  3. 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','First-Order Pade','Location','SouthWest');
    

    The magnitude and phase approximation errors are significant beyond 1 rad/s.

  4. Compare the time domain response of Tcl and Tnd1 using stepplot.

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

    Using the Padé approximation introduces a nonminimum phase artifact ("wrong way" effect) in the initial transient response.

  5. Increase the Padé approximation order to see if this will extend the frequency with good phase and magnitude approximation.

    Tnd3 = pade(Tcl,3);
    
  6. Observe the behavior of the third-order 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','Third-Order Pade','First-Order Pade',...
           'Location','SouthWest');
    

    The magnitude and phase approximation errors are reduced when a third-order 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.

 More About

Approximate Different Delays with Different Approximation Orders

This example shows how to specify different Padé approximation orders to approximate internal and output delays in a continuous-time open-loop system.

  1. Load sample continuous-time open-loop system that contains internal and output time delays.

    load PadeApproximation1 sys;
    

    sys is a second-order continuous-time ss model with internal delay 3.4 s and output delay 1.5 s.

      Tip   Enter get(sys) for more properties of sys.

  2. Use pade to compute a third-order approximation of the internal delay and a first-order 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 sixth-order continuous-time ss model with no delays.

  3. (Optional) For comparison, approximate only the internal delay of sys, leaving the output delay intact.

    P3 = pade(sys,inf,inf,3);
    

    P3 is a fifth-order continuous-time ss model with an output delay of 1.5 s. The internal delay is approximated and absorbed into the state-space matrices.

  4. (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 - First-order Output, ...
         Third-order Internal Delays',...
        'Pade Approximation - Third-order Internal Delay',...
        'location','SouthWest')

Convert Time Delay to Factors of 1/z in Discrete-Time Model

This example shows how to convert a time delay in a discrete-time model to factors of 1/z using absorbDelay.

In a discrete-time 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 discrete-time 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 discrete-time closed-loop model, and to observe the effects of doing so, create the following closed-loop system:

where G is a first-order discrete-time 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 second-order state-space 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: 0-by-1

Tnd has no internal delay, and the step response of Tnd exactly matches that of T:

step(T,Tnd)

However, Tnd is a ninth-order model, due to the seven extra poles introduced by absorbing the seven-unit delay into the model.

order(Tnd)
ans =

     9

Fractional Time-Delay Approximation in Discrete-Time Model

Use the thiran command to approximate a time delay that is a fractional multiple of the sampling time as a Thiran all-pass filter.

For a time delay of tau and a sampling time of Ts, the syntax thiran(tau,Ts) creates a discrete-time 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 all-pass filter.

Discretizing a Padé approximation does not guarantee good phase matching between the continuous-time delay and its discrete approximation. Using thiran to generate a discrete-time approximation of a continuous-time delay can yield much better phase matching. For example, the following figure shows the phase delay of a 10.2-second time delay discretized with a sample time of 1 s, approximated in three ways:

  • a first-order Padé approximation, discretized using the tustin method of c2d

  • an 11th-order Padé approximation, discretized using the tustin method of c2d

  • an 11th-order Thiran filter

The Thiran filter yields the closest approximation of the 10.2-second delay.

See the thiran reference page for more information about Thiran filters.

Frequency Response Data (FRD) Model with Time Delay

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 phase-wrapping.

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 τ.

 More About

Internal Delays

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, state-space (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 state-space models with input and output delays

  • Feeding back a delayed signal

  • Converting MIMO tf or zpk models with transport delays to state-space form

Using internal time delays, you can do the following:

  • In continuous time, generate approximate-free 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 discrete-time 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 .

Why Internal Delays Are Necessary

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 closed-loop 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 state-space 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.

Behavior of Models With Internal 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 zero-order 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 ill-defined, zero-delay 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.

Inside Time Delay Models

State-space objects use generalized state-space equations to keep track of internal delays. Conceptually, such models consist of two interconnected parts:

  • An ordinary state-space model H(s) with an augmented I/O set

  • A bank of internal delays.

The corresponding state-space 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 two-input, two-output model whereas T is SISO. The inverse operation (combining H and tau to construct T) is performed by setDelayModel.

See [1], [2] for details.

Functions That Support Internal Time Delays

The following commands support internal delays for both continuous- and discrete-time 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 discrete-time 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 state-space representation of models with internal delays.

Functions That Do Not Support Internal Time Delays

The following commands do not support internal time delays:

References

[1] P. Gahinet and L.F. Shampine, "Software for Modeling and Analysis of Linear Systems with Delays," Proc. American Control Conf., Boston, 2004, pp. 5600-5605

[2] L.F. Shampine and P. Gahinet, Delay-differential-algebraic Equations in Control Theory, Applied Numerical Mathematics, 56 (2006), pp. 574-588

Was this topic helpful?