Modeling and Simulation of Time-Varying Delays

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Modeling and Simulation of Time-Varying Delays

Fu Zhang and Murali Yeddanapudi MathWorks fzhang@mathworks.com, Murali.Yeddanapudi@mathworks.com Keywords: time delay, variable time delay, variable transport delay, time-varying delay, delay differentiation equations

Abstract
This paper presents the numerical methods for modeling and simulation of fundamental continuous time-varying delays. Continuous time-varying delays are categorized as variable time delay and variable transport delay. These two fundamental delays are formulated and implemented as two Simulink R built-in blocks. The difference between these two delays are discussed. With these two fundamental time varying delays, physical system such as convey belt, control system with delayed control signals, delay differential equations, can be easily modeled and simulated.

Figure 1. The Variable Time Delay Block

1. INTRODUCTION
Systems with time delays arise in many control systems and are of great interest [1, 2, 3, 4, 5]. The time delays may appear because of signal transmission. An example is to control a deep-space spacecraft and the control signal from the earth will take a long time to reach the spacecraft. Delays may also occur in sensors involved in feedback loops and it could change the stability of the control system [4, 8]. Many other physical system involving delays, such as human respiration [6], ethernet communication networks [11] can also be modeled as time delay systems. Computer simulation is an important method to study time delay systems [9, 10, 12]. As a hybrid dynamic system simulation platform, Simulink R provides two continuous timevarying delay blocks to model and simulate such systems, namely variable time delay and variable transport delay blocks. This paper presents the details of the formulations and implementations of these two delay blocks in Simulink R . Their applications are also discussed.

Figure 2. Formulation of the Variable Transport Delay

2.1. Variable Time Delay


A variable time delay is defined as: y(t ) = u(t td (t )) (1)

where u(t ) is the input variable and y(t ) is the output variable. td (t ) is a time-varying delay and is an independent input variable. The symbol of variable time delay block in Simulink R is shown in Fig. 1. This block delays the input u(t ) with a time-varying delay td (t ). A special case is that when td is a constant Td , then equation (1) can be written as y(t ) = u(t Td ) (2)

2. FORMULATION OF DELAYS

TIME-VARYING

In this case, the input and output are identical in shape, but output is shifted with a fixed time Td along time axis.

Time-varying delays can be categorized as variable time delay and variable transport delay. This section describes the formulation of these two delays so their difference can be clearly understood.

2.2. Variable Transport Delay


The concept of variable transport delay is best explained by an example as shown in Fig. 2. This example was first introduced in [7].

Table 1. Buffer Index T (t ) U (u)

Implementation of Variable Time Delay: The T U 0 0 1 1 0.2 1.4 2 0.5 1.6 3 0.6 0.5 4 0.78 0.6 n 120 3

The variable transport delay can be formulated as follows: An input signal fw (t ) is written on a moving, incompressible medium with speed vm (t ) 0 and will later produce the output by passing the information through the moving medium to a read device at some other location. The distance between the write and read device is L, which is a constant. The signal read at time t , fr (t ) will form the a variable transport delay of the signal f w (t ) as: fr (t ) = fw (t d (t )) (3)

Figure 3. General Structure of Variable Transport Delay Block 2. y(t ) = u(t td (t )) can be interpolated from [Tn 1 ,Un1 ] and [Tn ,Un ] and t td . If linear interpolation is used, then: Tn+1 (t td (t )) (t td (t )) Tn Un + Un+1 Tn+1 Tn Tn+1 Tn (5) For example, suppose t = 5, td = 4.7, then t td = 0.3 is between T1 = 0.2 and T2 = 0.5, and thus n = 1. y = u(t td ) = u(0.3) can be found as y = u(0.3) = interpolate(T1 , T2 ,U1 ,U2 , t td ). If liner interpolation is used, y(t td (t )) = 1.4667. An extreme case is when if t td < t0 , then y = u(t td (t )) = init ialValue, where init ialV value is a value provided by the user and is not stored in the T U buffer. y(t td (t )) =

