- Add the “Variable Integer Delay” block ( Simulink → Discrete → Variable Integer Delay) and set Maximum delay to the highest expected sample delay (e.g., 10 for 10 ms at 1 kHz).
- Set Initial condition to the desired starting value of the signal and enable Allow delay length to be zero.
- Convert delay in milliseconds to delay in samples.
- Feed the delay length from the workspace by creating a workspace variable “delay_ms” that you set before simulation. You can use a “MATLAB Function block” to convert “delay_ms” to “delay_samples” and connect it to the delay length input port of the “Variable Integer Delay” block. An example MATLAB Function block:
Simulink Dynamic Signal Delay
11 views (last 30 days)
Show older comments
Hi all, I need to delay a signal in Simulink to simulate a hardware delay. I need to dynamically set this delay in the workspace to a value of 0, 4, 8, or 10 ms, and have a specific signal be delayed by that amount of time pursuant to a specified initial condition of the signal. I have tried using a transport delay block and delay block with limited success. Can anyone help me figure out how to do this? I have some comments on my previous attempts below. Thanks!
For the transport delay, the delay will be inside of an atomic unit operating at a fixed rate, and the transport delay is error-ing out and saying that it must inherit the time from a non-atomic block. I must be using the atomic unit with that specified rate, so I don't think there's a workaround here.
For the delay block, I run into problems when dynamically setting the delay to 0. Since the delay block needs NxM initial condition where N is the number of time steps to delay, setting that to 0 leads to an error.
0 Comments
Answers (1)
Riya
on 13 Aug 2025
Hi Will,
I understand that you are trying to implement a variable delay in Simulink to simulate a hardware delay of 0 ms, 4 ms, 8 ms, or 10 ms, with the delay value dynamically set from the MATLAB workspace. Also, you will need this to work inside an “atomic subsystem operating” at a fixed rate, with a specified initial condition for the delayed signal.
The current setup errors out inside an atomic subsystem because the block requires inherited sample time from a non-atomic block. The “Delay” block also causes issues when it is set to zero, since it requires an initial condition vector whose size depends on the number of delay steps.
To resolve this, I recommend using the “Variable Integer Delay” block instead which will solve the issue you are encountering. Kindly refer to the following implementation steps:
function N = ms2samples(delay_ms)
Fs = 1000; % Sampling frequency in Hz
N = uint32(round(delay_ms * Fs / 1000));
End
This method resolves the Transport Delay’s atomic subsystem compatibility issue and the “Delay” block’s zero-delay initial condition problem, while allowing full dynamic control from the workspace.
For more details on the “Variable Integer Delay” block, you can refer to the documentation below:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!