Documentation Center

  • Trial Software
  • Product Updates

Delay

Delay input signal by fixed or variable sample periods

Library

Discrete

Description

Supported Block Operations

The Delay block supports:

  • Variable delay length

  • Specification of the initial condition from an input port

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

  • State storage

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

The Delay block delays an input u according to the Delay length parameter, which you specify on the dialog box, or a delay length that a signal supplies to the d input port. The initial block output depends on the Initial condition parameter, which you specify on the dialog box, or an initial condition that a signal supplies to the x0 input port. Whether or not the block output resets to the initial condition depends on the External reset parameter, which you specify on the dialog box.

The following dimensional requirements apply:

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

Block Icon Appearance

The icon changes depending on the number of block inputs.

IconNumber of Inputs

One:

  • Input signal to delay, u

Two:

  • Input signal to delay, u

  • Delay length, d

Three:

  • Input signal to delay, u

  • Delay length, d

  • External reset

Four:

  • Input signal to delay, u

  • Delay length, d

  • External reset

  • Initial condition, x0

Data Type Support

The block supports input signals of the following data types:

Input SignalSupported Data Types
u
  • Floating point

  • Built-in integer

  • Fixed point

  • Boolean

  • Enumerated

d
  • Floating point

  • Fixed-point integer

  • Built-in integer

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.

When you specify Delay length and Initial condition on the dialog box, you can use the following data types for those parameters:

ParameterSupported Data Types
Delay length
  • Floating point

  • Fixed-point integer

  • Built-in integer

Initial condition
  • Floating point

  • Built-in integer

  • Fixed point

  • Boolean

  • Enumerated

For more information, see Data Types Supported by Simulink in the Simulink® documentation.

Parameters and Dialog Box

The Main pane of the Delay block dialog box appears as follows:

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, positive 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.

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.

External reset

Specify the trigger event to use to reset the states to the initial conditions.

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.

The reset signal must be a scalar of type single, double, boolean, or integer. Fixed point data types, except for ufix1, are not supported.

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.

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.

As described in Specify Sample Time, you can specify a discrete sample time as [Tsampling, Toffset], where Tsampling is the sampling period and Toffset is the initial time offset. If Tstart is the simulation start time and n is the delay length, the Delay block output is as follows.

Simulation Time RangeBlock Output

(Tstart) to (Tstart + Toffset)

Zero

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

Initial condition

After (Tstart + Toffset + n * Tsampling)

Input signal

If the Delay block inherits or specifies a nonzero value for Toffset, the Delay block outputs zero at Tstart. Otherwise, the Delay block outputs the initial condition at Tstart.

The State Attributes pane of the Delay block dialog box appears as follows:

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

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 must 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

Examples

Variable-Size Signals for Sample-Based Processing

This modelmodel 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 modelmodel 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.

Characteristics

Direct Feedthrough

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

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes, of the input u when Initial condition is nonscalar and sample-based processing applies

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?