Fourier Series
calculator.
Rebuild a repeating signal from sines and cosines, and see how many terms it takes.
- Average, a₀ over 2
- 0
- Energy held
- 95.98%
- Peak of the sum
- 1.1823
f is odd, so only sine terms appear. 9 harmonics hold 96% of its energy. It jumps, so the sum peaks at 1.1823 against 1 for f.
The sum over f
Drag the point along x to read the sum there. The dotted line is the harmonic chosen under the spectrum.
f(x) = sign(x) over two periods, with the partial sum of 9 harmonics on top. The sum peaks at 1.1823 against a peak of 1 for f. At x = 1.571 the sum is 1.0631.
Working
- 1Period and harmonicsf(x) = sign(x) on [−3.1416, 3.1416], repeated every 2L = 6.2832
- 2The constant term is the average of fa₀ = 1L∫ f(x) dx = 0, so a₀2 = 0
- 3First harmonic: multiply by a cosine or a sine, then integratea₁ = 0, b₁ = 1.2732
- 4Symmetryf is odd, so every aₙ is 0 and only sine terms remain.
- 5Strongest harmonicn = 1, with amplitude √aₙ2 + bₙ2 = 1.2732
- 6Check with Parseval’s theorem: the squares must add up to the energy of f1L∫ f² dx = 1.9997; 9 harmonics hold 1.9192, which is 95.98% of it
Amplitude spectrum
Harmonic 1: amplitude 1.2732, phase 90°, a = 0 and b = 1.2732.
Coefficients and amplitudes
| aₙ | bₙ | Phase | ||
|---|---|---|---|---|
| 1 | 0 | 1.2732 | 1.2732Phase 90° | 90° |
| 2 | 0 | 0 | 0Phase 0° | 0° |
| 3 | 0 | 0.4244 | 0.4244Phase 90° | 90° |
| 4 | 0 | 0 | 0Phase 0° | 0° |
| 5 | 0 | 0.2546 | 0.2546Phase 90° | 90° |
| 6 | 0 | 0 | 0Phase 0° | 0° |
| 7 | 0 | 0.1819 | 0.1819Phase 90° | 90° |
| 8 | 0 | 0 | 0Phase 0° | 0° |
| 9 | 0 | 0.1415 | 0.1415Phase 90° | 90° |
How the sum improves with more harmonics
Energy and peak as N grows
| Harmonics N | Energy held | Peak of the sum |
|---|---|---|
| 1 | 81.07% | 1.2732 |
| 3 | 90.08% | 1.2004 |
| 5 | 93.32% | 1.1884 |
| 11 | 96.65% | 1.1813 |
| 21 | 98.18% | 1.1797 |
| 51 | 99.24% | 1.179 |
| 99 | 99.61% | 1.179 |
Energy held climbs toward 100%. If f jumps, the peak settles above f instead of falling to it. That gap is the Gibbs overshoot.
How it's worked out
A Fourier series/09:_Partial_Differential_Equations/9.03:_Fourier_Series) writes a function that repeats every 2L as a constant plus waves. Each wave fits a whole number of times into one period. Here L is the half-period, so a period of 2π means . The wave with number n is called harmonic n.
To find how much of a wave is in f, multiply f by that wave and integrate over one period. Every other wave averages out to 0, so only the one you want is left.
The cosine formula with gives a₀, and that is why the series starts with half of it: is the average of f over a period. The tool works each integral out with Simpson's rule on 4,096 panels. Each harmonic can also be written as one shifted wave, with amplitude and phase given by the angle of the point .
The check. Parseval's theorem says the squares of all the coefficients add up to the energy of f, which is times the integral of f squared. So the share that N harmonics hold tells you how much of f the sum has captured.
Worked examples
Elena expands a square wave
Elena's signal is −1 for negative x and 1 for positive x, repeating every 2π. It is an odd function, so every aₙ is 0. Only odd harmonics of sine appear, with : that gives 1.2732 for , 0.4244 for and 0.2546 for .
With 9 harmonics, the sum holds 96% of the energy, yet it peaks at 1.182, above the wave's height of 1. That is the Gibbs overshoot. Adding more terms makes the bump narrower but no shorter, and with 99 harmonics it still peaks at 1.179.
Kai looks at a rectifier's output
A single diode passes the top half of a sine wave and blocks the rest. Kai types that as max(0, sin x). The average is 0.3183 of the peak, which is the direct voltage a filter would pull out.
The first harmonic is a sine of size 0.5, half the input. The next one is a cosine at twice the frequency, with size 0.2122. That second term is the ripple the filter has to remove. The function is neither odd nor even, so both kinds of wave appear.
x² gives a famous sum
On [−π, π], x² is even, so only cosines appear, with . The first is −4, and the average is 3.2899.
Now set . The signs cancel, so every term turns positive, and the series rearranges into a result you may have seen before:
With 5 harmonics, the sum at π is 9.1443, against the true 9.8696. The gap closes slowly at this corner, because the repeated curve has a sharp point there.
Reading your result
Zeros in the table are real. For an even function/09:_Partial_Differential_Equations/9.04:_Fourier_Sine_and_Cosine_Series) every bₙ is 0, and for an odd one every aₙ is 0. The tool also rounds anything under about a billionth of the function's size to 0, so rounding noise does not look like a harmonic.
Smooth functions need fewer terms. A jump makes coefficients shrink like , and a corner like . So a triangle wave passes far more of its energy in the first few harmonics than a square wave does.
| N | Square wave | Triangle wave |
|---|---|---|
| 1 | 81.07% | 99.638% |
| 3 | 90.08% | 99.943% |
| 11 | 96.65% | 99.998% |
| 21 | 98.18% | 100% |
| 99 | 99.61% | 100% |
The peak near a jump settles near 1.179 for a wave that jumps from −1 to 1, per the sine integral. That is about 9% of the jump of 2. At the jump itself, the series settles on the midpoint of the two sides, which is 0 here.
Other periods. Set L to half of your period. For a sawtooth with period 4, use , and the formula can use L by name, as in . Its first sine has size 0.6366, and a triangle wave's first harmonic with has size 0.4053.
Common mistakes
The tool goes up to 100 harmonics, which still leaves about 40 samples per cycle at the top of the range. For a list of measured samples and not a formula, use the discrete Fourier transform calculator.
- Using the whole period for L. L is half the period. A signal that repeats every 4 needs , or every coefficient comes out wrong.
- Forgetting the half on a₀. The constant term is , not a₀. Some books define a₀ as the average itself, so check which one yours uses before you compare.
- Typing a function that is not on −L to L. The tool reads f on that interval. If your function is given on 0 to 2L, write the same period in terms of the shifted x, or use a form that repeats correctly.
- Expecting more terms to cure the overshoot. Near a jump the peak height does not fall. It only gets narrower.