Delay input signal by fixed or variable sample periods
expand all in page
Libraries:
Simulink / Commonly Used Blocks
Simulink / Discrete
DSP System Toolbox / Signal Operations
HDL Coder / Commonly Used Blocks
HDL Coder / Discrete
Description
The Delay block outputs the input of the block after a delay. The blockdetermines the delay time based on the value of the Delay lengthparameter. 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 resetsignal
Controlling execution of the block at every time step with an external enablesignal
The initial block output depends on several factors such as the Initialcondition parameter and the simulation start time. For more information,see Initial Block Output. The External reset parameterdetermines if the block output resets to the initial condition on triggering. TheShow enable port parameter determines if the block execution iscontrolled 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 blocksample time, the delay length, and the simulation start time. The block supportsspecifying or inheriting discrete sample times to determine the time intervalbetween samples. For more information, see Specify Sample Time.
The table shows the Delay block output for the first few time steps with thesesettings. The block inherits a discrete sample time as[
,where Tsampling
,Toffset
]
is the sampling periodand Tsampling
is the initial timeoffset. Toffset
n
is the value of the Delaylength parameter and
is the simulation starttime for the modelTstart
Simulation Time Range | Block Output |
---|---|
| Zero |
| Initial conditionparameter |
After | Input signal |
Behavior with External Enable Signal
Selecting the Show enable port check box enables the Enableport. If the enable port is enabled, the block operates in this order
Checks if the enable condition is satisfied.
If the reset port is enabled, checks the reset condition.
Performs the Delay block functionality.
The block has this operation with the Enable port:
At the first block enable, the block output is the initial condition value(
x0
).For consecutive enable signals, the block takes the last state of theinput signal u.
If the port is not enabled at the start of simulation, theDelay block outputs
0
.During simulation, if the port becomes disabled after having been enabled,the block does not execute and holds its last value.
Variable-Size Support
The Delay block provides the following support for variable-sizesignals:
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 modeof the Delay block.
Input Processing Mode | Rules for Variable-Size Signal Support |
---|---|
Elements as channels (sample based) |
|
Columns as channels (frame based) |
|
Bus Support
The Delay block provides the following support for bussignals:
The data input
u
accepts virtual and nonvirtual bussignals. Other than input portx0
, the other input portsdo not accept bus signals.The initial condition
x0
port accepts nonvirtual bussignals.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 theinitial condition on the dialog box or through the x0
port.Support for virtual and nonvirtual buses depends on the initial condition that youspecify and whether the State name parameter is empty or not.For the x0
input port, only nonvirtual buses aresupported.
Initial Condition | State Name | |
---|---|---|
Empty | Not Empty | |
Zero | Virtual and nonvirtual bus support | Nonvirtual bus support only |
Nonzero scalar | Virtual and nonvirtual bus support | No bus support |
Nonscalar | No bus support | No bus support |
Structure | Virtual and nonvirtual bus support | Nonvirtual bus support only |
Partial structure | Virtual and nonvirtual bus support | Nonvirtual bus support only |
String Support
The Delay block can accept and output string data type onlyif:
The block is configured for the default value of the Initialcondition parameter (0).
The Delay length value is 1 or less.
Examples
expand all
Using Variable-Size Signals on the Delay Block
Open Model
This example 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 these rules for variable-size signals while using sample-based processing.
Signal dimensions change only during state reset when the block is enabled.
Initial condition must be scalar.
The rules are implemented by these blocks.
Enable block sets Propagate sizes of variable-size signals to
Only when enabling
.Delay block sets the Initial condition to the scalar value
0.0
.
Buses with the Delay Block for Frame-Based Processing
Open Model
This example shows how the Delay block supports buses for frame-based processing.
Each Constant block supplies an input signal to the Bus Creator block, which outputs a two-dimensional bus. After the Delay block delays the bus by three sample periods, the Bus Selector block separates the bus back into the two original signals.
The model follows these rules for buses:
For the initial condition, set the value on the dialog box.
For frame-based processing, signal dimensions of the data input port
u
cannot be larger than two.
The model implements the rules by:
Setting Initial condition to a scalar value of
0
.Setting bus input to the Delay block as two dimensions.
Control Execution of Delay Block with Enable Port
Open Model
This example shows how you can enable or disable the execution of the Delay block using an enable port. In this model, a ramp input signal feeds into a Delay block. The execution of the block is controlled by an enabling signal from the Pulse Generator block.
The blue line shows that the Delay block outputs the input signal value delayed by one time step while the enabling signal has a value of one. At t=5
the enabling signal transitions to zero and the Delay block stops executing. The output is held at the last value until the block is enabled again.
Ports
Input
expand all
u — Data input signal
scalar | vector
Input data signal delayed according to parameters settings.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| string
| Boolean
| fixed point
| enumerated
| bus
d — Delay length
scalar
Delay length specified as inherited from an input port. Enabled whenyou select the Delay length: Source parameter asInput port
.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| fixed point
Enable — External enable signal
scalar
Enable signal that enables or disables execution of the block. Tocreate this port, select the Show enable portparameter.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
External reset — External reset signal
scalar
External signal that resets execution of the block to the initialcondition. To create this port, select the Externalreset parameter.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
x0 — Initial condition
scalar | vector
Initial condition specified as inherited from an input port. Enabledwhen you select the Initial Condition: Sourceparameter as Input port
.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
| bus
Output
expand all
Port_1 — Output signal
scalar | vector
Output signal that is the input signal delayed by the length of timespecified by the parameter Delay length. Theinitial value of the output signal depends on several conditions. SeeInitial Block Output.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| string
| Boolean
| fixed point
| enumerated
| bus
Parameters
expand all
Main
Delay length — Delay length
Dialog
(default) | Input port
Specify whether to enter the delay length directly on the dialog box(fixed delay) or to inherit the delay from an input port (variabledelay).
If you set Source to
Dialog
, enter the delay length inthe edit field under Value.If you set Source to
Inputport
, verify that an upstream signal suppliesa delay length for thed
input port. You canalso specify its maximum value by specifying the parameterUpper limit.
Specify the scalar delay length as a real, non-negative integer. Anout-of-range or non-integer value in the dialog box (fixed delay)returns an error. An out-of-range value from an input port (variabledelay) 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: charactervector |
Values:'Dialog' | 'Inputport' |
Default:'Dialog' |
Block Parameter:DelayLength |
Type: charactervector |
Values: scalar |
Default:'2' |
Block Parameter:DelayLengthUpperLimit |
Type: charactervector |
Values: scalar |
Default:'100' |
Initial condition — Initial condition
Dialog
(default) | Input port
Specify whether to enter the initial condition directly on the dialogbox or to inherit the initial condition from an input port.
If you set Source to
Dialog
, enter the initialcondition in the edit field underValue.If you set Source to
Inputport
, verify that an upstream signal suppliesan initial condition for thex0
inputport.
Simulink® converts offline the data type of Initialcondition to the data type of the input signalu
using a round-to-nearest operation andsaturation.
Note
When State name must resolve to Simulink signalobject is selected on the StateAttributes pane, the block copies the initial valueof the signal object to the Initial conditionparameter. However, when the source for Initialcondition is Input port
,the block ignores the initial value of the signal object.
Programmatic Use
Block Parameter:InitialConditionSource |
Type: charactervector |
Values:'Dialog' | 'Inputport' |
Default:'Dialog' |
Block Parameter:InitialCondition |
Type: charactervector |
Values: scalar |
Default:'0.0' |
Input processing — Specify sample- or frame-based processing
Elements as channels (sample based)
(default) | Columns as channels (frame based)
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. 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)' |
Use circular buffer for state — Circular buffer for storing state
off
(default) | on
Select to use a circular buffer for storing the state in simulationand code generation. Otherwise, an array buffer stores the state.
Using a circular buffer can improve execution speed when the delaylength is large. For an array buffer, the number of copy operationsincreases as the delay length goes up. For a circular buffer, the numberof copy operations is constant for increasing delay length.
If one of the following conditions is true, an array buffer alwaysstores the state because a circular buffer does not improve executionspeed.
For sample-based signals, the delay length is 1.
For frame-based signals, the delay length is no larger thanthe frame size.
Programmatic Use
Block Parameter:UseCircularBuffer |
Type: charactervector |
Values:'off' | 'on' |
Default:'off' |
Prevent direct feedthrough — Prevent direct feedthrough
off
(default) | on
Select to increase the delay length from zero to the lower limit forthe Input processing mode.
For sample-based signals, increase the minimum delay length to1.
For frame-based signals, increase the minimum delay length tothe frame length.
Selecting this check box prevents direct feedthrough from the inputport, u
, to the output port. However, this check boxcannot prevent direct feedthrough from the initial condition port,x0
, to the output port.
Dependency
To enable this parameter, set Delay length:Source to Inputport
.
Programmatic Use
Block Parameter:PreventDirectFeedthrough |
Type: charactervector |
Values:'off' | 'on' |
Default:'off' |
Remove delay length check in generated code — Remove delay length out-of-range check
off
(default) | on
Select to remove code that checks for out-of-range delaylength.
Check Box | Result | When to Use |
---|---|---|
Selected | Generated code does not include conditionalstatements to check for out-of-range delaylength. | For code efficiency |
Cleared | Generated code includes conditional statementsto check for out-of-range delaylength. | For safety-critical applications |
Dependency
To enable this parameter, set Delay length:Source to Inputport
.
Programmatic Use
Block Parameter:RemoveDelayLengthCheckInGeneratedCode |
Type: charactervector |
Values:'off' | 'on' |
Default:'off' |
Diagnostic for delay length — Diagnostic checks for delay length
None
(default) | Warning
| Error
Specify whether to produce a warning or error when the inputd
is less than the lower limit or greater thanthe Delay length: Upper limit. The lower limitdepends on the setting for Prevent directfeedthrough.
If the check box is cleared, the lower limit is zero.
If the check box is selected, the lower limit is 1 forsample-based signals and frame length for frame-basedsignals.
Options for the diagnostic include:
None
— Simulink software takes no action.Warning
— Simulink software displays a warning and continues thesimulation.Error
— Simulink software terminates the simulation and displays anerror.
Dependency
To enable this parameter, set Delay length:Source to Inputport
.
Programmatic Use
Block Parameter:DiagnosticForDelayLength |
Type: charactervector |
Values:'None' | 'Warning' |'Error' |
Default:'None' |
Show enable port — Create enable port
off
(default) | on
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' |
External reset — External state reset
None
(default) | Rising
| Falling
| Either
| Level
| Level hold
Specify the trigger event to use to reset the states to the initial conditions.
Reset Mode | Behavior |
---|---|
None | No reset |
Rising | Reset on a rising edge |
Falling | Reset on a falling edge |
Either | Reset on either a rising or falling edge |
Level | Reset in either of these cases:
|
Level hold | Reset 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' |
Sample time (-1 for inherited) — Discrete interval between sample time hits
-1
(default) | scalar
Specify the time interval between samples. To inherit the sample time,set this parameter to -1
. This block supportsdiscrete sample time, but not continuous sample time.
Programmatic Use
Block Parameter:SampleTime |
Type: charactervector |
Value: real scalar |
Default:'-1' |
State Attributes
State name — Unique name for block state
''
(default) | alphanumeric string
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 Data Code Interface Configuration for Model Interface Elements (Simulink Coder).
Programmatic Use
Block Parameter: StateName |
Type: character vector |
Values: unique name |
Default: '' |
State name must resolve to Simulink signal object — Require state name resolve to a signal object
off
(default) | on
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
.
Programmatic Use
Block Parameter: StateMustResolveToSignalObject |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
aPorts of this block have different direct feedthrough characteristics. |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on memcpy
ormemset
functions (string.h
) undercertain conditions.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides configuration options that affect HDL implementation andsynthesized logic.
Block Parameter Setting | Description |
---|---|
Set External reset toLevel . | Generates a reset port in the HDL code. |
Select Show enable port. | Generates an enable port in the HDL code. |
For Initial condition, setSource to Dialog and enter the value. | Specifies an initial condition for the block. |
Set Input processing to Columnsas channels (frame based) or Elementsas channels (sample based) . | Expects vector input data, where each element of the vectorrepresents a sample in time. |
Additional Settings When Using State Control Block
If you use a State Control block with the Delayblock inside a subsystem in your Simulink model, use these additional settings.
Block Parameter Setting | Description |
---|---|
Set External reset to Levelhold forSynchronous mode andLevel forClassic mode of the StateControl block. | Generates a reset port in the HDL code. |
Set Delay length to zero for aDelay block with an external enableport. | Treated as a wire in onlySynchronous mode of theState Control block. |
Set Delay length to zero for aDelay block with an external resetport. | Treated as a wire in Synchronous and Classic modes of the StateControl block. |
For more information about the State Control block, see State Control (HDL Coder).
HDL Architecture
This block has one default HDL architecture.
HDL Block Properties
AllowDelayDistribution | Allow delay to be distributed or absorbed during thedistributed pipelining and delay absorption optimizations.The default is |
InputPipeline | Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is |
OutputPipeline | Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is |
ResetType | Suppress reset logic generation. The default is |
UseRAM | Map delays to RAM instead of registers. The default is |
Variable Integer Delay Support
You can generate HDL code for the Delay block that hasDelay Length set through the
Input port
. Input delay length can beinteger types or floating-point types.The code generation supports positive integer values at the 'd' portof the delay block. The delay length set through the input port must bebetween
0
andUpper limit
,specified in the Block Parameters dialog box.For negative delay length values, HDL Coder translates these negative delay length to
0
.Similarly, if you specify delay length greater than the upper limit,HDL Coder translates the delay length to the
Upperlimit
value.Upper limit range is defined by the range of the delay length inputdata type. For example, if you specify delay length input data type as
uint8
, then the upper limit must not exceed255
.You can use enable and reset ports for the variable integer Delayblock.
Complex Data Support
This block supports code generation for complex signals.
Restrictions
For Initial condition,Source set to
Inputport
is not supported for HDL codegeneration.HDL code generation supports only the Boolean data type at theReset and Enable ports.
HDL Block Property UseRAM for RAM mapping isnot supported for Delay block that has DelayLength set through the
Inputport
.The Delay block that has Delay Lengthset through the
Input port
does notsupport bus and matrix data input for HDL code generation.
PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006a
See Also
Resettable Delay | Unit Delay | Variable Integer Delay | Tapped Delay
Topics
- Using Enabled Subsystems
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office