Vibrating String Fourier Lab

Any shape of a fixed-end string is a sum of standing sine waves (harmonics). Add harmonics one by one, watch the partial sum approach the shape, see where it cannot (jumps overshoot by 8.95 %), and hear the tone built from the same numbers.

Shape

Live readouts

Convergence: energy captured and RMS error

Experiment: how big is the Gibbs overshoot?

Measures the highest peak of the square-wave partial sum next to the jump for many N and compares it with the limit Si(π)/π - 1/2 of the jump height (the sum never gets rid of it, it only squeezes it towards the jump).

Press the button.

Independent numerical checks

  • running...
The science

String modes. A string of length L fixed at both ends has standing-wave modes sin(nπx/L) with frequencies fn = n f1, f1 = c/2L. Any initial shape (with f(0) = f(L) = 0 in the odd extension) is f(x) = Σ bn sin(nπx/L) with bn = (2/L) ∫0L f(x) sin(nπx/L) dx. After release, y(x,t) = Σ bn sin(nπx/L) cos(nω1t) (ideal string, no stiffness). The string view adds an illustrative damping e-γnt so higher modes fade first, as in real strings.

Coefficients used. Square 4/(nπ) for odd n; sawtooth (1-x) 2/(nπ); centre-plucked triangle 8 sin(nπ/2)/(nπ)2; pluck at p: 2 sin(nπp)/(n2π2 p(1-p)), which has no n-th harmonic when n p is an integer (pluck at the middle: no even harmonics); hammer pulse of width w: (2/nπ)[cos(nπ(p-w/2)) - cos(nπ(p+w/2))]. Smooth shapes have coefficients falling as 1/n2, shapes with jumps only as 1/n.

Parseval. The mean square of the shape equals Σ bn2/2. The energy captured by N harmonics is the partial sum; the remaining RMS error is exactly √(mean square - Σn≤N bn2/2). The page compares that with a direct numerical RMS error.

Gibbs. Near a jump of height J the partial sums overshoot by J (Si(π)/π - 1/2) = 0.0895 J, with Si(π) = 1.85194, no matter how many terms are added; only the width of the overshoot shrinks (like 1/N). The constant is computed here from the power series of Si, independently of the harmonic sums it is compared with.

Sound. The tone is generated from the same coefficients with a Web Audio PeriodicWave (sine terms bn). The ear mostly hears the harmonic amplitudes, not the phases, so a square and its mirror image sound alike.

What is simplified. Ideal, perfectly flexible string and rigid ends; no stiffness (real strings have slightly stretched, inharmonic overtones), no air or body coupling; the damping law is illustrative; the pluck and hammer shapes are idealised displacement shapes, not a model of finger or felt contact. Sample values are exact maths and need no literature spot-check.

2D Canvas simulation, no external libraries. Educational model.