Total Harmonic Distortion (THD) in Power Electronics - Time & Space Complexity
When calculating Total Harmonic Distortion (THD), we want to know how the work needed grows as we include more harmonics.
We ask: How does the calculation time increase when we analyze more harmonic frequencies?
Analyze the time complexity of the following code snippet.
// Calculate THD by summing squares of harmonic amplitudes
function calculateTHD(harmonics) {
let sumSquares = 0;
for (let i = 1; i < harmonics.length; i++) {
sumSquares += harmonics[i] * harmonics[i];
}
return Math.sqrt(sumSquares) / harmonics[0];
}
This code calculates THD by looping through all harmonic amplitudes except the fundamental, summing their squares, then dividing by the fundamental amplitude.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through the harmonic amplitudes array once.
- How many times: Exactly once for each harmonic beyond the first (fundamental).
As the number of harmonics increases, the number of operations grows directly with it.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 9 additions and multiplications |
| 100 | 99 additions and multiplications |
| 1000 | 999 additions and multiplications |
Pattern observation: The work grows in a straight line as more harmonics are added.
Time Complexity: O(n)
This means the time to calculate THD increases proportionally with the number of harmonics analyzed.
[X] Wrong: "Calculating THD takes the same time no matter how many harmonics we include."
[OK] Correct: Each additional harmonic adds more calculations, so the time grows with the number of harmonics.
Understanding how calculation time grows with input size shows you can analyze and explain performance, a useful skill in many technical discussions.
"What if we only calculated THD using every other harmonic? How would the time complexity change?"
Practice
Solution
Step 1: Understand the definition of THD
THD measures how much extra unwanted signals (harmonics) are present compared to the main signal.Step 2: Compare options with the definition
Only the option describing the amount of unwanted harmonic frequencies compared to the main signal matches the definition of THD.Final Answer:
The amount of unwanted harmonic frequencies compared to the main signal -> Option BQuick Check:
THD = unwanted harmonics / main signal [OK]
- Confusing THD with total voltage
- Thinking THD measures frequency only
- Mixing THD with power consumption
Solution
Step 1: Recall the THD formula
THD is calculated as the square root of the sum of squares of harmonic voltages divided by the fundamental voltage (V1).Step 2: Match formula to options
THD = √(V2² + V3² + ... + Vn²) / V1 matches the correct formula: THD = √(V2² + V3² + ... + Vn²) / V1.Final Answer:
THD = √(V2² + V3² + ... + Vn²) / V1 -> Option DQuick Check:
THD formula uses root sum squares over fundamental [OK]
- Using addition instead of root sum squares
- Dividing fundamental by harmonics instead of reverse
- Multiplying voltages instead of dividing
Solution
Step 1: Calculate root sum squares of harmonics
√(3² + 4²) = √(9 + 16) = √25 = 5 volts.Step 2: Divide by fundamental voltage
THD = 5 / 10 = 0.5.Final Answer:
0.5 -> Option AQuick Check:
THD = 5/10 = 0.5 [OK]
- Adding harmonic voltages instead of root sum squares
- Dividing fundamental by harmonics
- Mixing up voltage values
Solution
Step 1: Identify the correct THD calculation method
THD requires squaring each harmonic voltage, summing, then taking the square root before dividing by fundamental voltage.Step 2: Analyze the student's formula
The student summed harmonic voltages directly without squaring, which underestimates the distortion.Final Answer:
They forgot to square the harmonic voltages before summing -> Option CQuick Check:
THD needs squares of harmonics, not simple sums [OK]
- Summing harmonics directly without squares
- Ignoring square root step
- Mixing voltage units
Solution
Step 1: Calculate root sum squares of harmonic voltages
√(12² + 9² + 5²) = √(144 + 81 + 25) = √250 ≈ 15.81 volts.Step 2: Calculate THD percentage
THD = (15.81 / 120) x 100% ≈ 13.18%.Step 3: Choose closest option
13.5% is the closest approximate value among the options.Final Answer:
13.5% -> Option AQuick Check:
THD ≈ 13.2% closest to 13.5% [OK]
- Forgetting to multiply by 100 for percentage
- Adding harmonics instead of root sum squares
- Rounding errors without checking options
Ready to prove it?
Pass the test and this pattern moves unknown
