Toolyard

Fourier Series Simulator

Equations in this simulation

f(t) = Σ b_n sin(n ω t)
nharmonic numbercircle n turns n times as fast as the first; the waves here need only sines
b_namplitude of harmonic nthe radius of circle n
NNumber of termshow many circles are added; the pen's height is the partial sum

With the current values:

square: b_n = 4 ÷ (n π), odd n; sawtooth: b_n = −2 ÷ (n π); triangle: b_n = 8 (−1)^((n−1)/2) ÷ (n² π²), odd n
decayhow fast the terms shrinkas 1 ÷ n for waves with jumps, 1 ÷ n² for the triangle, which only has corners: smoother shapes need fewer terms

With the current values:

overshoot → 0.0895 × the jump
Gibbsthe overshoot next to a jumpabout 9% of the jump, however many terms are added: the ripple gets narrower but never lower

With the current values:

mean of f² = Σ b_n² ÷ 2
Parsevalpower in the first N terms over the totalhow much of the wave the circles have captured

With the current values:

c_k = (1 ÷ M) Σ z_j e^(−2πi jk ÷ M)
c_kone epicycle of a shapethe discrete Fourier transform of M points z_j = x + iy round the outline; the largest circles are used first

With the current values:

How to use the Fourier series simulator

  1. Pick a square, sawtooth or triangle wave. Each circle spins at a whole multiple of the first one's speed, and its radius is the amplitude of that harmonic; the pen at the end of the chain draws the sum, which scrolls off to the right over the exact wave in green.
  2. Add terms with the slider and watch the wave sharpen. Next to each jump the sum overshoots by about 9% however many terms you add, the Gibbs phenomenon; the error and the share of the power captured are under the picture, and the chart shows the spectrum of harmonics. Tick Play the wave as sound to hear a soft sine grow into a buzzy square wave as harmonics join.
  3. Switch to the heart or the star, or choose Your own drawing and drag a closed shape on the picture, and the epicycles trace it from its discrete Fourier transform, the largest circles first. A few circles give a rough blob; more add the corners. The Standing Wave Simulator shows harmonics on a string.

Frequently asked questions

What is a Fourier series?

A way of writing any repeating signal as a sum of sine and cosine waves whose frequencies are whole multiples of the repetition rate. Joseph Fourier introduced it in 1807 to solve the equation for heat flow. It is behind audio compression, image formats such as JPEG, radio and the analysis of anything that vibrates.

Why does a square wave need only odd harmonics?

A square wave has half-wave symmetry: its second half is the first half turned upside down. Even harmonics would break that symmetry, so their coefficients are zero. Its odd harmonics have amplitudes 4 ÷ (nπ): one third, one fifth, one seventh of the first, falling off slowly because of the sudden jumps.

What is the Gibbs phenomenon?

Near a jump, a Fourier partial sum overshoots by about 9% of the jump, and adding more terms makes the ripple narrower but not lower. The sum still gets closer to the wave on average, since the ripple covers less and less of the period, but it never fits a jump perfectly.

How do circles draw a picture?

Write each point of the outline as a complex number x + iy and take its discrete Fourier transform. Each coefficient is a circle of fixed radius spinning at its own whole-number speed, some one way and some the other. Added tip to tail, they trace the outline exactly when all are used, and approximately with the largest few.

It says WebGL is turned off.

The 3D view needs WebGL, which every current browser has. It can be switched off by hardware acceleration being disabled in the browser settings, or by a very old graphics driver. Turn hardware acceleration on, or try another browser.

Is anything uploaded?

No. The simulation is drawn by your own browser with WebGL; nothing is sent anywhere, and it keeps working offline once the page has loaded.

More science simulations

Related calculators and tools

Guides