PWM generation in Simulink - Time & Space Complexity
We want to understand how the time needed to generate PWM signals changes as the input size changes.
Specifically, how does the system behave when the number of PWM channels or signal resolution increases?
Analyze the time complexity of the following PWM generation setup in Simulink.
% Simulink model snippet for PWM generation
% 1. Compare input signal with carrier waveform
% 2. Generate PWM output based on comparison
% 3. Repeat for each PWM channel
for i = 1:N_channels
pwm_output(i) = input_signal(i) > carrier_waveform;
end
This code compares each input signal with a carrier waveform to create PWM signals for multiple channels.
Look at what repeats in this process.
- Primary operation: Comparing input signals to the carrier waveform.
- How many times: Once for each PWM channel, so N times.
As the number of PWM channels increases, the number of comparisons grows directly with it.
| Input Size (N_channels) | Approx. Operations |
|---|---|
| 10 | 10 comparisons |
| 100 | 100 comparisons |
| 1000 | 1000 comparisons |
Pattern observation: The operations increase in a straight line as channels increase.
Time Complexity: O(N)
This means the time to generate PWM signals grows directly with the number of channels.
[X] Wrong: "The time to generate PWM signals stays the same no matter how many channels there are."
[OK] Correct: Each channel needs its own comparison, so more channels mean more work and more time.
Understanding how time grows with input size helps you explain system performance clearly and confidently in real projects.
"What if we increased the resolution of the carrier waveform instead of the number of channels? How would the time complexity change?"