Numerical checks
1. modal sum vs finite-difference wave solver, max error
2. pitch from audio autocorrelation
formula f1 = sqrt(T/μ)/(2L)
relative error
3. Parseval: sum of mode energies vs string energy
Check 1 compares the Fourier series with an independent leapfrog solver of the wave equation (200-point grid, ideal string, no damping). Check 2 analyses the generated sound. They are recomputed whenever you change a string parameter.
The science
A stretched string of length L, tension T and mass per length μ obeys the one-dimensional wave equation with fixed ends. Waves travel at c = sqrt(T/μ). Only standing waves that fit between the ends survive, so the string vibrates as a sum of harmonics:
y_tt = c^2 y_xx (ideal string)
y(x,t) = sum_n A_n sin(n pi x / L) cos(w_n t)
f_n = n f1 , f1 = (1/2L) sqrt(T/mu)
Pluck at x = p L (triangle, height h):
A_n = 2h sin(n pi p) / (n^2 pi^2 p (1-p))
Hammer (velocity v0 over width w at p L):
A_n = (4 v0 / (n pi w_n)) sin(n pi p) sin(n pi w / 2L)
Where you strike sets the timbre: a harmonic whose node falls on the strike point (n p = integer) is missing, and striking near the end (small p) makes the spectrum bright because many harmonics are excited; the pluck amplitude falls like 1/n², the narrow hammer like 1/n.
Real piano strings are stiff. Bending stiffness adds a restoring term, which lifts the partials above exact multiples: f_n = n f1 sqrt(1 + B n²). B is the inharmonicity coefficient (typically 10⁻&sup4; to 10⁻³). This sim also damps mode n with a decay rate r_n = r0 (1 + n²/16), so high harmonics die faster, as in a real string.
Method: the picture and sound are a modal (Fourier) synthesis with up to 60 harmonics. The independent checks use a finite-difference leapfrog solver of the wave equation (Courant number 1, exact for the ideal string apart from the initial discretisation), and an autocorrelation pitch detector on the synthesised audio.
Honest simplifications: one polarisation only (no coupling to the soundboard, no double decay or beats from three strings per note); the soundboard filter and the felt hammer contact are not modelled (the hammer is an ideal velocity impulse of fixed width); damping is a simple two-parameter law; the sound is the string displacement at a pickup near the bridge end, not a microphone recording.