Error signal computation in Simulink - Time & Space Complexity
We want to understand how the time to compute an error signal changes as input size grows.
How does the number of operations grow when we calculate the difference between signals?
Analyze the time complexity of the following code snippet.
// Simulink model snippet for error signal computation
error = reference_signal - measured_signal;
This code calculates the error by subtracting the measured signal from the reference signal element-wise.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Element-wise subtraction of two signals (arrays).
- How many times: Once for each element in the input signals.
Each element requires one subtraction operation, so the total work grows with the number of elements.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 subtractions |
| 100 | 100 subtractions |
| 1000 | 1000 subtractions |
Pattern observation: The number of operations grows directly in proportion to the input size.
Time Complexity: O(n)
This means the time to compute the error grows linearly with the number of signal elements.
[X] Wrong: "The error computation takes constant time no matter the input size."
[OK] Correct: Because each element must be processed, the time grows with the number of elements, not fixed.
Understanding how simple operations scale helps you explain performance clearly and confidently in real projects.
"What if the signals were matrices instead of vectors? How would the time complexity change?"
Practice
Solution
Step 1: Understand the definition of error signal and match to options
The error signal is defined as the difference between what is desired (reference) and what is actually produced (output). The difference between the desired and actual output values correctly states this difference, while others describe unrelated operations.Final Answer:
The difference between the desired and actual output values -> Option DQuick Check:
Error signal = desired - actual [OK]
- Confusing error with sum or product of signals
- Thinking error is a delay or time difference
- Mixing input and output signals
Solution
Step 1: Identify block for error calculation and eliminate others
The Sum block can be configured to subtract one input from another, which matches error signal computation. Gain multiplies, Integrator accumulates, Scope only displays signals, so they do not compute error.Final Answer:
Sum block with configuration to subtract output from reference -> Option CQuick Check:
Sum block subtracts signals for error [OK]
- Choosing Gain block which multiplies instead of subtracts
- Confusing Scope as a computation block
- Using Integrator which accumulates rather than subtracts
Solution
Step 1: Subtract output values from reference values element-wise
Calculate 5-3=2, 7-7=0, 9-10=-1. The resulting error signal is [2, 0, -1].Final Answer:
[2, 0, -1] -> Option AQuick Check:
Error = Reference - Output = [2, 0, -1] [OK]
- Adding instead of subtracting signals
- Mixing order: output - reference instead of reference - output
- Copying output values as error
Solution
Step 1: Understand correct error signal formula and identify setup issue
Error signal is Reference minus Output, so adding them is incorrect. Sum block configured to add will produce wrong error values, leading to incorrect control or training.Final Answer:
The error signal should be Reference minus Output, not their sum -> Option BQuick Check:
Error = Reference - Output, not Reference + Output [OK]
- Configuring Sum block to add instead of subtract
- Using Gain block unnecessarily for subtraction
- Assuming inputs cannot be connected to same block
Solution
Step 1: Calculate error signal and understand its importance
Subtract each output value from 10: 10-8=2, 10-12=-2, 10-9=1, 10-11=-1, resulting in [2, -2, 1, -1]. The error shows how much the output deviates from desired value, guiding adjustments to improve system performance.Final Answer:
[2, -2, 1, -1]; it shows how far output deviates from desired value to adjust control -> Option AQuick Check:
Error = Reference - Output; deviation guides control [OK]
- Adding signals instead of subtracting
- Reversing subtraction order
- Ignoring error's role in control adjustment
Ready to prove it?
Pass the test and this pattern moves unknown
