Fourier Series Builder: Add Harmonics, Watch the Wave

Pick a waveform and the number of harmonics. The partial sum is drawn over the ideal wave, with each coefficient and how much of the signal's power the harmonics carry.

Partial sum (solid) over the ideal wave (muted), two periods
-101-1-0.500.51t / Tx(t)

Harmonics 1 to 5 carry 93.31% of the signal's power. The partial sum peaks at 1.188 (the Gibbs overshoot stays near 9% of the jump however many harmonics you add).

Coefficients
na_nb_nAmplitude
10.00001.27321.2732
20.00000.00000.0000
30.00000.42440.4244
40.00000.00000.0000
50.00000.25460.2546

The formulas

x(t)=a0+∑n=1∞[ancos⁡(nω0t)+bnsin⁡(nω0t)]x(t) = a_0 + \sum_{n=1}^{\infty} \left[a_n \cos(n\omega_0 t) + b_n \sin(n\omega_0 t)\right]

a0 is the average; an and bn are found by integrating x(t) against each cosine and sine over one period.

P=a02+∑n=1∞an2+bn22P = a_0^2 + \sum_{n=1}^{\infty} \dfrac{a_n^2 + b_n^2}{2}

Parseval's theorem: the average power is the sum of the powers in the DC term and each harmonic.

Worked example: building a square wave

  1. A ±1 square wave has bn = 4/(nπ) for odd n and nothing else: b1 = 1.2732, b3 = 0.4244, b5 = 0.2546.
  2. Its average power is 1. The fundamental alone carries (4/π)²/2 = 81.1% of it; harmonics 1, 3 and 5 together carry 93.3%.
  3. However many harmonics you add, the partial sum overshoots the jump to about 1.179, 9% of the jump height on each side: the Gibbs phenomenon.
  4. A triangle wave is continuous, so its coefficients fall as 1/n² and the fundamental alone carries 98.5% of its power, with no overshoot.
  • Coefficients fall as 1/n for a waveform with jumps and as 1/n² for one with only corners, which is why the triangle converges so much faster.
  • Waveforms with half-wave symmetry, such as the square and triangle, have only odd harmonics.

Sources