# Variable Time Delay, Variable Transport Delay

Delay input by variable amount of time

Continuous

## Description

The Variable Transport Delay and Variable Time Delay appear as two blocks in the Simulink® block library. However, they are the same Simulink block with different settings of a Select delay type parameter. Use this parameter to specify the mode in which the block operates.

### Variable Time Delay

In this mode, the block has a data input, a time delay input, and a data output. (See Port Location After Rotating or Flipping in the Simulink documentation for a description of the port order for various block orientations.) The output at the current time step equals the value of its data input at a previous time step. This time step is the current simulation time minus a delay time specified by the time delay input.

`$y\left(t\right)=u\left(t-{t}_{0}\right)=u\left(t-\tau \left(t\right)\right)$`

During the simulation, the block stores time and input value pairs in an internal buffer. At the start of simulation, the block outputs the value of the Initial output parameter until the simulation time exceeds the time delay input. Then, at each simulation step, the block outputs the signal at the time that corresponds to the current simulation time minus the delay time.

If you want the output at a time between input storing times and the solver is a continuous solver, the block interpolates linearly between points. If the time delay is smaller than the step size, the block extrapolates an output point from a previous point. For example, consider a fixed-step simulation with a step size of 1 and the current time at t = 5. If the delay is 0.5, the block needs to generate a point at t = 4.5, but the most recent stored time value is at t = 4. Thus, the block extrapolates the input at 4.5 from the input at 4 and uses the extrapolated value as its output at t = 5.

Extrapolating forward from the previous time step can produce a less accurate result than extrapolating back from the current time step. However, the block cannot use the current input to calculate its output value because the input port does not have direct feedthrough.

If the model specifies a discrete solver, the block does not interpolate between time steps. Instead, it returns the nearest stored value that precedes the required value.

### Variable Transport Delay

In this mode, the block output at the current time step is equal to the value of its data (top, or left) input at an earlier time step equal to the current time minus a transportation delay.

`$y\left(t\right)=u\left(t-{t}_{d}\left(t\right)\right)$`

Simulink software finds the transportation delay, ${t}_{d}\left(t\right)$, by solving the following equation:

`${\int }_{t-{t}_{d}\left(t\right)}^{t}\frac{1}{{t}_{i}\left(\tau \right)}d\tau =1$`

This equation involves an instantaneous time delay, ${t}_{i}\left(t\right)$, given by the time delay (bottom, or right) input.

Suppose you want to use this block to model the fluid flow through a pipe where the fluid speed varies with time. In this case, the time delay input to the block is

`${t}_{i}\left(t\right)=\frac{L}{{v}_{i}\left(t\right)}$`

where L is the length of the pipe and ${v}_{i}\left(t\right)$ is the speed of the fluid.

## Data Type Support

The Variable Time Delay and Variable Transport Delay blocks accept and output real signals of type `double`.

## Parameters

### Select delay type

Specify the mode in which the block operates.

#### Settings

Default: The Variable Time Delay block has a default value of `Variable time delay`. The Variable Transport Delay block has a default value of ```Variable transport delay```.

`Variable time delay`

Specifies a Variable Time Delay block.

`Variable transport delay`

Specifies a Variable Transport Delay block.

#### Dependencies

Setting this parameter to `Variable time delay` enables the Handle zero delay parameter.

Setting this parameter to `Variable transport delay` enables the Absolute tolerance and State Name parameters.

#### Command-Line Information

 Parameter: `VariableDelayType` Type: character vector Value: ```'Variable transport delay'``` | `'Variable time delay'` Default: ```'Variable time delay'```

### Maximum delay

Set the maximum value of the time delay input.

#### Settings

Default: `10`

• This value defines the largest time delay input that this block allows. The block clips any delay that exceeds this value.

• This value cannot be negative. If the time delay becomes negative, the block clips it to zero and issues a warning message.

#### Command-Line Information

 Parameter: `MaximumDelay` Type: scalar or vector Value: `'10'` Default: `'10'`

### Initial output

Specify the output that the block generates until the simulation time first exceeds the time delay input.

#### Settings

Default:`Run-to-run tunable parameter`

A `Run-to-run tunable parameter` cannot be changed during simulation run time. However, changing it before a simulation begins will not cause Accelerator or Rapid Accelerator to regenerate code. Also, the initial output of this block cannot be `inf` or `NaN`.

#### Command-Line Information

 Parameter: `InitialOutput` Type: scalar or vector Value: `'0'` Default: `'0'`

### Initial buffer size

Define the initial memory allocation for the number of input points to store. The input points define the history of the input signal up to the current simulation time.

#### Settings

Default: `1024`

• If the number of input points exceeds the initial buffer size, the block allocates additional memory.

• After simulation ends, a message displays if the buffer is not sufficient and more memory needs to be allocated.

#### Tips

• Because allocating memory slows down simulation, choose this value carefully if simulation speed is an issue.

• For long time delays, this block might use a large amount of memory, particularly for dimensionalized input.

#### Command-Line Information

 Parameter: `MaximumPoints` Type: scalar Value: `'1024'` Default: `'1024'`

### Use fixed buffer size