The time-varying delay td (t ) in the variable time delay is treated as a known input. However, the time-varying delay d (t ) in the variable transport delay , is not known explicitly and must be computed from the length L and the speed of the medium vm (t ). If we define the write signal fw (t ) and input u and the read signal as output y, then equation (3) can be written as: y(t ) = u(t d (L, vm (t ))) (4)

3. IMPLEMENTATIONS
This section describes how the time-varying delays are implemented. For variable transport delay, two implementations are given.

3.2. Variable Transport Delay


A variable transport delay block that implements y(t ) = u(t d (L, vm (t ))) can be implemented by adding a preprocessing unit to a variable time delay block. The preprocessing unit first computes d (L,Vm (t )) and then pass the computed d (t ) to a variable time delay block. The general structure of the variable transport delay block could be depicted a Fig. 3. It is composed of two parts: the unit that computes d and a variable time delay block that delays the input with d . Two numerical methods to solve for d (t ) have been developed and are discussed below: 3.2.1. Method I As depicted in Fig. 2, the signal that is read at time t is actually the signal that was written at time t d . This signal has been carried from the write position to the read position by the medium with time varying speed vm , thus:
Z
t

3.1. Variable Time Delay


For computer simulation purpose, a variable time delay can be implemented using a buffer that store the history of simulation time t and the corresponding input signal u(t ). This buffer is called T U buffer in this paper. Because the delay td (t ) can vary, all the history (from simulation start time t0 to current time t )(integration time steps) of input variable u and time t should be stored. For continuous simulation with variable step size ODE solver, number of time steps of the simulation is not known in advance. Thus a buffer with growing size is needed to store u(t ) and y(t ). Table 1 shows an example of the T U buffer that stores the input u(t ) and the simulation time t . This buffer is initially allocated with an initial size to store history data and will be dynamically resized if it is full as simulation continues. The output signal y(t ) = u(t td (t )) can be found from the buffer data in two steps: 1. t td (t ) can be bracketed by [Tn1 , Tn ], where Tn1 (t td ) Tn .

L=

t d

vm (T )dT

(6)

holds. Since L is a constant, (6) can be normalized as:

Figure 5. Structure of Variable Transport Delay: Method I

Figure 4. x(t) and Solving for d


Z
t

t d

vm (T ) dT = L

L t d v (T ) m

dT = 1

(7) Figure 6. The Variable Time Delay Block In Simulink R , the state variable x can be computed using the Simulink R built-in ODE solver by integrating the following derivative function: x = 1 TD (t ) (13)

Define: TD (t ) = L vm (t ) (8)

TD (t ) is called instantaneous delay and can be understood as a estimated delay based current speed vm (t ). Equation (7) can be rewritten as:
Z
t

t d

1 dT = 1 Td (T )

(9)

Apply the properties of the integral, (9) can be rewritten as:


Z
t

t0

1 dT Td (T ) x(t ) =

t d

t0 t

1 dT = 1 Td (T )

(10)

Define:

t0

1 dT Td (T )

(11)

then (10) can be rewritten as: x(t ) x(t d (t )) = 1 (12)

Fig. 4 is a graphical representation of (12). It actually reflects the conservative nature of the setup shown in Fig. 2. The signal passes through the write location must go through the read location and is incompressible. x(t ) is the normalized displacement of a signal that leaves the write location and moves to the read location. Since vm >= 0), which means that the medium can only move in one direction, x(t ) monotonically increased. This will guarantee (12) has only one solution d (t ) at any given time t .

Once d (t ) is found from (12), it can then be passed into a variable time delay block and the variable transport delay is implemented. By normalizing and introducing the concept of instantaneous delay TD , L and vm can be removed from the equation and thus no particular physical meaning is attached to the variable transport delay block. Therefore the block can have two inputs u and instantaneous delay TD . Fig. 5 shows the structure ofvariable transport delay block implemented based on above steps. The Simulink R symbol of this block is shown in Figure 6. Although this symbol is quite similar to the symbol of the variable time delay block shown in Fig. 1, there are slightly difference between them. The name of the time-varying delay input of the variable time delay block is to , which shows that this delay will show up directly at the output port. While the name of the time-varying delay input of the variable transport delay block is ti , which is the instantaneous delay TD . The actually delay d (t ) observed at the output (read location) must be computed and is usually quite different from TD (t ). A growing buffer (T XU buffer) that contains the history of time t , input u and the state x can then be used to solve for d . This method is similar to the circular buffer method used in

