T-036 — The differentiable fit on real notes: Salamander C4 with beating mode pairs, onset and noise floor
Status: done · Area: julia, piano · Depends on: T-006 (start values), T-013 (fit machinery), T-014 (data)
Read for that: the T-006 page (decay model, results), the T-013 page (NoteFit: renderer, loss, parametrisation), Piano 12 step 3, Piano 07 (mode pairs).
Why: T-013 fitted a synthetic note; T-006 fitted each partial’s envelope on its own. Neither has run the model itself against a recording. This task does, on Salamander C4 first, and answers the first question of Piano 12: how far does a modal model with mode pairs get on isolated notes? T-007 (the reference piano) builds on its model.
What
- Model (
NoteFitextended, recurrence in delta form, closed form as oracle): per partial the components of T-006’sDecayFit(D1), with relative phases now fitted; , and the decay laws as in T-013; the per-partial beat offsets and amplitudes free (D2). - What a recording adds: the onset (from
find_onset, plus a fitted sub-sample delay); the noise floor (a per-bin floor measured in the target, added in power to the model’s magnitude before the log, so the loss ignores what is below it); partials not tracked by T-006 are left out of the model. - Start from T-006:
notes.csv(, ),keys.csv(decay laws),partials.csv(amplitudes, , phases per partial). Then the joint fit (STFT + frequency term, Adam, as T-013). - Report: recovered vs start values, loss curves, the remaining error per partial and over time (where the model fails: attack, beating, the floor, phantom partials), and a render to listen to (in the scratchpad or
data/, not committed). Check the non-decaying slow components T-006 found (C4 has some): sympathetic ring, room, or fit artefact? - Then the other velocities and channels of C4 (D4), and a decision whether the keyboard-wide fit over curves (Piano 12 step 3) is a step of this task or a new one (D5).
Decisions
All five proposals accepted by the maintainer (Nov 2026).
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | Components per partial | (a) T-006’s form: prompt + slow pair, the pair sharing one rate, three sinusoids; (b) two independent mode pairs (prompt pair, slow pair), four sinusoids each with own rate and offset; (c) three free sinusoids per partial (Piano 07: “two or three”) | (a): T-006 shows it fits 71 % of partials to a median 2.3 dB, it costs three resonators per partial in the engine, fewer than Piano 14’s strings × polarisations (up to six on triple-strung keys), and a partial that needs less sets . (b)/(c) only if the residual shows (a) failing |
| D2 | What is shared across partials | (a) decay laws shared, beat offsets and amplitudes per partial; (b) everything per partial (T-006 again, jointly); (c) beat offsets as a law too | (a): beat offsets are irregular across partials (C4v8: 0.09–3 Hz with no trend), so a law would not fit them; decay laws follow T-013 and Piano 12 |
| D3 | Time window | (a) 1.5 s as T-013; (b) 6 s; (c) 1.5 s STFT loss + an envelope term per partial over the whole note | (b): C4’s beats have periods of 2–4 s and its slow T60 is 27 s, invisible in 1.5 s. Cost: three components and 4× the length make a step ~1.5 s, 400 steps ~10 min per fit on one thread |
| D4 | Which samples | (a) C4 v8, channel 1 only; (b) C4 v8, both channels as two fits (decays should agree; amplitudes differ by mic); (c) all 16 velocities × 2 channels of C4 | (b) first, then (c): the channel comparison is the cheapest check that the fit finds the string and not the mic; (c) tells T-035 how much of the spectrum moves with velocity |
| D5 | Keyboard-wide fit over curves (Piano 12 step 3: parameters are curves, not per-note values) | (a) in this task, after C4; (b) a new task after T-036 | (b): it needs the per-note fit to work first and costs ~30 notes × several velocities per step; split once C4 shows what the model is |
Done when
Tests: the extended model recovers known parameters of a synthetic note with a beating slow pair, random phases, an onset delay and a noise floor (as T-013’s tests); the gradients of recurrence and closed form agree. A results section here: C4 v8 fitted on both channels with start vs fitted values, loss curves, the error of the fit vs T-006’s per-partial fits, the channel comparison, and where the model fails; Piano 12 step 3 updated with what the real note showed; the follow-up tasks (keyboard fit, model changes) in the backlog.
Results
Code: training/src/PairFit.jl (submodule InstrumentsTraining.PairFit, tested in training/test/pairfit.jl), the noise floor in NoteFit.STFTLoss (noise_halfwidth), and the driver training/scripts/t036_fit_real_note.jl, which prints the tables below, writes renders to data/t036/ (target, both fits, residual; not committed) and the per-partial results to training/results/salamander/t036_fits.csv (CC BY 4.0; columns in its README):
julia --project=training -t 4 training/scripts/t036_fit_real_note.jl C4v8 # ~18 min
julia --project=training -t 4 training/scripts/t036_fit_real_note.jl --sweep C4 # 16 × 2, ~80 minMethod, as it ended up
- Model (
PairFit): per partial the three components of T-006 (prompt at ; slow pair at and with one rate), each with its own amplitude and phase; rates and . Two fits: laws (D2: held by a gradient mask) and free ( fitted: own rates per partial). The baseline T-006 renders T-006’s per-partial fits as they are. 8 + 9 per partial parameters (152 for C4’s 16 partials). - Onset: the window starts 5 ms before
find_onset’s onset; the note is multiplied by a gate with and the rise time fitted (the sub-sample delay of the plan became this gate: with phases free, a delay only matters where the note switches on). - Noise floor: measured once at the finest resolution (per bin: the median over frames, then the median over ± half a partial spacing, so a partial’s bin gets the noise beside it), turned into a density and scaled to each resolution; added in power to the model’s magnitude. On white noise it reads 0.83 of the RMS magnitude (the Rayleigh median), at a tone’s bin too.
- Loss and optimiser as T-013: STFT (N = 512 … 4096) + 0.01 × the frequency term on T-006’s peaks; Adam, lr 0.03, 400 steps; 6 s at 48 kHz (D3).
- Envelope error (diagnostic): per partial, the RMS dB difference between the model’s and the recording’s envelopes (T-006’s
partial_envelopes) where the recording is 6 dB above its floor.
On synthetic notes (tests): with beat rates started within 5 %, , , decay laws, beat rates, amplitudes (< 1 dB) and relative phases are recovered. Two limits, both relevant here: the beat rate has a narrow basin: started 20 % off (about one beat cycle of phase drift over the window), it stays there and the phases compensate, so the fit depends on T-006’s beat rates as its start; and the onset is weakly identified: a 1 ms error barely moves (frames of ≥ 512 samples see little of a 1 ms shift).
C4 v8, both channels
| ch 1: T-006 | ch 1: laws | ch 1: free | ch 2: T-006 | ch 2: laws | ch 2: free | |
|---|---|---|---|---|---|---|
| STFT loss | 0.0543 | 0.0502 | 0.0496 | 0.0424 | 0.0411 | 0.0388 |
| envelope error 0–0.3 s / 0.3–2 s / 2–6 s, dB | 4.6 / 2.8 / 3.5 | 3.3 / 2.6 / 3.5 | 4.3 / 2.5 / 2.9 | 4.2 / 2.5 / 2.1 | 4.7 / 2.9 / 2.3 | 4.3 / 2.2 / 1.8 |
| vs T-006, vs T-006 | 261.426 Hz, 2.951e-4 | −0.005 cent, +0.0 % | −0.013 cent, +0.1 % | 261.469 Hz, 2.947e-4 | +0.035 cent, −0.2 % | +0.037 cent, −0.2 % |
| law T60 slow / prompt @ | 26.9 / 4.79 s (keys.csv) | 21.7 / 3.52 s | 26.9 / 4.79 s | 25.2 / 3.42 s | ||
| law T60 slow / prompt @ 3 kHz | 10.4 / 2.85 s | 8.4 / 2.65 s | 10.4 / 2.85 s | 8.9 / 2.66 s | ||
| onset , rise | 5.00, 1.00 ms (start) | 5.09, 0.22 ms | 5.05, 0.46 ms | 5.00, 1.00 ms | 5.19, 0.73 ms | 5.16, 0.57 ms |
| time, 400 steps, one thread | — | 507 s | 516 s | — | 482 s | 489 s |
Per partial (channel 1; the full tables are printed by the driver and in t036_fits.csv):
| n | T-006 kind | T60 prompt T-006 / laws / free (s) | T60 slow T-006 / laws / free (s) | beat Hz T-006 / laws / free | env. error T-006 / laws / free (dB) |
|---|---|---|---|---|---|
| 1 | 3 | 3.36 / 3.52 / 1.02 | 31.4 / 21.7 / 33.8 | 0.09 / 0.11 / 0.04 | 1.2 / 1.3 / 2.3 |
| 2 | 3 | 3.34 / 3.50 / 3.44 | 20.1 / 20.9 / 11.6 | 0.25 / 0.23 / 0.19 | 1.7 / 1.3 / 0.8 |
| 4 | 3 | 1.79 / 3.39 / 1.74 | 17.7 / 18.3 / 10.8 | 0.41 / 0.46 / 0.41 | 2.8 / 3.0 / 2.0 |
| 6 | 2 | 12.1 / 3.23 / 8.06 | 73.9 / 15.2 / 67.0 | — / 0.55 / 0.61 | 4.7 / 2.3 / 3.9 |
| 8 | 3 | 7.03 / 3.03 / 8.24 | 17.8 / 12.2 / 22.0 | 0.92 / 1.00 / 0.90 | 2.0 / 2.1 / 1.8 |
| 11 | 3 | 1.72 / 2.68 / 1.62 | 9.4 / 8.7 / 10.8 | 0.97 / 1.03 / 0.98 | 1.2 / 2.0 / 0.9 |
| 12 | 3 | 9.41 / 2.56 / 9.09 | 10.1 / 7.8 / 9.9 | 0.35 / 0.34 / 0.36 | 1.3 / 1.7 / 1.3 |
| 14 | 1 | — / 2.31 / 0.17 | 3.8 / 6.2 / 4.1 | — / 0.16 / 0.10 | 10.1 / 4.5 / 6.2 |
| 15 | 3 | 3.08 / 2.19 / 2.94 | 7.5 / 5.6 / 6.9 | 3.05 / 3.07 / 3.05 | 3.0 / 6.3 / 3.4 |
| 20 | 1 | — / 1.65 / 2.03 | 4.5 / 3.4 / 3.9 | — / 1.18 / 0.09 | 6.1 / 8.6 / 6.9 |
Channels (beat rates of the free fit, partials 1–6, ch 1 / ch 2): 0.04/0.58, 0.19/0.15, 0.17/0.22, 0.41/0.34, 0.39/0.36, 0.61/0.68 Hz. differs by 0.34 cent and by 0.5 % between the channels, the decay laws by 14 % (slow) and 3 % (prompt) at .
C4, all 16 velocities × 2 channels (D4)
6 s, 200 steps per fit (half of the above, to keep the sweep at 76 minutes on four threads). “T60 @ ” is the law at for laws and partial 1’s own rates for free; the median beat is over the partials.
| vel | ch | loss T-006 / laws / free | median env. error (dB) T-006 / laws / free | laws − free (cent) | T60 slow @ laws / free (s) | T60 prompt @ laws / free (s) | median beat (Hz) laws / free |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 0.099 / 0.100 / 0.097 | 1.7 / 2.4 / 1.7 | +0.00 | 30.9 / 51.3 | 4.97 / 1.67 | 0.30 / 0.41 |
| 1 | 2 | 0.060 / 0.061 / 0.059 | 1.2 / 1.7 / 0.9 | -0.01 | 21.9 / 45.1 | 4.54 / 2.71 | 0.42 / 0.41 |
| 2 | 1 | 0.074 / 0.074 / 0.072 | 2.6 / 2.5 / 2.4 | +0.00 | 23.2 / 50.4 | 4.61 / 1.55 | 0.45 / 0.46 |
| 2 | 2 | 0.060 / 0.057 / 0.050 | 2.2 / 5.2 / 2.1 | -0.00 | 13.7 / 38.2 | 9.26 / 2.71 | 0.34 / 0.43 |
| 3 | 1 | 0.073 / 0.071 / 0.069 | 2.5 / 2.7 / 2.3 | +0.02 | 31.0 / 48.0 | 3.71 / 1.55 | 0.45 / 0.46 |
| 3 | 2 | 0.050 / 0.050 / 0.047 | 2.1 / 2.8 / 2.1 | +0.02 | 25.1 / 37.4 | 4.14 / 2.64 | 0.43 / 0.49 |
| 4 | 1 | 0.061 / 0.061 / 0.059 | 1.9 / 2.6 / 1.9 | +0.01 | 16.7 / 25.0 | 3.97 / 1.73 | 0.41 / 0.38 |
| 4 | 2 | 0.043 / 0.049 / 0.041 | 2.3 / 3.0 / 2.2 | +0.04 | 12.6 / 22.5 | 7.32 / 2.82 | 0.37 / 0.37 |
| 5 | 1 | 0.060 / 0.060 / 0.057 | 1.8 / 2.8 / 1.9 | +0.03 | 28.7 / 42.4 | 3.87 / 1.78 | 0.46 / 0.40 |
| 5 | 2 | 0.044 / 0.044 / 0.041 | 2.0 / 2.4 / 1.5 | -0.02 | 24.7 / 34.4 | 4.27 / 2.68 | 0.47 / 0.46 |
| 6 | 1 | 0.062 / 0.061 / 0.057 | 1.8 / 2.5 / 1.8 | +0.00 | 31.9 / 43.4 | 4.69 / 1.54 | 0.55 / 0.56 |
| 6 | 2 | 0.043 / 0.043 / 0.040 | 1.9 / 2.3 / 2.0 | -0.01 | 24.1 / 35.0 | 4.17 / 2.70 | 0.52 / 0.54 |
| 7 | 1 | 0.062 / 0.062 / 0.058 | 2.1 / 2.8 / 2.0 | -0.01 | 32.4 / 29.4 | 4.71 / 1.72 | 0.38 / 0.43 |
| 7 | 2 | 0.043 / 0.044 / 0.041 | 2.3 / 2.7 / 1.8 | +0.02 | 22.7 / 32.5 | 3.58 / 2.76 | 0.58 / 0.55 |
| 8 | 1 | 0.062 / 0.061 / 0.058 | 2.0 / 2.5 / 1.9 | -0.05 | 29.7 / 31.0 | 4.44 / 1.45 | 0.39 / 0.43 |
| 8 | 2 | 0.046 / 0.045 / 0.042 | 2.2 / 2.6 / 2.0 | -0.01 | 23.1 / 33.3 | 3.62 / 2.70 | 0.54 / 0.57 |
| 9 | 1 | 0.100 / 0.401 / 0.055 | 5.0 / 28.1 / 1.9 | -0.06 | 11.7 / 32.6 | 0.78 / 1.66 | 0.50 / 0.45 |
| 9 | 2 | 0.049 / 0.068 / 0.043 | 2.3 / 3.7 / 2.0 | -0.06 | 20.0 / 36.6 | 1.12 / 2.83 | 0.43 / 0.49 |
| 10 | 1 | 0.064 / 0.062 / 0.059 | 3.0 / 3.5 / 2.8 | +0.02 | 31.7 / 39.0 | 4.15 / 1.35 | 0.52 / 0.59 |
| 10 | 2 | 0.051 / 0.049 / 0.046 | 2.3 / 2.7 / 2.0 | +0.00 | 22.2 / 32.2 | 3.67 / 2.74 | 0.43 / 0.47 |
| 11 | 1 | 0.059 / 0.058 / 0.055 | 2.5 / 3.3 / 2.6 | +0.05 | 22.3 / 38.4 | 4.50 / 1.42 | 0.60 / 0.63 |
| 11 | 2 | 0.046 / 0.046 / 0.042 | 2.3 / 2.8 / 2.2 | +0.01 | 22.2 / 32.8 | 3.80 / 2.74 | 0.49 / 0.59 |
| 12 | 1 | 0.061 / 0.060 / 0.056 | 2.7 / 3.3 / 2.7 | +0.02 | 22.5 / 37.5 | 4.59 / 1.55 | 0.47 / 0.55 |
| 12 | 2 | 0.048 / 0.046 / 0.043 | 2.4 / 3.1 / 2.1 | -0.00 | 22.6 / 32.3 | 3.43 / 2.71 | 0.38 / 0.47 |
| 13 | 1 | 0.062 / 0.060 / 0.056 | 2.9 / 3.7 / 2.8 | -0.00 | 22.5 / 37.5 | 4.55 / 1.48 | 0.47 / 0.48 |
| 13 | 2 | 0.051 / 0.050 / 0.047 | 2.4 / 3.3 / 2.2 | -0.01 | 21.7 / 33.9 | 3.30 / 2.76 | 0.38 / 0.35 |
| 14 | 1 | 0.063 / 0.058 / 0.055 | 3.1 / 3.9 / 3.2 | -0.05 | 28.8 / 35.3 | 3.44 / 1.34 | 0.43 / 0.48 |
| 14 | 2 | 0.051 / 0.050 / 0.047 | 2.4 / 3.4 / 2.5 | -0.01 | 24.2 / 35.1 | 3.26 / 2.70 | 0.38 / 0.37 |
| 15 | 1 | 0.068 / 0.067 / 0.060 | 3.5 / 3.9 / 3.1 | -0.01 | 15.5 / 38.3 | 5.10 / 3.70 | 0.19 / 0.34 |
| 15 | 2 | 0.056 / 0.057 / 0.049 | 3.7 / 4.2 / 3.4 | -0.04 | 12.4 / 23.6 | 5.02 / 2.61 | 0.19 / 0.23 |
| 16 | 1 | 0.062 / 0.060 / 0.054 | 3.2 / 5.1 / 3.1 | -0.02 | 15.5 / 35.6 | 3.57 / 1.39 | 0.46 / 0.50 |
| 16 | 2 | 0.048 / 0.046 / 0.044 | 2.2 / 3.3 / 2.1 | -0.01 | 21.4 / 34.9 | 3.30 / 2.71 | 0.38 / 0.38 |
What the real note showed
- The model holds: prompt + beating slow pair per partial reproduces C4 to a median envelope error of about 2 dB per partial after the attack (0.3–6 s), across all velocities and both mics; 3–5 dB in the first 0.3 s, where the recording has what the model lacks (hammer knock, soundboard ring, the build-up of the attack).
- The joint fit adds little to T-006: it lowers the STFT loss by 3–12 % (free rates) below T-006’s per-partial fits rendered as they are; and move by < 0.06 cent and < 0.2 %. T-006’s analysis is already close to what this model can do on an isolated note; the rest of the loss lies outside the model (attack, noise, room, partials T-006 did not track).
- Shared decay laws (D2) cost little when they converge: at 400 steps on v8, laws end within 1–6 % of free rates. But they start further away (keys.csv’s laws: loss 0.098 vs 0.062 for T-006’s per-partial fits), stay at T-006’s level after 200 steps, and diverged once (v9 ch 1: loss 0.40, the T-006 fit of that sample is poor too). The keyboard fit should start the laws from a log-domain fit to the sample’s own T-006 rates and run ≥ 400 steps.
- Per-partial rates are not unique: freed, a partial’s rates trade against its amplitudes and its partner (ch 1, partial 1: prompt T60 3.4 → 1.0 s with the prompt 12 dB louder). The laws, or a penalty pulling the rates to them, are needed when the fit runs on many notes.
- The decays depend on the mic: partial 1’s prompt T60 (free fit) is 1.3–1.8 s at mic 1 and 2.6–2.8 s at mic 2 in every velocity layer; the laws’ slow T60 differs by 14 % between the mics at v8 and scatters 12–32 s over the velocity layers. Each mic sees a different mixture of the coupled modes, so a per-channel three-component fit is not the string’s decomposition. Fitting both channels jointly with shared frequencies and rates (amplitudes and phases per mic) is the next test of the model.
- The beating is a property of the string: median beat rates 0.3–0.6 Hz at every velocity and both mics (v15: 0.2 Hz), the per-partial rates agree between channels to < 0.07 Hz for partials 2–6 and with T-006 to a few hundredths of a hertz. Partial 1 disagrees between mics (0.04 vs 0.58 Hz): its partner is 30 dB below the slow component at mic 1.
- Non-decaying slow components (T-006: 430, 5 of them on C4): on C4 they sit at −108 dB, 4 dB above the floor of −112 dB, so they are the floor absorbed into a component, not a sound. Most of the 430 are in the bass (F#1 106, A0 76, C1 66), not looked at here.
- The C5’s decay at C4 after the joint fit: slow T60 about 22–25 s and prompt 3.4–3.5 s at (laws, v8), 8–9 s and 2.7 s at 3 kHz; T-006’s laws said 27 and 4.8 s at : its prompt rate was biased, as its synthetic tests warned.
- Cost: 1.25 s per step for 16 partials × 3 components over 6 s at 48 kHz, so 400 steps take 8.5 minutes on one thread; a keyboard fit of 30 keys × 16 velocities × 2 mics is ~70 thread-hours per 400 steps (fewer velocities, shorter windows for the treble, or a coarser STFT would cut it).
Not done here
- The keyboard-wide fit over curves (D5) is T-037, with the two lessons above: start the laws from the sample’s T-006 rates, and fit both mics jointly with shared rates. The attack and the residual stay with T-012; phantom partials with T-010.