This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Delay

Delay input signal by fixed or variable sample periods

  • Library:
  • Simulink / Commonly Used Blocks

    Simulink / 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 several 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 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.

The table shows the Delay block output for the first few time steps with these settings. 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 Delay length parameter and Tstart is the simulation start time for the model

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

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, specify the initial condition on the dialog box. 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

Ports

Input

expand all

Input data signal delayed according to parameters settings.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point | enumerated | bus

Delay length specified as inherited from an input port. Enabled when you select the Delay length: Source parameter as Input port.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Enable signal that enables or disables execution of the block. To create this port, select the Show enable port parameter.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point

External signal that resets execution of the block to the initial condition. To create this port, select the External reset parameter.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point

Initial condition specified as inherited from an input port. Enabled when you select the Initial Condition: Source parameter as Input port.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Output

expand all

Output signal that is the input signal delayed by the length of time specified by the parameter Delay length. The initial value of the output signal depends on several conditions. See Initial Block Output.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Main

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 noninteger value from an input port (variable delay) truncates it to the integer.

Programmatic Use

Block Parameter: DelayLengthSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'
Block Parameter: DelayLength
Type: character vector
Values: scalar
Default: '2'
Block Parameter: DelayLengthUpperLimit
Type: character vector
Values: scalar
Default: '100'

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.

Programmatic Use

Block Parameter: InitialConditionSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'
Block Parameter: InitialCondition
Type: character vector
Values: scalar
Default: '0.0'

Specify whether the block performs sample- or frame-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 (DSP System Toolbox).

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

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 (DSP System Toolbox).

Programmatic Use

Block Parameter: InputProcessing
Type: character vector
Values: 'Columns as channels (frame based)' | 'Elements as channels (sample based)'
Default: 'Elements as channels (sample based)'

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.

Programmatic Use

Block Parameter: UseCircularBuffer
Type: character vector
Values: 'off' | 'on'
Default: 'off'

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.

Dependency

To enable this parameter, set Delay length: Source to Input port.

Programmatic Use

Block Parameter: PreventDirectFeedthrough
Type: character vector
Values: 'off' | 'on'
Default: 'off'

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

Dependency

To enable this parameter, set Delay length: Source to Input port.

Programmatic Use

Block Parameter: RemoveDelayLengthCheckInGeneratedCode
Type: character vector
Values: 'off' | 'on'
Default: 'off'

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.

  • 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 — Simulink software takes no action.

  • Warning — Simulink software displays a warning and continues the simulation.

  • Error — Simulink software terminates the simulation and displays an error.

Dependency

To enable this parameter, set Delay length: Source to Input port.

Programmatic Use

Block Parameter: DiagnosticForDelayLength
Type: character vector
Values: 'None' | 'Warning' | 'Error'
Default: 'None'

Select to control execution of this block with an enable port. 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.

Programmatic Use

Block Parameter: ShowEnablePort
Type: character vector
Values: 'off' | 'on'
Default: 'off'

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

Reset in either of these cases:

  • when the reset signal is nonzero at the current time step

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

Level holdReset when the reset signal is nonzero at the current time step

Programmatic Use

Block Parameter: ExternalReset
Type: character vector
Values: 'None' | 'Rising' | 'Falling' | 'Either' | 'Level' | 'Level hold'
Default: 'None'

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.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Value: real scalar
Default: '-1'

State Attributes

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 Apply Storage Classes to Individual Signal, State, and Parameter Data Elements (Simulink Coder).

Programmatic Use

Block Parameter: StateName
Type: character vector
Values: unique name
Default: ''

Select this check box to require that the state name resolves to a Simulink signal object.

Dependencies

To enable this parameter, specify a value for State name. This parameter appears only if you set the model configuration parameter Signal resolution to a value other than None.

Selecting this check box disables Code generation storage class.

Programmatic Use

Block Parameter: StateMustResolveToSignalObject
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Choose a custom storage class package by selecting a signal object class that the target package defines. For example, to apply custom storage classes from the built-in package mpt, select mpt.Signal. Unless you use an ERT-based code generation target with Embedded Coder®, custom storage classes do not affect the generated code.

If the class that you want does not appear in the list, select Customize class lists. For instructions, see Target Class Does Not Appear in List of Signal Object Classes (Embedded Coder).

For information about storage classes, see Apply Storage Classes to Individual Signal, State, and Parameter Data Elements (Simulink Coder). For information about custom storage classes, see Apply Custom Storage Classes to Individual Signal, State, and Parameter Data Elements (Embedded Coder).

Programmatic Use

Block Parameter: StateSignalObject
Type: character vector
Values: 'Simulink.Signal' | '<StorageClass.PackageName>'
Default: 'Simulink.Signal'

Select state storage class for code generation.

Use Signal object class to select custom storage classes from a package other than Simulink.

Dependencies

To enable this parameter, specify a value for State name.

Programmatic Use

Block Parameter: StateStorageClass
Type: character vector
Values: 'Auto' | 'SimulinkGlobal' | 'ExportedGlobal' | 'ImportedExtern' | 'ImportedExternPointer' | 'Custom' | ...
Default: 'Auto'

Block Characteristics

Data Types

double | single | Boolean | base integer | fixed point | enumerated | bus

Direct Feedthrough

Yes

Multidimensional Signals

Yes

Variable-Size Signals

Yes

Zero-Crossing Detection

No

Extended Capabilities

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Convert floating-point algorithms to fixed point using Fixed-Point Designer™.

Introduced before R2006a