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

  1. Model (NoteFit extended, recurrence in delta form, closed form as oracle): per partial the components of T-006’s DecayFit (D1), with relative phases now fitted; , and the decay laws as in T-013; the per-partial beat offsets and amplitudes free (D2).
  2. 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.
  3. 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).
  4. 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?
  5. 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).

QuestionOptionsProposal
D1Components 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
D2What 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
D3Time 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
D4Which 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
D5Keyboard-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 min

Method, 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-006ch 1: lawsch 1: freech 2: T-006ch 2: lawsch 2: free
STFT loss0.05430.05020.04960.04240.04110.0388
envelope error 0–0.3 s / 0.3–2 s / 2–6 s, dB4.6 / 2.8 / 3.53.3 / 2.6 / 3.54.3 / 2.5 / 2.94.2 / 2.5 / 2.14.7 / 2.9 / 2.34.3 / 2.2 / 1.8
vs T-006, vs T-006261.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 s26.9 / 4.79 s25.2 / 3.42 s
law T60 slow / prompt @ 3 kHz10.4 / 2.85 s8.4 / 2.65 s10.4 / 2.85 s8.9 / 2.66 s
onset , rise 5.00, 1.00 ms (start)5.09, 0.22 ms5.05, 0.46 ms5.00, 1.00 ms5.19, 0.73 ms5.16, 0.57 ms
time, 400 steps, one thread—507 s516 s—482 s489 s

Per partial (channel 1; the full tables are printed by the driver and in t036_fits.csv):

nT-006 kindT60 prompt T-006 / laws / free (s)T60 slow T-006 / laws / free (s)beat Hz T-006 / laws / freeenv. error T-006 / laws / free (dB)
133.36 / 3.52 / 1.0231.4 / 21.7 / 33.80.09 / 0.11 / 0.041.2 / 1.3 / 2.3
233.34 / 3.50 / 3.4420.1 / 20.9 / 11.60.25 / 0.23 / 0.191.7 / 1.3 / 0.8
431.79 / 3.39 / 1.7417.7 / 18.3 / 10.80.41 / 0.46 / 0.412.8 / 3.0 / 2.0
6212.1 / 3.23 / 8.0673.9 / 15.2 / 67.0— / 0.55 / 0.614.7 / 2.3 / 3.9
837.03 / 3.03 / 8.2417.8 / 12.2 / 22.00.92 / 1.00 / 0.902.0 / 2.1 / 1.8
1131.72 / 2.68 / 1.629.4 / 8.7 / 10.80.97 / 1.03 / 0.981.2 / 2.0 / 0.9
1239.41 / 2.56 / 9.0910.1 / 7.8 / 9.90.35 / 0.34 / 0.361.3 / 1.7 / 1.3
141— / 2.31 / 0.173.8 / 6.2 / 4.1— / 0.16 / 0.1010.1 / 4.5 / 6.2
1533.08 / 2.19 / 2.947.5 / 5.6 / 6.93.05 / 3.07 / 3.053.0 / 6.3 / 3.4
201— / 1.65 / 2.034.5 / 3.4 / 3.9— / 1.18 / 0.096.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.

