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?"
Practice
Solution
Step 1: Understand PWM meaning
PWM stands for Pulse Width Modulation, a method to control power by changing signal ON/OFF times.Step 2: Identify PWM purpose in Simulink
In Simulink, PWM controls power by switching signals ON and OFF quickly to adjust power delivery.Final Answer:
Pulse Width Modulation; it controls power by switching signals ON and OFF quickly. -> Option CQuick Check:
PWM = Pulse Width Modulation controlling power [OK]
- Confusing PWM with measuring signals
- Thinking PWM stores data
- Mixing PWM with battery management
Solution
Step 1: Recall Simulink blocks for PWM
The Pulse Generator block is designed to create pulses with adjustable width and frequency.Step 2: Match block to PWM function
Since PWM requires pulses with specific widths, the Pulse Generator block is the correct choice.Final Answer:
Pulse Generator block -> Option AQuick Check:
Pulse Generator block creates PWM pulses [OK]
- Choosing Gain block which scales signals
- Selecting Integrator block which sums signals
- Picking Scope block which only displays signals
Solution
Step 1: Calculate ON time from pulse width and period
ON time = Pulse Width (%) x Period = 30% x 10 = 0.3 x 10 = 3 seconds.Step 2: Confirm units and values
Period is in seconds, so ON time is 3 seconds.Final Answer:
3 seconds -> Option AQuick Check:
ON time = 30% x 10 = 3 seconds [OK]
- Using amplitude instead of period for calculation
- Confusing pulse width percentage with time
- Calculating OFF time instead of ON time
Solution
Step 1: Understand pulse width limits
Pulse Width should be between 0% and 100%. Values above 100% mean the signal is ON all the time.Step 2: Predict simulation behavior
With 110%, the block treats it as always ON, so the output stays high continuously.Final Answer:
The block will generate a continuous ON signal (always high). -> Option BQuick Check:
Pulse Width > 100% means always ON [OK]
- Expecting simulation error for >100% pulse width
- Thinking signal stays OFF
- Assuming default pulse width is used
Solution
Step 1: Calculate period from frequency
Period = 1 / Frequency = 1 / 50 = 0.02 seconds.Step 2: Set pulse width and amplitude
Duty cycle is 40%, so Pulse Width = 40%. Amplitude should match motor voltage level to control speed.Final Answer:
Set Period = 0.02 seconds, Pulse Width = 40%, Amplitude = motor voltage level -> Option DQuick Check:
Period = 1/50 = 0.02s, Pulse Width = 40% [OK]
- Using period equal to frequency value
- Setting wrong pulse width different from duty cycle
- Confusing period units (seconds vs milliseconds)
Ready to prove it?
Pass the test and this pattern moves unknown
