Unit delay block in Simulink - Time & Space Complexity
We want to understand how the time cost changes when using a Unit Delay block in Simulink models.
Specifically, how the block's execution time grows as the input size or simulation steps increase.
Analyze the time complexity of the following Unit Delay block operation in a simulation loop.
for k = 2:n
y(k) = u(k-1); % Unit Delay output
end
This code simulates the Unit Delay block outputting the previous input value at each step.
Look for repeated actions in the code.
- Primary operation: Assigning output y(k) from input u(k-1) inside a loop.
- How many times: The loop runs once for each simulation step, n-1 times.
Each simulation step does one simple operation. So, if we double the steps, the work doubles.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 9 |
| 100 | 99 |
| 1000 | 999 |
Pattern observation: The number of operations grows directly with the number of steps.
Time Complexity: O(n)
This means the time to run the Unit Delay block grows linearly with the number of simulation steps.
[X] Wrong: "The Unit Delay block does all its work at once, so time does not grow with steps."
[OK] Correct: The block processes each step one by one, so more steps mean more work and more time.
Understanding how simple blocks like Unit Delay scale helps you reason about simulation performance and model efficiency.
What if the Unit Delay block was replaced with a block that processes multiple past inputs at each step? How would the time complexity change?
Practice
Unit Delay block in Simulink do?Solution
Step 1: Understand the function of Unit Delay block
The Unit Delay block holds the input value and outputs it one time step later, effectively delaying the signal by one step.Step 2: Compare options with the definition
Only Outputs the previous input value, delaying the signal by one step correctly describes this behavior; others describe different or incorrect behaviors.Final Answer:
Outputs the previous input value, delaying the signal by one step -> Option AQuick Check:
Unit Delay = previous input output [OK]
- Thinking it outputs current input immediately
- Confusing with blocks that sum inputs
- Assuming it outputs random or initial values only
Solution
Step 1: Identify how initial conditions are set in Unit Delay
The Unit Delay block has a parameter called 'Initial condition' in its dialog box where you specify the output value at the first time step.Step 2: Evaluate the options
Set the 'Initial condition' parameter in the block's dialog box correctly states this method. Options B, C, and D describe indirect or incorrect ways.Final Answer:
Set the 'Initial condition' parameter in the block's dialog box -> Option CQuick Check:
Initial condition set inside block dialog [OK]
- Trying to set initial condition outside the block
- Using other blocks to simulate initial condition
- Assuming MATLAB workspace variable sets it automatically
Solution
Step 1: Understand Unit Delay output behavior
At each time step, output is the input from the previous step. At step 1, output is initial condition (0).Step 2: Calculate output for each step
Step 1 output: 0 (initial condition)
Step 2 output: input at step 1 = 1
Step 3 output: input at step 2 = 3
Step 4 output: input at step 3 = 5Final Answer:
[0, 1, 3, 5] -> Option BQuick Check:
Output lags input by one step [OK]
- Outputting current input instead of previous
- Forgetting initial condition at first step
- Shifting output incorrectly by more than one step
Solution
Step 1: Analyze the initial condition effect
The Unit Delay block outputs the initial condition at the first step if set properly.Step 2: Identify why output is zero instead of 5
If output is zero, likely the initial condition parameter was not set or saved correctly in the block dialog.Final Answer:
The initial condition parameter was not set correctly in the block -> Option AQuick Check:
Initial condition must be set inside block [OK]
- Assuming input signal affects initial output
- Thinking connection errors cause initial output zero
- Believing Simulink ignores initial conditions
Solution
Step 1: Understand the requirement
The output should be current input plus previous input value.Step 2: Use Unit Delay to get previous input
A Unit Delay block outputs the previous input. Adding this output to the current input gives the desired sum.Step 3: Evaluate options
Add the current input to the output of a Unit Delay block that delays the input by one step correctly describes this setup. Options A, B, and D do not produce the required output.Final Answer:
Add the current input to the output of a Unit Delay block that delays the input by one step -> Option DQuick Check:
Sum = current input + delayed input [OK]
- Using multiple Unit Delay blocks unnecessarily
- Misusing initial condition to store sums
- Multiplying instead of adding signals
Ready to prove it?
Pass the test and this pattern moves unknown