velchloss T-006 / laws / freemedian 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
110.099 / 0.100 / 0.0971.7 / 2.4 / 1.7+0.0030.9 / 51.34.97 / 1.670.30 / 0.41
120.060 / 0.061 / 0.0591.2 / 1.7 / 0.9-0.0121.9 / 45.14.54 / 2.710.42 / 0.41
210.074 / 0.074 / 0.0722.6 / 2.5 / 2.4+0.0023.2 / 50.44.61 / 1.550.45 / 0.46
220.060 / 0.057 / 0.0502.2 / 5.2 / 2.1-0.0013.7 / 38.29.26 / 2.710.34 / 0.43
310.073 / 0.071 / 0.0692.5 / 2.7 / 2.3+0.0231.0 / 48.03.71 / 1.550.45 / 0.46
320.050 / 0.050 / 0.0472.1 / 2.8 / 2.1+0.0225.1 / 37.44.14 / 2.640.43 / 0.49
410.061 / 0.061 / 0.0591.9 / 2.6 / 1.9+0.0116.7 / 25.03.97 / 1.730.41 / 0.38
420.043 / 0.049 / 0.0412.3 / 3.0 / 2.2+0.0412.6 / 22.57.32 / 2.820.37 / 0.37
510.060 / 0.060 / 0.0571.8 / 2.8 / 1.9+0.0328.7 / 42.43.87 / 1.780.46 / 0.40
520.044 / 0.044 / 0.0412.0 / 2.4 / 1.5-0.0224.7 / 34.44.27 / 2.680.47 / 0.46
610.062 / 0.061 / 0.0571.8 / 2.5 / 1.8+0.0031.9 / 43.44.69 / 1.540.55 / 0.56
620.043 / 0.043 / 0.0401.9 / 2.3 / 2.0-0.0124.1 / 35.04.17 / 2.700.52 / 0.54
710.062 / 0.062 / 0.0582.1 / 2.8 / 2.0-0.0132.4 / 29.44.71 / 1.720.38 / 0.43
720.043 / 0.044 / 0.0412.3 / 2.7 / 1.8+0.0222.7 / 32.53.58 / 2.760.58 / 0.55
810.062 / 0.061 / 0.0582.0 / 2.5 / 1.9-0.0529.7 / 31.04.44 / 1.450.39 / 0.43
820.046 / 0.045 / 0.0422.2 / 2.6 / 2.0-0.0123.1 / 33.33.62 / 2.700.54 / 0.57
910.100 / 0.401 / 0.0555.0 / 28.1 / 1.9-0.0611.7 / 32.60.78 / 1.660.50 / 0.45
920.049 / 0.068 / 0.0432.3 / 3.7 / 2.0-0.0620.0 / 36.61.12 / 2.830.43 / 0.49
1010.064 / 0.062 / 0.0593.0 / 3.5 / 2.8+0.0231.7 / 39.04.15 / 1.350.52 / 0.59
1020.051 / 0.049 / 0.0462.3 / 2.7 / 2.0+0.0022.2 / 32.23.67 / 2.740.43 / 0.47
1110.059 / 0.058 / 0.0552.5 / 3.3 / 2.6+0.0522.3 / 38.44.50 / 1.420.60 / 0.63
1120.046 / 0.046 / 0.0422.3 / 2.8 / 2.2+0.0122.2 / 32.83.80 / 2.740.49 / 0.59
1210.061 / 0.060 / 0.0562.7 / 3.3 / 2.7+0.0222.5 / 37.54.59 / 1.550.47 / 0.55
1220.048 / 0.046 / 0.0432.4 / 3.1 / 2.1-0.0022.6 / 32.33.43 / 2.710.38 / 0.47
1310.062 / 0.060 / 0.0562.9 / 3.7 / 2.8-0.0022.5 / 37.54.55 / 1.480.47 / 0.48
1320.051 / 0.050 / 0.0472.4 / 3.3 / 2.2-0.0121.7 / 33.93.30 / 2.760.38 / 0.35
1410.063 / 0.058 / 0.0553.1 / 3.9 / 3.2-0.0528.8 / 35.33.44 / 1.340.43 / 0.48
1420.051 / 0.050 / 0.0472.4 / 3.4 / 2.5-0.0124.2 / 35.13.26 / 2.700.38 / 0.37
1510.068 / 0.067 / 0.0603.5 / 3.9 / 3.1-0.0115.5 / 38.35.10 / 3.700.19 / 0.34
1520.056 / 0.057 / 0.0493.7 / 4.2 / 3.4-0.0412.4 / 23.65.02 / 2.610.19 / 0.23
1610.062 / 0.060 / 0.0543.2 / 5.1 / 3.1-0.0215.5 / 35.63.57 / 1.390.46 / 0.50
1620.048 / 0.046 / 0.0442.2 / 3.3 / 2.1-0.0121.4 / 34.93.30 / 2.710.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.