/ proof-of-concept / bead-percussion
Sign in
proof-of-concept / bead-percussion
bead-percussion / README.md
9.8 KBPreviewCodeBlameHistoryRaw

bead-percussion#

A browser app for idealized percussion: a network of beads (point masses) joined by springs, set up by a MATLAB-syntax script that runs in the browser with numbl, integrated accurately in time, and heard through the displacement of a listener bead.

The aim is to reproduce the phenomena of drums and cymbals (resonant modes, nonlinear coupling between them, transfer of energy to higher frequencies, amplitude-dependent detuning) in a system that is physical but much simpler than the continuum equations of a membrane or a shell. Nothing here discretizes a PDE. The bead network is the system.

Running#

npm install
npm run dev      # the app, at the printed localhost URL
npm test         # solver tests (Node)

The model#

Each bead has a mass and a position in 3D. The script defines:

Damping is easiest to set by its effect. [sys.friction, sys.dashpots] = bp_decay(pos, mass, springs, [f1 T1; f2 T2]) chooses them so that every transverse mode of a flat net falls 60 dB in time T(f) following the law sigma(f) = sigma0 + sigma1 (2 pi f)^2 for the amplitude decay rate, through the two given points (one point gives the same decay time at every frequency). It does this by giving each bead friction 2 sigma0 m and each spring a parallel dashpot 2 sigma1 times its tension per length, which makes the damping matrix of the transverse motion 2 sigma0 M + 2 sigma1 K; the modes then stay uncoupled and the law holds exactly at small amplitude. Large motion and the in-plane modes are damped by the same elements, but not by this law. The page plots the small-amplitude decay time of every mode for whatever damping the script sets. A script that sets neither sys.friction nor sys.dashpots gets a default under which every mode falls 60 dB in 2.5 s; sys.friction = 0 turns damping off.

Bending stiffness (for plates and cymbals) is not in yet.

The matlab/helpers/bp_*.m functions build common geometries (bp_hexdisk: a triangular lattice clipped to a disk, with its rim beads; bp_chain: a line of beads), list edges (bp_edges), make springs with a given tension at rest (bp_springs), set damping from decay times (bp_decay) and find beads near a point (bp_near). They are ordinary scripts; the app lists them, and a script can ignore them and build sys directly. The full list of sys fields is in the app under "sys fields".

Time integration#

The conservative part (springs and force pulses) is integrated with velocity Verlet, or with Yoshida's fourth-order composition of it (sys.method = 'yoshida4'). Damping is linear in the velocities, dv/dt = -A v, and is applied as a separate step v <- exp(-tau A) v, computed to round-off with a scaled Taylor series, once per audio sample (Strang splitting). The splitting error scales with the damping rate times the sample interval, which is small for the damping of interest here.

The time step is chosen automatically. We estimate the highest frequency of the system linearized about rest by power iteration, take sys.safety (default 0.5) of the method's stability limit, and round so that a whole number of steps fits in each audio sample (48 kHz by default). The in-plane (stretching) modes of a net are much stiffer than its transverse modes, so they, not the audible frequencies, usually set the step; a smaller pre-stretch makes this worse.

Each run reports:

Linear modes#

For a net that rests flat (all beads at one z), small transverse motion decouples from in-plane motion, and its stiffness matrix is a graph Laplacian weighted by spring tension over length. For any other rest shape (a dome, a 3D structure) the app uses the full 3n-by-3n stiffness of the springs. It computes the eigenpairs with numbl's eig (up to 1500 degrees of freedom; about 1 s for the 721 free beads of the drum example) and records the energy of every mode over time. The "energy by linear mode" plot shows the share of the quadratic energy in log-spaced frequency bands: in a linear system each band only decays, so any band that gains energy is fed by the nonlinearity.

The "small-strike reference" option runs the same system with every hit scaled down by 1000 and the output scaled back up, which is what the system would do if it were linear. The app plays it for comparison and reports the difference from the actual run.

Chaos test#

The "perturbed twin" option runs the system again with every hit changed by one part in 10^9 and plots, over time, the largest difference in any bead coordinate between the two runs, relative to the largest displacement of the original run over the preceding 50 ms (so the measure stays meaningful as the motion decays). In chaotic motion this separation grows exponentially (a straight line on the log plot) until the runs are unrelated; in regular motion it grows slowly, roughly in proportion to time. The app fits the exponential rate over the stretch where the separation rises from 100 times the perturbation to 10^-2 and reports the e-folding time. Positions are compared at full precision, which needs the original run's positions at every frame in memory (limit 400 MB).

Examples#

Example What it shows
drum A 15 cm drum head (823 beads, fundamental 237 Hz) struck by a soft mallet. Nearly linear at first (2% from the small-strike reference over 10 ms); the slight pitch change at large amplitude accumulates to 25% by 0.3 s. About 7x real time.
cascade The same net with a 0.5% pre-stretch, weaker dashpots and a hard strike. The share of energy in modes above 1 kHz grows from 4% (small strike) to about 25% within 30 ms. About 10x real time.
string 120 beads on a string, struck slightly off-axis; fast.
dome Chaos that keeps its pitch. A small drum head (127 beads) bulged 4.6 mm into a dome by a steady load and struck hard: the twin separates with an e-folding time of 8 ms, while the main partial (582 Hz) moves by only about 20 cents and the spectrum stays tonal. Flat nets of the same kind become chaotic only when struck hard enough to move the pitch by about a semitone. About real time.
chaos The minimal chaotic example: two beads on a short string, free to move in 3D (6 degrees of freedom), struck hard and off-axis, with every mode decaying 60 dB in 2.5 s. With the perturbed twin, the separation e-folds every 2 ms and the runs are unrelated within 0.15 s; at 0.025 of the strike the motion is regular and the separation stays below 1e-8 for 3 s. With half the strike, the damping pulls the motion out of the chaotic range before the runs fully separate (transient chaos). Runs in a fraction of a second.

Timings are for a laptop (Chrome, single thread).

Limitations and next steps#

What makes chaos sound good here#

Measured over several nets (2026-10-06): a net held only by tension (flat, or a string) becomes chaotic at moderate size only when the strike is strong enough to raise its pitch by 90 cents or more, and the two-bead chaos example, which needs a very hard strike, shifts by 3 semitones or more and sounds harsh. The reason appears to be that a flat net's nonlinearity is cubic (stretching stiffens it), so the coupling that moves energy between modes comes with a pitch shift of the same order. A curved net has a quadratic coupling as well, through which two modes drive a third directly, as in gongs and cymbals; in the dome example the motion is chaotic with a pitch change of about 20 cents. tests/screen.ts prints the measurements (twin growth rate, nonlinear pitch shift against a small-strike run, spectral flatness) for any script.

↑↓ move↵openescclose