Documentation

Delay

Delay input signal by fixed or variable sample periods

Library

Discrete

Description

The Delay block outputs the input of the block after a delay. The block determines the delay time based on the value of the Delay length parameter. The block supports:

  • Variable delay length

  • Specification of the initial condition from an input port

  • State storage

  • Using a circular buffer instead of an array buffer for state storage

  • Resetting the state to the initial condition with an external reset signal

  • Controlling execution of the block at every time step with an external enable signal

The initial block output depends on a number of factors such as the Initial condition parameter and the simulation start time. For more information, see Initial Block Output. The External reset parameter determines if the block output resets to the initial condition on triggering. The Show enable port parameter determines if the block execution is controlled in every time step by an external enable signal.

Initial Block Output

The output of the Delay block in the first few time steps of the simulation depends on the block sample time, the delay length, and the simulation start time. The block supports specifying or inheriting discrete sample times to determine the time interval between samples. For more information, see Specify Sample Time.

Suppose that the block inherits a discrete sample time as [Tsampling,Toffset], where Tsampling is the sampling period and Toffset is the initial time offset. n is the value of the block's Delay length parameter and Tstart is the simulation start time for the model.

The table shows the Delay block output for the first few time steps.

Simulation Time RangeBlock Output

(Tstart) to (Tstart + Toffset)

Zero

(Tstart + Toffset) to (Tstart + Toffset + n * Tsampling)

Initial condition parameter

After (Tstart + Toffset + n * Tsampling)

Input signal

Data Type Support

The block's parameters have these dimensional requirements:

  • Delay length and External reset must be scalar.

  • Initial condition can be scalar or nonscalar.

  • For frame-based processing, signal dimensions of the data input port u cannot be larger than two.

The block supports input signals with these data types.

Input SignalSupported Data Types
Data input port u
  • Floating point

  • Built-in integer

  • Fixed point

  • Boolean

  • Enumerated

Delay length d
  • Floating point

  • Fixed-point integer

  • Built-in integer

Enable port
  • Floating point

  • Built-in integer

  • Fixed point Integer (only ufix1)

  • Boolean

External reset port
  • Floating point

  • Built-in integer

  • Fixed point Integer (only ufix1)

  • Boolean

Initial condition x0
  • Floating point

  • Built-in integer

  • Fixed point

  • Boolean

  • Enumerated

When u is Boolean, x0 must be Boolean. When u uses an enumerated type, x0 must use the same enumerated type. Otherwise, x0 can use a floating-point, built-in integer, or fixed-point data type that fits in the data type of u. For example, when u uses int32, x0 can use int8 but not double.

The data type of the output signal is the same as the input signal u.

For more information, see Data Types Supported by Simulink.

Variable-Size Support

The Delay block provides the following support for variable-size signals:

  • The data input port u accepts variable-size signals. The other input ports do not accept variable-size signals.

  • The output port has the same signal dimensions as the data input port u for variable-size inputs.

The rules that apply to variable-size signals depend on the input processing mode of the Delay block.

Input Processing ModeRules for Variable-Size Signal Support
Elements as channels (sample based)
  • The signal dimensions change only during state reset when the block is enabled.

  • The initial condition must be scalar.

Columns as channels (frame based)
  • No support

Inherited
(where input is a sample-based signal)
  • The signal dimensions change only during state reset when the block is enabled.

  • The initial condition must be scalar.

Inherited
(where input is a frame-based signal)
  • The channel size changes only during state reset when the block is enabled.

  • The initial condition must be scalar.

  • The frame size must be constant.

Bus Support

The Delay block provides the following support for bus signals:

  • The data input port u accepts virtual and nonvirtual bus signals. The other input ports do not accept bus signals.

  • The output port has the same bus type as the data input port u for bus inputs.

  • Buses work with:

    • Sample-based and frame-based processing

    • Fixed and variable delay length

    • Array and circular buffers

To use a bus signal as the input to a Delay block, you should specify the initial condition on the dialog box. In other words, the initial condition cannot come from the input port x0. Support for virtual and nonvirtual buses depends on the initial condition that you specify and whether the State name parameter is empty or not.

Initial ConditionState Name
EmptyNot Empty
ZeroVirtual and nonvirtual bus supportNonvirtual bus support only
Nonzero scalarVirtual and nonvirtual bus supportNo bus support
NonscalarNo bus supportNo bus support
StructureVirtual and nonvirtual bus supportNonvirtual bus support only
Partial structureVirtual and nonvirtual bus supportNonvirtual bus support only

Parameters and Dialog Box

Delay length

Specify whether to enter the delay length directly on the dialog box (fixed delay) or to inherit the delay from an input port (variable delay).

  • If you set Source to Dialog, enter the delay length in the edit field under Value.

  • If you set Source to Input port, verify that an upstream signal supplies a delay length for the d input port. You can also specify its maximum value by specifying the parameter Upper limit.