Table 2. Implementation of Variable T XU Buffer Index 0 1 2 3 4 T (t ) 0 0.2 0.5 0.6 0.9 X (x) 0 0.7 1.2 1.4 1.8 U (u) 1 1.4 1.6 0.5 4.7

Transport Delay: The 5 1.1 2 5.5 6 2 2.1 1.2 7 2.1 2.3 2

[10]. An example of the T XU buffer is shown in Table 2. The output signal y(t ) = u(t d (t )) can be found from the buffer data in three steps: 1. From the T XU buffer, find index n so that: X (t ) Xn+1 1 and x(t ) Xn 1. 2. The precise time d that x(t ) x(t d (t )) = 1 can be calculated by using interpolation. If linear interpolation is used, then d can be computed from the following equations: f = X [n+1]X [n] d (t ) = t (1 f ) T [n 1] + f T [n + 1]
X (t )1.0X [n]

Figure 7. Structure of Variable Transport Delay II Equations (15,16) form a time delay ODE and can be solved directly by Simulink R . It can be implemented with a variable time delay block with a feedback loop. Using this method, a variable transport delay block can be implemented using two variable time delay blocks as shown in Fig. 7. With this method, the state variable is the variable transport delay d and is solved by ODE solver of Simulink R directly, unlike the state x in method I is solved by using interpolation. For this reason method II is also called direct-method and method I is called indirect method. Compare to the indirect method that needs extra interpolation code to solve for d , direct method uses Simulink R ODE solver to solve for the delay d directly. This method can implement the variable transport delay block with existing variable time delay block. But block implemented with method I (need coding to solve for d (t )) may have better performance (faster simulation speed).

(14)

3. y(t ) = u(t d (t )) can be interpolated from [Tn1 ,Un1 ] and [Tn ,Un ] and t d . This step is the same as the 2nd step when computing the output of variable time delay block. For example, assume t = 2.1 and X (2.1) = 2.3, then it can be found that X (2.1) X2 = 2.3 1.2 = 1.1 > 1 and X (2.1) X3 = 2.3 1.4 = 0.9 < 1, then n = 2. Using f= X (t ) 1.0 X [2] 2.3 1 1.2 = = 0.5 X [3] X [2] 1.4 1.2

and d (2.1) = 2.1 (1 f ) T [2] + f T [3] = 0.5 0.5 + 0.5 0.6 = 1.55 Once d (t ) = 1.55 is found then t d (t ) = 0.55, another interpolation based on (5) can be used to find y = u(t d (t )) = u(0.55) with U(0.5) = 1.6 an U(0.6) = 0.5. 3.2.2. Method II Another method to solve for d (t ) is to differentiate (10) against time t , and yields: T (t d ) d d = 1 D dt TD (t ) The initial value of d can be determined as
0 d

4. SIMULATIONS AND APPLICATIONS


When modeling and simulation of time-varying systems, it is quite important to chose the right variable delay blocks. This section shows how variable time delay and variable transport delay are used for simulating different physical phenomena.

4.1. Variable Time Delay


4.1.1. Solving delay differential equations (DDE) Many dynamical systems can be modeled as a delay differentiable equations. For delay differential equations, the derivative at any time depends on the solution at prior times. Usually such differential equations need special DDE solvers and the delay is treated as constant [13]. However, with the variable time delay block, such DDEs can be modeled in Simulink R and approximately solved with a normal ODE solver. For example, one famous delay differential equation is

(15)

L = (16)

= TD (0) vm ( 0) which equals to the instantaneous delay at time t0 .

Figure 10. Simulate Sine wave with Phase Noise

Figure 8. Simulink Model of Hutchinsons equation or delayed logistic equation

Figure 11. Simulate Sine wave with Phase Noise Figure 9. Simulation result of Hutchinsons equation or delayed logistic equation 4.1.2. Physical delay simulation A typical application of variable time delay is to simulate a source with phase noise. For example, a sine wave source with phase noise can be defined as: y(t ) = sin( t + (t )) (18)

