An unrolled inner ear: traveling waves on the basilar membrane sort a chord by pitch.
The cochlea is unrolled into a fluid-filled duct split by the basilar membrane, stiff at the base and floppy at the apex, with each of 400 sections tuned to its place by Greenwood's map (20 kHz at the base, 20 Hz at the apex). It is the classic one-dimensional transmission line model: each section is a mass, spring and damper, the fluid couples them, the stapes drives the base, and for every frequency the result is a complex tridiagonal system solved exactly with the Thomas algorithm. The solution is the traveling wave, which slows and grows as it moves toward the apex and peaks just before the place tuned to its frequency, so a chord blooms into separate peaks, two close tones beat where their waves overlap, and a click, rebuilt from 110 tones, sweeps from base to apex with the high frequencies peeling off first. The piano under the membrane is drawn where each key's pitch peaks, the spiral view coils the same activity into the snail shell, the inset shows the organ of Corti with its hair bundles shearing and the inner hair cell firing, and the nerve raster shows spikes that lock to the positive half of each cycle.
Try it. Click piano keys to build your own chord, or press and drag along the membrane to play the frequency that lives at that place. Keys 1 to 5 pick the chord, the beating pair, the sweep, the click and the octaves, Space switches the outer hair cell amplifier off and on, M mutes; sound starts on the first click.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build an interactive model of the cochlea's basilar membrane with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Split a 35 mm membrane into 400 sections. Give each one a characteristic frequency from Greenwood's map, CF = 165.4 (10^(2.1 u) - 0.88) Hz, where u is the fraction of the length from the apex (so 20 kHz at the base, 20 Hz at the apex).
- Model each section as a mass, spring and damper with impedance Z = m (i w + w_c / Q + w_c^2 / (i w)), with m = 0.3, Q = 10 and w_c = 2 pi CF. The fluid couples them: d2p/dx2 = (2 rho / h) (i w) p / Z, with rho = 1000 and h = 1 mm.
- For a tone of frequency f, discretize that equation into a complex tridiagonal system (the stapes pushes at the base, p = 0 at the apex) and solve it with the Thomas algorithm. Membrane displacement is p / (i w Z).
- Draw the membrane as a horizontal line and animate the real part of the displacement times e^(i phase), with the phase advancing slowly so the traveling wave crawls from base to apex. Draw the envelope as a dashed line.
- Let the mouse pick the frequency from the place you click.
Once that works, make it beautiful:
- Allow several tones at once (sum their waves) so a chord shows separate peaks, and draw a piano keyboard under the membrane with each key placed where its pitch peaks.
- Give two tones a few hertz apart a shared clock so their beating plays at the true rate.
- Draw the duct, the scala vestibuli and tympani, the stapes and the helicotrema, and add a spiral view of the coiled cochlea glowing where it moves.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as sound with the Web Audio API, a click rebuilt from many tones, or an auditory nerve raster that phase locks to the wave.