Specify the scalar delay length as a real, non-negative integer. An out-of-range or non-integer value in the dialog box (fixed delay) returns an error. An out-of-range value from an input port (variable delay) casts it into the range. A non-integer value from an input port (variable delay) truncates it to the integer.

This parameter is not tunable for simulation or code generation.

Initial condition

Specify whether to enter the initial condition directly on the dialog box or to inherit the initial condition from an input port.

  • If you set Source to Dialog, enter the initial condition in the edit field under Value.

  • If you set Source to Input port, verify that an upstream signal supplies an initial condition for the x0 input port.

Simulink® converts offline the data type of Initial condition to the data type of the input signal u using a round-to-nearest operation and saturation.

    Note:   When State name must resolve to Simulink signal object is selected on the State Attributes pane, the block copies the initial value of the signal object to the Initial condition parameter. However, when the source for Initial condition is Input port, the block ignores the initial value of the signal object.

Input processing

Specify whether the block performs sample- or frame-based processing. You can select one of the following options:

  • Elements as channels (sample based) — Treat each element of the input as a separate channel (sample-based processing).

  • Columns as channels (frame based) — Treat each column of the input as a separate channel (frame-based processing).

      Note:   Frame-based processing requires a DSP System Toolbox™ license.

      For more information, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.

  • Inherited — Inherit the processing mode from the input signal and delay the input accordingly. You can identify whether the input signal is sample or frame based by looking at the signal line. Simulink represents sample-based signals with a single line and frame-based signals with a double line.

      Note:   When you choose the Inherited option for the Input processing parameter, and the input signal is frame-based, Simulink will generate a warning or error in future releases.

Use Input processing to specify whether the block performs sample- or frame-based processing. The block accepts frame-based signals for the input u. All other input signals must be sample based.

Input Signal uInput Processing ModeBlock Works?
Sample basedSample basedYes
Frame basedNo, produces an error
Sample basedFrame basedYes
Frame basedYes
Sample basedInheritedYes
Frame basedYes

For more information about these two processing modes, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.

Use circular buffer for state

Select to use a circular buffer for storing the state in simulation and code generation. Otherwise, an array buffer stores the state.

Using a circular buffer can improve execution speed when the delay length is large. For an array buffer, the number of copy operations increases as the delay length goes up. For a circular buffer, the number of copy operations is constant for increasing delay length.

If one of the following conditions is true, an array buffer always stores the state because a circular buffer does not improve execution speed:

  • For sample-based signals, the delay length is 1.

  • For frame-based signals, the delay length is no larger than the frame size.

Prevent direct feedthrough by increasing delay length to lower limit

Select to increase the delay length from zero to the lower limit for the Input processing mode:

  • For sample-based signals, increase the minimum delay length to 1.

  • For frame-based signals, increase the minimum delay length to the frame length.

Selecting this check box prevents direct feedthrough from the input port, u, to the output port. However, this check box cannot prevent direct feedthrough from the initial condition port, x0, to the output port.

This check box is available when you set Delay length: Source to Input port.

Remove protection against out-of-range delay length in generated code

Select to remove code that checks for out-of-range delay length.

Check BoxResultWhen to Use

Selected

Generated code does not include conditional statements to check for out-of-range delay length.

For code efficiency

Cleared

Generated code includes conditional statements to check for out-of-range delay length.

For safety-critical applications

This check box is available when you set Delay length: Source to Input port.

Diagnostic for out-of-range delay length

Specify whether to produce a warning or error when the input d is less than the lower limit or greater than the Delay length: Upper limit. The lower limit depends on the setting for Prevent direct feedthrough by increasing delay length to lower limit.

  • If the check box is cleared, the lower limit is zero.

  • If the check box is selected, the lower limit is 1 for sample-based signals and frame length for frame-based signals.

Options for the diagnostic include:

  • None — No warning or error appears.

  • Warning — Display a warning in the MATLAB® Command Window and continue the simulation.

  • Error — Stop the simulation and display an error in the Diagnostic Viewer.

This parameter is available when you set Delay length: Source to Input port.

Show enable port

Select to show an enable port for this block. This port can control execution of the block. The block is considered enabled when the input to this port is nonzero, and is disabled when the input is 0. The value of the input is checked at the same time step as the block execution.

External reset

Specify the trigger event to use to reset the states. The reset trigger resets the state to the initial condition and then copies it to the output at that time step.

Reset ModeBehavior
NoneNo reset.
RisingReset on a rising edge.
FallingReset on a falling edge.
EitherReset on either a rising or falling edge.
LevelReset in either of these cases:
  • when there is a nonzero at the current time step

  • when the time step value changes from nonzero at the previous time step to zero at the current time step