the famous Hutchinsons equation or delayed logistic equation [14]: x(t ) x = rx(t )[1 ] K

(17)

With the help of variable time delay block, this equation can be represented as a Simulink R model as shown in Fig. 8 This model can be solved using Simulink R built-in ODE solver such as ODE45 directly, other than using special solver for delay differential equations using step method. Figure 9 shows the simulation result with r = 0.15, K = 1, = 8. When t < 0, x = 0.5.

where (t ) is the phase noise. Fig. 10 shows the Simulink R diagram of the model that simulates a sine wave with phase noise using variable time delay block. The phase noise is modeled using a random number generator. Fig. 11(a) shows the waveform of a pure sine wave and Fig. 11(b) shows waveform of the sine wave with phase noise.

4.2. Variable Transport Delay


Fig. 12 is a Simulink R model that simulates the variable transport delay defined in the setup depicted in Fig. 2 with

Figure 12. Simulink Model of Variable Transport Delay the transport distance L = 1. The write signal is u = sin(t ). The medium speed vm (t ) = 0.2 + 0.1 K sin t . The upper part of the model uses a built-in variable transport delay block, which is implemented based on indirect method. The lower part of the model is to simulate the same variable transport delay using direct method. In the upper part of the model, the speed vm is integrated and thus the internal state x of the variable transport delay block can be observed outside the block for comparison purpose. In the lower part of the model that implements direct method, the variable transport delay d can be acquired directly from the model, which is the output of integration 1. 4.2.1. Simulation Case I: constant vm In this case, K = 0 and thus the medium speed vm = 0.2 is constant. The simulation results are shown in Fig. 13. From top to bottom, the sub-figures (a)-(e) show the following variables: 1. Input signal u(t ). 2. Output signal y1 (t ) computed with indirect method. 3. Output signal y2 (t ) computed with direct method. 4. State x(t) in indirect method. 5. State d (t ) in direct method. Both indirect and direct generate the same output y(t ). It can be found that when the medium is moving with a constant speed, the variable transport delay just shift the input with a fixed delay.

Figure 13. Variable Transport Delay with constant vm The transport delay d = L 1 = =5 vm 0.2

