Unit Delay

Delay signal one sample period

  • Library:
  • Simulink / Discrete

    HDL Coder / Discrete

  • Unit Delay block

Description

The Unit Delay block holds and delays its input by the sample period you specify. When placed in an iterator subsystem, it holds and delays its input by one iteration. This block is equivalent to the z-1 discrete-time operator. The block accepts one input and generates one output. Each signal can be scalar or vector. If the input is a vector, the block holds and delays all elements of the vector by the same sample period.

You specify the block output for the first sampling period with the Initial conditions parameter. Careful selection of this parameter can minimize unwanted output behavior. You specify the time between samples with the Sample time parameter. A setting of -1 means the block inherits the Sample time.

Note

The Unit Delay block errors out if you use it to create a transition between blocks operating at different sample rates. Use the Rate Transition block instead.

Comparison with Similar Blocks

The Memory, Unit Delay, and Zero-Order Hold blocks provide similar functionality but have different capabilities. Also, the purpose of each block is different.

This table shows recommended usage for each block.

BlockPurpose of the BlockReference Examples
Unit DelayImplement a delay using a discrete sample time that you specify. The block accepts and outputs signals with a discrete sample time.
MemoryImplement a delay by one major integration time step. Ideally, the block accepts continuous (or fixed in minor time step) signals and outputs a signal that is fixed in minor time step.
Zero-Order HoldConvert an input signal with a continuous sample time to an output signal with a discrete sample time.

Each block has the following capabilities.

CapabilityMemoryUnit DelayZero-Order Hold
Specification of initial conditionYesYesNo, because the block output at time t = 0 must match the input value.
Specification of sample timeNo, because the block can only inherit sample time from the driving block or the solver used for the entire model.YesYes
Support for frame-based signalsNo YesYes
Support for state loggingNoYesNo

String Support

The Unit Delay block can accept and output string data type only if the block is configured for a delay length of 0 or 1 or for direct feedthrough.

Ports

Input

expand all

Input signal that the block delays by one sample period.

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

Output

expand all

Output signal that is the input delayed by one sample period.

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

Parameters

expand all

Main

Specify the output of the simulation for the first sampling period, during which the output of the Unit Delay block is otherwise undefined.

Programmatic Use

Block Parameter: InitialCondition
Type: character vector
Value: scalar | vector
Default: '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

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)'

Enter the discrete interval between sample time hits or specify -1 to inherit the sample time.

See also Specify 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 C Code Generation Configuration for Model Interface Elements (Simulink Coder).

Programmatic Use

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

Specify if requiring that state name resolve to Simulink signal objects or not. If selected, the software generates an error at run time if you specify a state name that does not match the name of a Simulink signal object.

Dependency

Enabled when you give the parameter State name a value and 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.

To use a storage class package other than the Simulink® package, you must load the package into the model's Embedded Coder Dictionary. See Load Storage Class Packages into Embedded Coder Dictionary (Embedded Coder).

For information about configuring model data by using storage classes, see C Code Generation Configuration for Model Interface Elements (Embedded Coder). For information about custom storage classes, see Organize Data into Structures in Generated Code (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. If you do not need to interface to external code, select Auto.

For more information, see C Code Generation Configuration for Model Interface Elements (Simulink Coder) and Organize Parameter Data into a Structure by Using Struct Storage Class (Embedded Coder).

Programmatic Use

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

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | half | integer | single | string

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
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a