🎸 String Vibration — Harmonics & Standing Waves

Pluck a vibrating string and explore its fundamental frequency and overtones. See how string tension, length, and linear density determine pitch. Visualise the Fourier decomposition into harmonics, and the spectrum of partial amplitudes. Click on the string to pluck it at any position.

Click on the top string to pluck at that position.

f₁: Hz
Note:
f₂: Hz
f₃: Hz
Wave speed: m/s

Physics

The wave equation: ∂²y/∂t² = (T/μ)·∂²y/∂x². The fundamental frequency is f₁ = (1/2L)·√(T/μ), and harmonics fn = n·f₁. When you pluck the string at position x₀, the Fourier coefficients are bn = (2/nπ)·(1/x₀(1−x₀))·sin(nπx₀), weighting each harmonic differently. The simulated string is computed as a sum of standing waves y(x,t) = Σ bn·sin(nπx/L)·cos(2πfnt).

About this simulation

This simulator solves the idealised 1-D wave equation for a string clamped at both ends, ∂²y/∂t² = (T/μ)·∂²y/∂x², whose transverse wave speed is c = √(T/μ). Because both endpoints are fixed, only standing waves that fit a whole number of half-wavelengths on the string can exist, giving fundamental frequency f₁ = (1/2L)√(T/μ) and harmonics fn = n·f₁. Clicking the string imposes an initial triangular pluck shape at position x₀, which the code decomposes into 16 harmonics using the exact Fourier sine coefficients bn = (2/n²π²)·sin(nπx₀)/[x₀(1−x₀)]. Each frame the string shape is rebuilt as y(x,t) = Σbn·sin(nπx/L)·cos(2πfnt), with every harmonic's amplitude fading by the same exponential damping factor.

🔬 What it Shows

A plucked string rebuilt live from up to 16 sine harmonics: the main canvas draws the summed string shape plus faint "ghost" curves for the first six individual harmonics, while the lower panel is a bar-chart spectrum of each harmonic's amplitude fn = n·f₁, decaying together as the damping factor shrinks every term over time.

🎮 How to Use It

Click anywhere on the string to pluck it at that point, or drag the Length L, Tension T, Linear density μ, Pluck position x₀ and Damping sliders. The four instrument presets (guitar, violin, cello, piano) jump straight to realistic tension/length/density combinations for those strings' real fundamental pitches.

💡 Did You Know?

Pluck exactly at the midpoint (x₀=0.5) and every even harmonic vanishes — sin(nπ·0.5) is zero for even n, since the midpoint sits on a node of those modes. That is why guitarists and harpists pluck near the bridge: it excites more high, even-numbered harmonics for a brighter tone.

Frequently asked questions

Why does a fixed string only vibrate at certain frequencies?

Because the string is clamped at both x=0 and x=L, the displacement y must be exactly zero at both ends at all times. Only sine shapes sin(nπx/L) with a whole number n of half-wavelengths satisfy that boundary condition, so the string's motion is restricted to this discrete ladder of standing-wave modes, each oscillating at fₙ = n·f₁ = n·(1/2L)√(T/μ) — any other shape or frequency cannot maintain zero displacement at the endpoints and is not a valid free vibration of the string.

How does the pluck position x₀ change the harmonic mix?

The Fourier coefficient for harmonic n from a triangular pluck at x₀ is bn = (2/n²π²)·sin(nπx₀)/[x₀(1−x₀)], computed once every time you click or move the pluck-position slider. Plucking near an end (small or large x₀) excites many harmonics strongly, giving a bright, buzzy tone, while plucking near the middle concentrates energy in the fundamental and odd harmonics and produces a rounder, warmer sound — visible directly in the spectrum bars.

Why do tension, length and linear density change the pitch?

The wave speed on the string is c = √(T/μ): more tension T stiffens the restoring force and speeds up the wave, while more linear density μ (a heavier string) slows it down. Since the fundamental is f₁ = c/(2L), a shorter, tighter, lighter string always rings higher, and a longer, looser, heavier one always rings lower — exactly why a guitar's thick bass strings are tuned low and its thin top string is tuned high.

Is the damping in this simulation physically realistic?

Not quite — the code multiplies every harmonic's amplitude by the same factor damp60t each second, so all 16 partials decay at an identical relative rate. Real strings actually damp higher harmonics faster than the fundamental, because air resistance and internal friction losses grow with frequency, which is why a plucked guitar note gets progressively duller (loses brightness) as it rings out. This simulator's uniform decay is a simplification chosen to keep the harmonic ladder visible for longer.

What are the faint "ghost" curves drawn behind the main string shape?

The code separately draws the first six individual harmonic sine waves, each scaled by its own amplitude and drawn at low opacity (drawHarmonics), before layering the full summed string shape on top in solid colour. Watching them side by side shows visually how the fundamental and low overtones — sin(πx/L), sin(2πx/L), sin(3πx/L) and so on — add together to build the single complex waveform the string actually traces out.