is constant. The x is a line with slop equals to vm = 0.2. The delay d is equals to the time t at which x(t ) = 1, which is the result of (10). 4.2.2. Simulation Case II: Variable vm In this case, K = 1 and thus the medium speed vm is timevarying and the simulation results are shown in Fig. 14. From top to bottom, the sub-figures (a)-(f) show the following variables: 1. Input signal u(t ). 2. Output signal y1 (t ) computed with indirect method. 3. Output signal y2 (t ) computed with direct method. 4. State x(t) in indirect method. 5. State d (t ) of direct method. 6. Input variable instantaneous delay TD of both methods. First, the figures show that both methods generate comparable simulation results. It can be found that the signal u(0) (point A, which is written at t = 0 is delayed about 4.2 seconds. It means that it took

Figure 15. Variable Transport Delay: Conveyor Belt

Figure 16. Variable Transport Delay: Incompressible flow Figure 14. Variable Transport Delay with variable vm about 4.2 seconds for the medium to transport point A(signal u(0)) to point A0 (y(4.2)), where the read device read the signal as y(4.2) = u(4.2 4.2) = u(0). Also, x(4.2) x(0) = 1 shows how td (4.2) = 4.2 is computed from 10 with indirect method. td (4.2) = 4.2 is also found by direct method directly, as shown in the sub-figure 14(e). Similarly, point B which is written at t = 3.1415 is transported to the read device at time t = 8.3849. The variable transport delay d (8.3849) = 5.243 because x(8.3849) x(3.1415) = 1. Thus y(8.3849) = u(8.3849 5.243) = u(3.1415). td (8.3849) = 5.243 is also found by direct method directly, as shown in the sub-figure 14(e). It also can be found that the waveform of delayed signal y(t ) is quite different from the input signal u(t ) due to the changing instantaneous delay TD . The waveform of the instantaneous delay TD is also quite different from the waveform of variable transport delay d (t ). On the other hand, if TD (T ) changes very slowly, then a variable transport delay with input u(t ) and TD (t ) can be approximated by a variable time delay block that has the same inputs u and td (t ) = TD (t ). Many physical systems can be modeled with variable transport delay blocks, the followings are just a few: 1. Conveyor Belt system as shown in Fig. 15. A conveyor belt is used for mass transfer. The length of the conveyor belt is L and the belt is moving with speed vm (t ). At the input side, the mass transfer rate is Vi and at the output side the mass transfer rate is Vo . Vo can be simulated as a variable transport delay of Vi . 2. Incompressible flow through a pipe as shown in Fig. 16. An incompressible flow goes through a pipe of volume L with volume speed vm (t ). At the inlet, the flow temperature is Ti . We can model the temperature at the outlet To as a variable transport delay of Ti . 3. Rolling machine control is a well know control problem. In steel rolling process, the measurement point is located at some distance away from the steel press point. Consequently, there is always a time delay in feeding back the plate thickness to the press controller [9]. This delayed feedback signal can be treated as a variable transport delay of the thickness at the steel press point.

5. CONCLUSIONS
Computer simulation is an important method to fstudy continuous time-varying delay systems. This paper discussed the methods to simulate two types of time-varying delays, namely variable time delay and variable transport delay in Simulink R . The relations of these two delay blocks are also discussed. Simulation results showed the capabilities of the presented methods. With these two fundamental time varying delays, physical system such as convey belt, control system with delayed control signals, delay differential equations, can be easily modeled and simulated.

REFERENCES
[1] M. Malek-Zavarei and M. Jamshidi. 1987. Time-Delay Systems Analysis, Optimization and Applications. Amsterdam, The Netherlands: Elsevier Science Publishers B. V. [2] J. E. Marshall, H. Gorecki, K. Walton, and A. Korytowski, 1992. Time Delay Systems, Stability and Performance Criteria with Applications. 1st ed. West Sussex, England: Ellis Horwood Limited. [3] Hirai, K. and Satoh, Y., 1980. Stability of a system with variable time delay,IEEE Transactions on Automatic Control, vol. 25, no. 3, Jun. 1980, pp. 552-554. [4] J. H. Su, 1994. On the stability of time-delay systems. In Decision and Control, 1994., Proceedings of the 33rd IEEE Conference on, vol. 1, pp. 429-430, 1994 [5] J. P. Richard, Time-delay systems: an overview of some recent advances and open problems, Atomatica, Vol. 39, Issue 10, pp. 1667-1694. [6] K. L. Cooke and J. Turi, 1994, Stability, instability in delay equations modeling human respiration, Journal of Mathematical Biology, vol. 32, no. 6, pp. 535-543. [7] R.A. Johnson, 1968, General Analysis of TimeVariable Delay devices, Electronics Letters, Vol. 4, Issue 13, pp. 263 - 264. [8] J. E. Marshall and T. J. Ward, 1981, Control of timedelay systems, IEEE Transactions on Systems, Man and Cybernetics, Vol. 11, Issue 7, pp. 515-515. [9] C. Shan, 2004, On the Modeling of Time-Varying Delays, Master thesis, Texas A&M University. [10] C. L. Carnal and C. J. Remenyik, 1989, Variable Time Delay in Dynamic System Simulation. In Proc. Southeastern Simulation Conference, Oct. 1989. pp. 175-179. [11] B. Dermanovic, N. Peric and I. Petrovic, 1994, Modeling of transport delay on Ethernet communication networks. In Proceedings of the 12t h IEEE Mediterranean Electrotechnical Conference, May 1994, pp. 367-370, [12] M.B. Rothstein, 1973. A variable transport delay, SIMULATION, Dec. 1973, vol. 21, no.6, pp. 184. [13] L.F. Shampine and S. Thompson, 2001, Solving DDEs in MATLAB, Applied Numerical Mathematics 37 (2001) pp. 441-458. [14] Julien Arino, Lin Wang and Gail S.K. Wolkowicz, 2006,An alternative formulation for a delayed logistic equation, Journal of Theoretical Biology, vol. 241, pp. 109-119.

You might also like