Documentation Center

  • Trials
  • Product Updates

Unit Delay

Delay signal one sample period

Library

Discrete

Description

The Unit Delay block holds and delays its input by the sample period you specify. 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.

When the Unit Delay block inherits a continuous sample time, the block is analogous to the Memory block.

    Tip   Do not use the Unit Delay block to create a slow-to-fast transition between blocks operating at different sample rates. Instead, use the Rate Transition block.

Comparison with Similar Blocks

Blocks with Similar Functionality

The Unit Delay, Memory, and Zero-Order Hold blocks provide similar functionality but have different capabilities. Also, the purpose of each block is different. The sections that follow highlight some of these differences.

Recommended Usage for Each Block

BlockPurpose of the BlockReference Examples
Unit DelayImplement a delay using a discrete sample time that you specify. Ideally, the block accepts and outputs signals with a discrete sample time.
MemoryImplement a delay by one 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.

Overview of Block Capabilities

CapabilityBlock
Unit DelayMemoryZero-Order Hold
Specification of initial conditionYesYesNo, because the block output at time t = 0 must match the input value.
Specification of sample timeYesNo, because the block can only inherit sample time (from the driving block or the solver used for the entire model).Yes
Support for frame-based signalsYesNo Yes
Support for state loggingYesNoNo

Effect of Solver Specification on Block Output

When you specify a discrete sample time in the dialog box for a Unit Delay or Zero-Order Hold block, the block output can differ depending on the solver specification for the model.

Suppose that you have a modelmodel with Unit Delay and Zero-Order Hold blocks, which both use a discrete sample time of 1:

The Repeating Sequence Stair block uses a continuous sample time of 0 to provide input signals to the Unit Delay and Zero-Order Hold blocks.

If the model uses a fixed-step solver with a step size of 1, the scope shows the following simulation results:

If the model uses a variable-step solver, the scope shows the following simulation results:

The Zero-Order Hold block takes the input value of the Repeating Sequence Stair block at t = 0, 1, 2, ... , 9 and holds each input value for a sample period (1 second). The Unit Delay block applies the same 1-second hold to each input value of the Repeating Sequence Stair block, but also delays each value by a sample period. The Initial conditions parameter specifies the output for the Unit Delay block during the first sample period. For more information about sample time, see What Is Sample Time? and Specify Sample Time.

Solver specification for a model also affects the behavior of the Memory block. For details, see Examples of Memory Block Usage.

Data Type Support

The Unit Delay block accepts real or complex signals of any data type that Simulink® supports, including fixed-point and enumerated data types. If the data type of the input signal is user-defined, the initial condition must be zero.

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

Parameters and Dialog Box

During simulation, the block uses the following values:

  • The initial value of the signal object to which the state name is resolved

  • Min and Max values of the signal object

For more information, see States in the Simulink Coder™ documentation.

Initial condition

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

Settings

Default: 0

The Initial conditions parameter is converted from a double to the input data type offline using round-to-nearest and saturation.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Input processing

Specify whether the Unit Delay block performs sample- or frame-based processing.

Settings

Default: Elements as channels (sample based)

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

Inherited

Sets the block to 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.

Dependency

Frame-based processing requires a DSP System Toolbox license.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Sample time (-1 for inherited)

Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.

Settings

Default: -1

By default, the block inherits its sample time based upon the context of the block within the model. To set a different sample time, enter a valid sample time based upon the table in Types of Sample Time.

See also Specify Sample Time in the online documentation for more information.

Command-Line Information

See Block-Specific Parameters for the command-line information.

State name

Use this parameter to assign a unique name to each state.

Settings

Default: ' '

  • If left blank, no name is assigned.

Tips

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

Dependency

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

For more information, see States in the Simulink Coder documentation.

Command-Line Information

Parameter: StateIdentifier
Type: string
Value: ' '
Default: ' '

State name must resolve to Simulink signal object

Require that state name resolve to Simulink signal object.

Settings

Default: Off

On

Require that state name resolve to Simulink signal object.

Off

Do not require that state name resolve to Simulink signal object.

Dependencies

State name enables this parameter.

Selecting this check box disables Code generation storage class.

Command-Line Information

Parameter: StateMustResolveToSignalObject
Type: string
Value: 'off' | 'on'
Default: 'off'

Package

Select a package that defines the custom storage class you want to apply.

Settings

Default: ---None---

---None---

Sets internal storage class attributes.

mpt

Applies the built-in mpt package.

Simulink

Applies the built-in Simulink package.

Dependencies

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 state storage class.

Settings

Default: Auto

Auto

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

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.

Dependencies

State name enables this parameter.

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

Command-Line Information

Command-Line Information

Parameter: StateStorageClass
Type: string
Value: 'Auto' | 'ExportedGlobal' | 'ImportedExtern' | 'ImportedExternPointer'
Default: 'Auto'

Code generation storage class

Select custom storage class for state.

Settings

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.

Dependencies

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.

See Also

State Storage Classes in the Simulink Coder documentation.

Code generation storage type qualifier

Specify the Simulink Coder storage type qualifier.

Settings

Default: ' '

If left blank, no qualifier is assigned.

Dependency

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

Command-Line Information

Parameter: RTWStateStorageTypeQualifier
Type: string
Value: ' '
Default: ' '

Bus Support

The Unit Delay block is a bus-capable block. The input can be a virtual or nonvirtual bus signal subject to the following restrictions:

  • Initial conditions must be zero, a nonzero scalar, or a finite numeric structure.

  • If Initial conditions is zero or a structure, and you specify a State name, the input cannot be a virtual bus.

  • If Initial conditions is a nonzero scalar, no State name can be specified.

For information about specifying an initial condition structure, see Specify Initial Conditions for Bus Signals.

All signals in a nonvirtual bus input to a Unit Delay block must have the same sample time, even if the elements of the associated bus object specify inherited sample times. You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus. See Composite Signals and Bus-Capable Blocks for more information.

Examples

For an example of how to use the Unit Delay block, see the sldemo_enginewcsldemo_enginewc model. The Unit Delay block appears in the Compression subsystem.

Characteristics

Bus-capable

Yes, with restrictions as noted in Bus Support

Direct Feedthrough

No

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes, of input or initial conditions

States

Yes, inherited from the driving block for nonfixed-point data types

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?