Source blocks (Constant, Step, Sine Wave, Ramp) in Simulink - Time & Space Complexity
We want to understand how the time it takes to run source blocks in Simulink changes as we increase the simulation time or sample points.
How does the work grow when we ask the block to produce more data?
Analyze the time complexity of these source blocks generating signals over time.
Constant block: outputs a fixed value every time step
Step block: outputs one value before a step time, another after
Sine Wave block: computes sine of time at each step
Ramp block: outputs a value increasing linearly with time
Each block produces output at every simulation step for the total simulation duration.
Each block performs an operation at every simulation step.
- Primary operation: Calculate or output signal value per time step
- How many times: Once per simulation step, repeated for all steps
As the number of simulation steps increases, the total operations increase proportionally.
| Input Size (n = steps) | Approx. Operations |
|---|---|
| 10 | 10 calculations or outputs |
| 100 | 100 calculations or outputs |
| 1000 | 1000 calculations or outputs |
Pattern observation: The work grows linearly as we increase the number of steps.
Time Complexity: O(n)
This means the time to generate the signal grows directly with the number of simulation steps.
[X] Wrong: "The source blocks do all their work once and then just output values instantly."
[OK] Correct: Each step requires the block to produce a value, so the work repeats for every step, not just once.
Understanding how repeated operations scale helps you explain performance in simulations and real-time systems clearly and confidently.
"What if the simulation used variable step sizes instead of fixed steps? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand the behavior of each source block
The Constant block outputs a fixed value that does not change over time. The Step block changes value at a specified time. The Sine Wave block outputs a sinusoidal signal. The Ramp block outputs a linearly increasing or decreasing signal.Step 2: Identify the block with fixed output
Only the Constant block maintains the same value throughout the simulation without change.Final Answer:
Constant block -> Option DQuick Check:
Fixed value = Constant block [OK]
- Confusing Step block with Constant because both output numbers
- Thinking Sine Wave can be constant
- Assuming Ramp outputs fixed value
Solution
Step 1: Recall Step block parameters
The Step block changes its output from Initial value to Final value at the specified Step time.Step 2: Identify correct parameter settings for change at 5 seconds
To change at 5 seconds, Step time must be 5. Final value is the new output after 5 seconds.Final Answer:
Set Step time to 5 and Final value to new value -> Option CQuick Check:
Step time = 5 for change at 5 seconds [OK]
- Setting Step time to 0 causes immediate change
- Confusing Initial and Final values
- Setting wrong Step time for desired change
Solution
Step 1: Understand Ramp block output formula
Output = Initial output + slope * time. Here, initial output = 1, slope = 3.Step 2: Calculate output at each time
At t=0: 1 + 3*0 = 1; t=2: 1 + 3*2 = 7; t=4: 1 + 3*4 = 13.Step 3: Match calculated values with options
The calculated outputs [1, 7, 13] match [1, 7, 13].Final Answer:
[1, 7, 13] -> Option BQuick Check:
Output = 1 + 3*t matches [1,7,13] [OK]
- Forgetting to add initial output
- Multiplying slope by wrong time values
- Mixing up options with similar numbers
Solution
Step 1: Understand Step block timing
The Step block changes output at Step time. If Step time is after simulation ends, change never happens during simulation.Step 2: Analyze given values
Initial value = 0, Final value = 10, so values differ. If output never changes, likely Step time is beyond simulation time.Final Answer:
Step time is set after simulation end time -> Option AQuick Check:
Step time > simulation time means no output change [OK]
- Assuming Initial equals Final value causes no change
- Ignoring simulation stop time
- Confusing Step time with Final value
Solution
Step 1: Analyze signal requirements
Signal starts at 2, constant until 3 seconds, then increases smoothly by 4 units per second.Step 2: Choose blocks to model behavior
Use Step block to hold value at 2 until 3 seconds (change from 2 to 2 at 3 seconds means no jump). Then use Ramp block starting at 3 seconds with slope 4 to increase smoothly.Step 3: Confirm other options
Constant block with value 2 and Ramp block starting at 3 seconds with slope 4 is incorrect because Ramp cannot start at 3 seconds alone without Step block. Step block changing from 2 to 6 at 3 seconds is wrong because Step block changes instantly, not smoothly. Sine Wave block with amplitude 2 and frequency 4 is unrelated sine wave.Final Answer:
Step block from 2 to 2 at 3 seconds and Ramp block starting at 3 seconds with slope 4 -> Option AQuick Check:
Step holds constant, Ramp adds smooth increase [OK]
- Using only Step block causes sudden jump
- Using Constant block alone can't model increase
- Confusing Sine Wave with linear increase
Ready to prove it?
Pass the test and this pattern moves unknown