Specify use of a fixed-size buffer to save input data from previous time steps.

#### Settings

Default: Off

On

The block uses a fixed-size buffer.

Off

The block does not use a fixed-size buffer.

The Initial buffer size parameter specifies the buffer size. If the buffer is full, new data replaces data already in the buffer. Simulink software uses linear extrapolation to estimate output values that are not in the buffer.

 Note:   ERT or GRT code generation uses a fixed-size buffer even if you do not select this check box.

#### Tips

• If the input data is linear, selecting this check box can save memory.

• If the input data is nonlinear, do not select this check box. Doing so might yield inaccurate results.

#### Command-Line Information

 Parameter: `FixedBuffer` Type: character vector Value: `'off'` | `'on'` Default: `'off'`

### Handle zero delay

Convert this block to a direct feedthrough block.

#### Settings

Default: Off

On

The block uses direct feedthrough.

Off

The block does not use direct feedthrough.

#### Dependency

Setting Select delay type to ```Variable time delay``` enables this parameter.

#### Command-Line Information

 Parameter: `ZeroDelay` Type: character vector Value: `'off'` | `'on'` Default: `'off'`

### Direct feedthrough of input during linearization

Cause the block to output its input during linearization and trim, which sets the block mode to direct feedthrough.

#### Settings

Default: Off

On

Enables direct feedthrough of input.

Off

Disables direct feedthrough of input.

#### Tips

• Selecting this check box can cause a change in the ordering of states in the model when you use the functions `linmod`, `dlinmod`, or `trim`. To extract this new state ordering:

1. Compile the model using the following command, where `model` is the name of the Simulink model.

``` [sizes, x0, x_str] = model([],[],[],'lincompile'); ```
2. Terminate the compilation with the following command.

``` model([],[],[],'term'); ```
• The output argument `x_str`, which is a cell array of the states in the Simulink model, contains the new state ordering. When you pass a vector of states as input to the `linmod`, `dlinmod`, or `trim` functions, the state vector must use this new state ordering.

#### Command-Line Information

 Parameter: `TransDelayFeedthrough` Type: character vector Value: `'off'` | `'on'` Default: `'off'`

Set the order of the Pade approximation for linearization routines.

#### Settings

Default: `0`

• The default value is 0, which results in a unity gain with no dynamic states.

• Setting the order to a positive integer `n` adds `n` states to your model, but results in a more accurate linear model of the transport delay.

#### Command-Line Information

 Parameter: `PadeOrder` Type: character vector Value: `'0'` Default: `'0'`

### Absolute tolerance

Specify the absolute tolerance for computing the block state.

Default: `auto`

• You can enter `auto`, `-1`, or a positive real scalar or vector.

• If you enter `auto`, or `-1`, then Simulink uses the absolute tolerance value in the Configuration Parameters dialog box (see Solver Pane) to compute the block states.

• If you enter a real scalar, then that value overrides the absolute tolerance in the Configuration Parameters dialog box for computing all block states.

• If you enter a real vector, then the dimension of that vector must match the dimension of the continuous states in the block. These values override the absolute tolerance in the Configuration Parameters dialog box.

#### Dependency

Setting Select delay type to ```Variable transport delay``` enables this parameter.

#### Command-Line Information

 Parameter: `AbsoluteTolerance` Type: character vector, scalar, or vector Value: `'auto'` | `'-1'` | any positive real scalar or vector Default: `'auto'`

### State Name (e.g., 'position')

Assign a unique name to each state.

#### Settings

Default: `' '`

If this field is blank, no name assignment occurs.

#### Tips

• To assign a name to a single state, enter the name between quotes, for example, `'velocity'`.

• To assign names to multiple states, enter a comma-delimited list surrounded by braces, for example, `{'a', 'b', 'c'}`. Each name must be unique.

• The state names apply only to the selected block.

• The number of states must divide evenly among the number of state names.

• You can specify fewer names than states, but you cannot specify more names than states.

For example, you can specify two names in a system with four states. The first name applies to the first two states and the second name to the last two states.

• To assign state names with a variable in the MATLAB® workspace, enter the variable without quotes. A variable can be a character vector, cell array, or structure.

#### Dependency

Setting Select delay type to ```Variable transport delay``` enables this parameter.

#### Command-Line Information

 Parameter: `ContinuousStateAttributes` Type: character vector Value: `' '` | user-defined Default: `' '`

## Examples

The `sldemo_VariableTransportDelay` and `sldemo_VariableTransportDelay_pipe` models show how you can use the Variable Transport Delay block.

The `sldemo_VariableTransportDelay` model shows how to model vertical wheel displacement on a one-dimensional car. The Variable Transport Delay block models the delay in vertical displacement of the rear wheel when the road profile changes:

The `sldemo_VariableTransportDelay_pipe` model shows how to model incompressible flow through a fixed-length pipe. The Variable Transport Delay block models the delay in temperature change at the outlet when fluid flow occurs:

## Characteristics

 Data Types Double Sample Time Continuous Direct Feedthrough Yes, of the time delay (second) input Multidimensional Signals No Variable-Size Signals No Zero-Crossing Detection No Code Generation Yes