Fourier Series
What is a Fourier series?
A Fourier series is a way of writing a periodic signal, one that repeats every seconds, as a sum of sine and cosine waves. The waves are the harmonics: the fundamental frequency and its whole-number multiples Each harmonic has its own amplitude, given by the signal's Fourier coefficients.

A square wave and its Fourier series with harmonics 1 to 15 (top), and the amplitude of each harmonic (bottom). Try the interactive version, where you can change the waveform and the number of harmonics.
- Any practical periodic signal is a sum of harmonics at , plus a constant (its average).
- The coefficients and come from one integral each over one period. The trigonometric, amplitude–phase and complex forms all hold the same information.
- A square wave contains only odd harmonics, with amplitude . The smoother a waveform, the faster its harmonics shrink.
- At a jump, a truncated series always overshoots by about 9% of the jump (the Gibbs phenomenon), however many terms you add.
- For sampled data, the DFT of one period gives the coefficients: .
How a Fourier series works
A Fourier series is a recipe for a repeating waveform. The ingredients are fixed: a constant, then sine and cosine waves at one, two, three times the repeat frequency, and so on. Only the amounts change from one waveform to the next. Those amounts are the coefficients.
The picture below builds a square wave from its first three ingredients. Each one is a sine wave that fits a whole number of cycles into one period, so the sum repeats with the same period as the square wave.
Three terms already give flat-ish tops and steep edges. Each extra odd harmonic adds a smaller, faster ripple that fills in more of the corners.
The coefficients are easy to find because sines and cosines at different harmonics are orthogonal: multiply two of them together and average over one period, and the result is zero unless they are the same harmonic. So to measure how much of harmonic a signal contains, multiply the signal by that harmonic's cosine (or sine) and average. Every other harmonic averages to zero and drops out.
The idea is named after Joseph Fourier, who used these series in his 1822 work on the flow of heat.
The Fourier series formula
For a signal with period , write the fundamental angular frequency as . The trigonometric Fourier series is:
and its Fourier series coefficients are integrals over any one period:
- is the average value of the signal over a period (the DC level). Writing it as lets the same formula work for .
- measures the cosine part of harmonic , and the sine part.
- Harmonic has frequency hertz. For a 50 Hz waveform, harmonic 3 is at 150 Hz.
- Stopping the sum at gives the partial sum , which is what a graph or a computer actually draws.
Amplitude–phase form
A cosine and a sine at the same frequency add up to one shifted cosine. So the series can also be written with one amplitude and one phase per harmonic:
is what a spectrum analyser shows as the height of each line, and it doesn't change if you shift the signal in time. Only the phases change.
Complex exponential form
Using Euler's formula, , the sines and cosines fold into one sum over positive and negative . This is the complex (or exponential) Fourier series:
The two sets of coefficients convert directly:
| Complex form | Trigonometric form |
|---|---|
| (the average) | |
| , for | |
| , the complex conjugate of for a real signal | |
| : half the amplitude sits at , half at |
The complex form is shorter to write and to manipulate, and it is the form the Fourier transform and the DFT grow out of. The trigonometric form is easier to picture.
Worked example: the Fourier series of a square wave
Take a square wave that is for the first half of each period and for the second half.
- Use the symmetry. The wave is an odd function, , so every cosine coefficient is zero: . Only the are left.
- Integrate each half of the period. With :
- Read off the pattern. is for odd and for even . So for odd , and for even .
The square wave's Fourier series is therefore:
| Harmonic | Share of the wave's power, up to and including | |
|---|---|---|
| 1 | 1.2732 | 81.1% |
| 3 | 0.4244 | 90.1% |
| 5 | 0.2546 | 93.3% |
| 7 | 0.1819 | 95.0% |
| up to 99 | 99.6% |
The power column uses Parseval's theorem: the mean square of the signal (here 1) equals . So the fundamental alone carries of a square wave's power, and the last few per cent are spread over a long tail of harmonics. That tail is what makes the edges sharp.
At the square wave is 1 and every sine is , so the series gives . That is the Leibniz series for .
Fourier series examples: square, sawtooth, triangle and pulse waves
All four waves below swing between and (the pulse train between 0 and 1) and repeat every . You can draw each of them, with any number of harmonics, in the live grapher.
| Waveform (one period) | Fourier series | Harmonics present | Amplitudes fall as | Power in the fundamental |
|---|---|---|---|---|
| Square, then | Odd only | 81.1% | ||
| Sawtooth, rising from to , centred on | All | 60.8% | ||
| Triangle, peak at | Odd only | 98.6% | ||
| Pulse train, 1 for a fraction of each period (the duty cycle), centred on | All, except where is a whole number | (under a sinc-shaped envelope) | depends on |
The smoother a waveform, the faster its coefficients fall, because the faster a waveform changes, the more high harmonics it needs:
- The square, sawtooth and pulse waves jump, so their coefficients fall only as . Even harmonic 99 still has about 1% of the fundamental's amplitude.
- The triangle is continuous but has corners (its slope jumps), so its coefficients fall as . Harmonic 9 is already down to about 1%.
- In general, if a signal and its first derivatives are continuous and the th derivative jumps, the coefficients fall as . A signal with no corners at all, such as a rounded pulse, needs very few harmonics.
So a square-wave clock signal radiates interference at high frequencies, and a triangle wave sounds much mellower than a square wave at the same pitch.
Pulse trains show one more effect. With , the coefficient is zero at , so every fourth harmonic is missing. A narrower pulse spreads its power over more harmonics, and as shrinks towards zero the line spectrum fills in towards the continuous sinc shape of a single pulse's Fourier transform.
Even and odd symmetry shortcuts
Spotting symmetry before you integrate halves the work, and often tells you that whole groups of coefficients are zero.
| Symmetry | Test | Coefficients that are zero | What's left |
|---|---|---|---|
| Even | : a mirror image about | All | A Fourier cosine series, with |
| Odd | : rotate by half a turn about the origin | and all | A Fourier sine series, with |
| Half-wave | : the second half is the first half upside down | All even harmonics, including | Odd harmonics only |
The square wave is odd and half-wave symmetric, so only odd sine terms survive. The triangle above is even and half-wave symmetric, so only odd cosine terms survive. The sawtooth is odd but not half-wave symmetric, so it has every sine harmonic.
Two more shortcuts: adding a constant to a signal changes only , and shifting it in time changes only the phases, never the amplitudes . So a square wave that runs from 0 to 1 has the same harmonics as the one above, at half the size, plus an average of .
Convergence and the Gibbs phenomenon
If a periodic signal has a finite number of jumps, peaks and troughs in each period, and the area under its absolute value over a period is finite (the Dirichlet conditions), then its Fourier series converges:
- to wherever the signal is continuous;
- to the midpoint of the jump wherever it jumps. At the square wave's edges, every partial sum passes through 0.
Even without those conditions, the series converges in the mean-square sense for any signal with finite power: the RMS error between and goes to zero as grows. For the square wave it is 0.44 with one harmonic, 0.16 with harmonics up to 15 and 0.06 up to 99. For the triangle it is 0.0036 already at 15.
The Gibbs phenomenon at a jump
Near a jump, the partial sum doesn't settle. It overshoots and rings, and the overshoot doesn't shrink as you add terms. This is the Gibbs phenomenon. The overshoot stays at about 8.95% of the jump on each side; adding harmonics only squeezes the ripple into a narrower region next to the jump.
The exact limit is of the jump. For a square wave from to , the partial sums peak near . Henry Wilbraham described the overshoot in 1848; it is named after J. Willard Gibbs, who wrote about it in 1899.
Reducing the Gibbs overshoot with sigma factors
The ringing comes from cutting the series off abruptly at harmonic . Tapering the coefficients instead, by multiplying harmonic by a Lanczos sigma factor , cuts the overshoot from about 9% to about 1.2% of the jump, but it softens the edge and slightly raises the RMS error (about 0.078 instead of 0.064 for the square wave at ). This is the same trade-off a window function makes in spectrum analysis, and Gibbs ringing is the same effect you see as ringing from a sharp low-pass filter.
Fourier series vs Fourier transform vs DFT
All three describe a signal by its frequencies. Which one applies depends on whether the signal repeats and whether it is sampled.
| Your signal | Tool | Its spectrum | Typical use |
|---|---|---|---|
| Continuous and periodic (repeats every ) | Fourier series | Separate lines at | Analysing or building a repeating waveform on paper: square waves, harmonics, AC power, musical tones |
| Continuous and not periodic (a pulse, a transient, a chirp) | Fourier transform | A continuous curve over all frequencies | Theory of filters, modulation and signals that start and stop |
| Sampled, a finite block of samples | Discrete Fourier transform (DFT), computed with an FFT | lines, apart | Anything measured: audio, vibration, sensor data |
| Sampled and periodic (repeats every samples) | Discrete-time Fourier series (DTFS) | lines, exactly | The same sums as the DFT, scaled by |
The rows are closely linked. The Fourier transform is the limit of a Fourier series as the period grows to infinity: the lines get closer together until they merge into a curve. The DFT is a Fourier series of the samples, because it treats the block as one period of a signal that repeats forever. That is why the DFT can find a waveform's Fourier coefficients, as the next section shows.
How to find Fourier series coefficients from sampled data
In practice you rarely have a formula for . You have samples. To estimate the coefficients:
- Sample exactly one period (or a whole number of periods) at evenly spaced points, for . A sample that lands on a jump should take the midpoint value.
- Take the DFT, , usually with an FFT.
- Scale by : . In trigonometric form, and .
This is the coefficient formula with the integral replaced by a sum over the samples. The estimate is good for harmonics well below ; higher harmonics of the signal fold back onto the lower ones (aliasing). We sampled one period of the square wave and compared the estimates with the exact :
| Harmonic | Exact | From samples | From samples |
|---|---|---|---|
| 1 | 1.27324 | 1.27222 | 1.27324 |
| 3 | 0.42441 | 0.42134 | 0.42440 |
| 5 | 0.25465 | 0.24951 | 0.25463 |
| 7 | 0.18189 | 0.17468 | 0.18186 |
The estimates get worse as rises towards , and better with more samples per period. In JavaScript, a direct version for a handful of harmonics is only a few lines (use an FFT when you need many):
// Fourier series coefficients a[n] and b[n], n = 0 ... nMax, from M samples of exactly one period
function seriesFromSamples(samples, nMax) {
const M = samples.length;
const a = [];
const b = [];
for (let n = 0; n <= nMax; n++) {
let sumCos = 0;
let sumSin = 0;
for (let k = 0; k < M; k++) {
const angle = (2 * Math.PI * n * k) / M;
sumCos += samples[k] * Math.cos(angle);
sumSin += samples[k] * Math.sin(angle);
}
a.push((2 * sumCos) / M); // a[0] / 2 is the average
b.push((2 * sumSin) / M);
}
return { a, b };
}
If the block isn't a whole number of periods, the DFT sees a jump where the end of the block meets the start. The harmonics then spread into neighbouring bins (spectral leakage), and the bins no longer line up with the harmonics. Trim the block to whole periods, or resample it so they fit; a window function reduces the leakage but doesn't put the bins back on the harmonics.
Common Fourier series mistakes
Most Fourier series mistakes are slips in the coefficient formulas, or misreadings of what a partial sum shows.
- Forgetting the . If you compute with the same formula as the other , the constant term is , not . Some books define as the average itself, with ; check which convention a table uses.
- Integrating over less (or more) than one full period. The orthogonality that makes the formulas work holds only over whole periods. With sampled data, a block that isn't a whole number of periods causes leakage.
- Confusing harmonic number with frequency. Harmonic is at hertz. Harmonic 5 of a 60 Hz waveform is at 300 Hz, not 5 Hz.
- Mixing one-sided and two-sided amplitudes. The amplitude of harmonic is . Reading as the amplitude halves every harmonic.
- Applying a Fourier series to a signal that doesn't repeat. The series is periodic, so it repeats your interval forever, jump at the join included. For one-off signals, use the Fourier transform.
- Sampling too slowly for the harmonics you want. You need more than samples per period to estimate harmonic , and many more if the signal jumps, because its harmonics never stop.