Level holdReset when nonzero at the current time step.

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. This block supports discrete sample time, but not continuous sample time.

State name

Use this parameter to assign a unique name to the block state. The default is ' '. When this field is blank, no name is assigned. When using this parameter, remember these considerations:

  • A valid identifier starts with an alphabetic or underscore character, followed by alphanumeric or underscore characters.

  • The state name applies only to the selected block.

This parameter enables State name must resolve to Simulink signal object when you click Apply.

For more information, see Discrete Block State Naming in Generated Code in the Simulink Coder™ documentation.

State name must resolve to Simulink signal object

Select this check box to require that the state name resolve to a Simulink signal object. This check box is cleared by default.

State name enables this parameter.

Selecting this check box disables Code generation storage class.

Package

Select a package that defines the custom storage class you want to apply. If you have defined any packages of your own, click Refresh. This action adds all user-defined packages on your search path to the package list.

Code generation storage class

Select custom storage class for state.

Default: Auto

Auto

Auto is the appropriate storage class for states that you do not need to interface to external code.

SimulinkGlobal

model_P initializes the state to its corresponding value in the workspace.

ExportedGlobal

State is stored in a global variable

ImportedExtern

model_private.h declares the state as an extern variable.

ImportedExternPointer

model_private.h declares the state as an extern pointer.

Default

A non-editable placeholder storage class is created.

BitField

A struct declaration is created that embeds Boolean data.

Volatile

Volatile type qualifier is used in state declaration.

ExportToFile

Header (.h) file containing global variable declarations is generated with user-specified name.

ImportFromFile

Predefined header (.h) files containing global variable declarations are included.

FileScope

A static qualifier is generated in front of the state declaration to make the state visible only to the current file.

Struct

A struct declaration is created to encapsulate parameter or signal object data.

StructVolatile

Volatile type qualifier is used in struct declaration.

GetSet

Supports specialized function calls to read and write memory.

State name enables this parameter.

The list of valid storage classes differs based on the Package selection.

Setting this parameter to ExportedGlobal, ImportedExtern, or ImportedExternPointer enables Code generation storage type qualifier.

Code generation storage type qualifier

Specify a Simulink Coder storage type qualifier. The default is ' '. When this field is blank, no qualifier is assigned.

The Simulink Coder product does not check this string for errors. Thus, whatever value you enter appears automatically in the variable declaration.

Setting Code generation storage class to ExportedGlobal, ImportedExtern, or ImportedExternPointer enables this parameter.

Examples

Variable-Size Signals for Sample-Based Processing

This model shows how the Delay block supports variable-size signals for sample-based processing.

The Switch block controls whether the input signal to the enabled subsystem is a 3-by-3 or 3-by-2 matrix. The Delay block appears inside the enabled subsystem.

The model follows the rules for variable-size signals when the Delay block uses sample-based processing.

RuleHow the Model Follows the Rule

The signal dimensions change only during state reset when the block is enabled.

The Enable block sets Propagate sizes of variable-size signals to Only when enabling.

The initial condition must be scalar.

The Delay block sets Initial condition to 0.0, a scalar value.

Bus Signals for Frame-Based Processing

This model shows how the Delay block supports bus signals for frame-based processing.

Each Constant block supplies an input signal to the Bus Creator block, which outputs a two-dimensional bus signal. After the Delay block delays the bus signal by three sample periods, the Bus Selector block separates the bus back into the two original signals.

The model follows the rules for bus signals when the Delay block uses frame-based processing.

RuleHow the Model Follows the Rule

For the initial condition, set the value on the dialog box.

The Delay block sets Initial condition to 0, a scalar value.

For frame-based processing, signal dimensions of the data input port u cannot be larger than two. (This rule applies to all inputs for the port u, not just bus signals.)

The bus input to the Delay block has two dimensions.

Enable or Disable Execution of the Delay Block

This example shows how you can enable or disable the execution of the Delay block using the enable port of the block. Consider this model. A ramp input signal feeds into a Delay block whose execution is controlled by an enabling signal. A Pulse Generator block generates this enabling signal.

The Scope block displays the output of the Delay block along with the enabling signal and the ramp input. Simulating the model and viewing the scope output shows the following graph.

The magenta marks show that the Delay block outputs the input signal delayed by one time step only while the enabling signal is 1. At t=5 sec, the enabling signal becomes 0 and the Delay block does not execute. Hence, the output is held constant until the next time the enabling signal becomes 1.

Characteristics

Data Types

Double | Single | Boolean | Base Integer | Fixed-Point | Enumerated | Bus

Sample Time

Specified in the Sample time parameter

Direct Feedthrough

Yes, when you clear Prevent direct feedthrough by increasing delay length to lower limit

Multidimensional Signals

Yes

Variable-Size Signals

Yes

Zero-Crossing Detection

No

Code Generation

Yes

Was this topic helpful?