
Topics in Digital Heritage:
Numerical Methods for Digital Reconstruction
Fall 2026

s = ModalString(110.0, OPEN["A2"], B_open=1.5e-4) # class 15 stiff string, as exact modes
(F_b,), _ = s.response(s.pluck(0.12), 2.0, [s.bridge_weights()])
save_wav("recap_string", F_b)
fig, ax = plt.subplots(figsize=(5.0, 2.3))
show_spec(ax, F_b, f"A2 string, {len(s.p)} exact modes: the force on the bridge")
ax.set_xlabel("time (s)"); ax.set_ylabel("kHz")
plt.tight_layout()
plt.show()
an acoustic string: the bridge force (classes 15 to 17)

| part | today | physics | numerical method (first seen) |
|---|---|---|---|
| exciter | pick, Rhodes hammer, E-bow driver coil (fed by the E-bow’s own sensor coil) | contact, magnetic force | lumped ODE, explicit (13, 16) |
| resonator | guitar string, Rhodes tine + tonebar | stiff string, cantilever bar | modes + exact recursion (15, 17) |
| pickup | single coil, Rhodes pickup | Faraday’s law, nonlinear flux | interpolation + a memoryless nonlinearity (8, 16) |
| circuits | pickup RLC, wah filter, diode clipper, triode | Kirchhoff, Shockley, Child–Langmuir | trapezoid (time varying for the wah) + Newton per sample, tables, wave digital filters (5, 12) |
| mechanics | spring and plate reverb | dispersive helical spring, plate | modes (15, 17) |
Steel string moves, flux through the coil changes: \[ e=-N\frac{d\Phi}{dt},\qquad \Phi(u)=\frac{a^3}{\bigl(a^2+(d-u)^2\bigr)^{3/2}} \]
\[ e=-N\,\Phi'(u)\,u_t\ \approx\ -N\,\Phi'(0)\,u_t \]

u = np.linspace(-1e-3, 1e-3, 400); d = 3e-3
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(5.0, 2.5))
ax1.plot(1e3 * u, flux(u, d) / flux(0.0, d), color=COL["pickup"], lw=1.8, label="$\\Phi$")
ax1.plot(1e3 * u, 1 + dflux(0.0, d) * u / flux(0.0, d), "k--", lw=1, label="tangent")
ax2.plot(1e3 * u, dflux(u, d) / dflux(0.0, d), color=COL["pickup"], lw=1.8); ax2.axhline(1, color="k", ls="--", lw=1)
ax1.set_title("flux $\\Phi(u)/\\Phi(0)$, $d=3$ mm", fontsize=9); ax2.set_title("sensitivity $\\Phi'(u)/\\Phi'(0)$", fontsize=9)
for ax in (ax1, ax2):
ax.set_xlabel("$u$ (mm), toward the pole")
ax1.legend(fontsize=7, loc="upper left")
plt.tight_layout()
plt.show()
\[ e\propto\sum_p\phi_p(x_p)\,q_p'(t),\qquad \phi_p(x_p)=\sin\frac{p\pi x_p}{L} \]

s = ModalString(110.0, OPEN["A2"], B_open=1.5e-4)
a = s.pluck(0.12); P = 36
fig, axs = plt.subplots(2, 1, figsize=(5.0, 2.6), sharex=True)
for ax, (name, dp, col) in zip(axs, [("neck", 0.16, COL["string"]), ("bridge", 0.04, COL["pickup"])]):
w_pt = s.pickup_weights(dp) # point: sin(p pi x_p / L)
w_ap = s.pickup_weights(dp, width=0.02) # 2 cm aperture, trapezoid quadrature
ref = np.abs(a * s.om)[:P]; db = lambda v: 20 * np.log10(v / ref.max() + 1e-9)
ax.plot(s.p[:P], db(ref), color="0.6", lw=1.2)
ax.bar(s.p[:P], db(np.abs(a * s.om * w_ap)[:P]) + 70, bottom=-70, width=0.7, color=col)
for m in range(1, 3):
ax.axvline(m * s.L / dp, color=col, ls=":", lw=1)
ax.set_ylim(-70, 3); ax.set_ylabel("dB"); ax.set_xlim(0.3, P + 0.7)
ax.set_title(f"{name} pickup, {100 * dp:.0f} cm (gray: no pickup)", fontsize=8.5)
axs[1].set_xlabel("partial $p$")
plt.tight_layout()
plt.show()
for name, dp in [("neck", 0.16), ("bridge", 0.04)]:
(u_,), (ut_,) = s.response(a, 2.0, [s.pickup_weights(dp, width=0.02)])
save_wav(f"pos_{name}", pickup_filter(pickup_emf(u_, ut_, linear=True)))
neck pickup (16 cm)
bridge pickup (4 cm)
String is linear: \(u=A\sin\omega t\) stays a pure \(\omega\) at any \(A\) (class 17). Pickup is not: \(\Phi'(u)\approx\Phi'(0)+\Phi''(0)\,u\), so \[ e\approx-N\Phi'(0)A\omega\cos\omega t-\tfrac12N\Phi''(0)A^2\omega\,{\color{#c0392b}\sin2\omega t} \]

t = np.arange(int(0.5 * fs)) * k; w0 = 2 * np.pi * 110.0; A = np.geomspace(0.03e-3, 1.2e-3, 14)
dd = 1e-7; c2 = (dflux(dd) - dflux(-dd)) / (2 * dd) / dflux(0.0) # Phi''(0) / Phi'(0), centered difference
fig, ax = plt.subplots(figsize=(5.0, 2.5))
for lin, col, lab in [(False, COL["pickup"], "flux model"), (True, "0.5", "linear pickup")]:
h2 = [harmonics_db(pickup_emf(A_ * np.sin(w0 * t), A_ * w0 * np.cos(w0 * t), linear=lin), 110.0, 2)[1] for A_ in A]
ax.semilogx(1e3 * A, np.maximum(h2, -120), "o", color=col, ms=5, label=lab)
ax.semilogx(1e3 * A, 20 * np.log10(np.abs(c2) * A / 2), "k--", lw=1.2, label="$\\Phi''(0)A/2\\Phi'(0)$")
ax.set_xlabel("amplitude at the pickup $A$ (mm)"); ax.set_ylabel("$H_2/H_1$ (dB)"); ax.set_ylim(-125, 0)
ax.set_title("2nd harmonic of a pure 110 Hz motion, $d=3$ mm", fontsize=9); ax.legend(fontsize=7, loc="center right")
plt.tight_layout()
plt.show()
s = ModalString(110.0, OPEN["A2"], B_open=1.5e-4); W = [s.pickup_weights(0.16, width=0.02)]
for tag, amp, lin in [("soft", 0.1e-3, False), ("hard", 1.2e-3, False), ("hard_linear", 1.2e-3, True)]:
(u_,), (ut_,) = s.response(s.pluck(0.12, amp), 2.0, W)
save_wav(f"pluck_{tag}", pickup_filter(pickup_emf(u_, ut_, linear=lin)))
soft (0.1 mm)
hard (1.2 mm)
hard, linear

fig, axs = plt.subplots(3, 1, figsize=(5.4, 2.7), sharex=True)
for ax, (y, title) in zip(axs, [(F_riff, "bridge force (acoustic)"), (clean, "neck pickup, with its circuit"), (clean_bridge, "bridge pickup")]):
show_spec(ax, y, title, fmax=5); ax.set_ylabel("kHz", fontsize=7); ax.tick_params(labelsize=7)
axs[-1].set_xlabel("time (s)")
plt.tight_layout(h_pad=0.2)
plt.show()
acoustic: bridge force
electric: neck pickup
electric: bridge pickup

fig, ax = plt.subplots(figsize=(5.0, 2.5))
for (e, tip, F), col, lab in [(rh_nob, "0.55", "tine alone"), (rh_bar, COL["rhodes"], "tine + tonebar")]:
tt, db = frame_db(tip)
ax.plot(tt, db, color=col, lw=1.8, label=lab)
ax.set_ylim(-60, 2); ax.set_xlabel("time (s)"); ax.set_ylabel("tip (dB)"); ax.legend(fontsize=7.5)
ax.set_title("tine tip amplitude: the antiphase mode keeps ringing", fontsize=9)
plt.tight_layout()
plt.show()
tine alone
tine + tonebar
Tip swings across the pole axis: flux is a bell of the tip position \[ \Phi(s)=\bigl(1+s^2\bigr)^{-3/2},\quad s=\tfrac{\text{tip}}{w}+x_0,\quad e=-\Phi'(s)\,s_t \]

th = np.linspace(0, 4 * np.pi, 801)[:-1]
RH_X0 = [(0.0, "0.45"), (0.5, COL["rhodes"]), (1.5, COL["pickup"])]
fig, axs = plt.subplots(3, 2, figsize=(5.0, 2.8), sharex=True)
for j, (A, lab) in enumerate([(0.3, "soft: swing $\\pm0.3w$"), (1.1, "hard: swing $\\pm1.1w$")]):
for i, (x0, col) in enumerate(RH_X0):
ax = axs[i, j]; s_ = A * np.sin(th) + x0
e = 3 * s_ / (1 + s_**2)**2.5 * A * np.cos(th) # e = -Phi'(s) s_t for a sinusoidal tip
E = np.abs(np.fft.rfft(e)) # two periods: harmonic h is bin 2h
ax.plot(th / (2 * np.pi), np.sin(th), color="0.65", lw=0.9, ls="--")
ax.plot(th / (2 * np.pi), e / np.abs(e).max(), color=col, lw=1.5)
ax.set_yticks([]); ax.set_ylim(-1.2, 1.2); ax.set_xlim(0, 2)
r = "octave only" if E[2] < 1e-6 * E[4] else f"$H_2/H_1$ {20 * np.log10(E[4] / E[2]):.0f} dB"
ax.text(0.98, 0.04, r, transform=ax.transAxes, fontsize=6.5, ha="right", va="bottom", color=col,
bbox=dict(fc="white", ec="none", alpha=0.8, pad=0.5))
if j == 0:
ax.set_ylabel(f"$x_0={x0:g}$", fontsize=8, color=col, rotation=0, ha="right", va="center")
axs[0, j].set_title(lab, fontsize=8.5)
axs[-1, j].set_xlabel("time (tip periods)", fontsize=8, labelpad=0)
fig.text(0.5, 0.995, "dashed: tip motion; solid: pickup output $e(t)$", ha="center", va="top", fontsize=7.5, color="0.35")
plt.tight_layout(h_pad=0.15, w_pad=0.6, rect=(0, 0, 1, 0.96))
plt.show()
fig, axs = plt.subplots(1, 3, figsize=(9.0, 2.3), sharey=True)
names = {0.0: "centered on the pole", 0.5: "at the inflection", 1.5: "far from the pole"}
for ax, (x0, col) in zip(axs, [(0.0, "0.45"), (0.5, COL["rhodes"]), (1.5, COL["pickup"])]):
for j, (tag, lab, a_) in enumerate([("soft", "soft (0.4 m/s)", 0.35), ("hard", "hard (3 m/s)", 1.0)]):
h = harmonics_db(rh_cases[(tag, x0)][int(0.15 * fs):int(0.65 * fs)], 220.0, 6)
hh = np.maximum(h, -80)
ax.bar(np.arange(1, 7) + 0.2 * (2 * j - 1), hh + 80, bottom=-80, width=0.4, color=col, alpha=a_, ec=col, label=lab)
ax.set_xticks(range(1, 7)); ax.set_ylim(-80, 4); ax.set_xlabel("harmonic $h$ of $f_1=220$ Hz", labelpad=1)
ax.set_title(f"$x_0={x0:g}$: {names[x0]}", fontsize=9, color=col); ax.legend(fontsize=7, loc="upper right")
axs[0].set_ylabel("level (dB re strongest)")
plt.tight_layout(w_pad=0.6)
plt.show()
soft, \(x_0=0\)
soft, \(x_0=0.5\)
soft, \(x_0=1.5\)
hard, \(x_0=0\)
hard, \(x_0=0.5\)
hard, \(x_0=1.5\)


fig, axs = plt.subplots(1, 2, figsize=(5.0, 2.5), width_ratios=[1, 2.2])
z = np.linspace(-3, 3, 200)
axs[0].plot(z, np.tanh(z), color=COL["ebow"], lw=2); axs[0].plot(z, z, "k--", lw=0.8)
axs[0].set_ylim(-1.6, 1.6); axs[0].set_title("driver force $F/F_{\\max}$", fontsize=8.5)
v = eb_runs["above"][0]; tt = np.arange(len(v)) * k
axs[1].plot(tt, v / np.abs(v).max(), color=COL["ebow"], lw=0.3)
axs[1].annotate("exponential\ngrowth", (0.25, 0.3), (0.45, -0.85), fontsize=7, arrowprops=dict(arrowstyle="->", lw=0.7))
axs[1].text(2.0, 1.08, "limited: constant amplitude", fontsize=7, ha="center")
axs[1].set_ylim(-1.2, 1.3); axs[1].set_xlabel("time (s)"); axs[1].set_ylabel("$v_s$ (normalized)", labelpad=1); axs[1].set_yticks([])
axs[1].set_title("sensor velocity at $G=20\\,G_c$", fontsize=8.5)
axs[0].set_xlabel("$z/F_{\\max}$ (amp input)", labelpad=1)
plt.tight_layout()
plt.show()
Small amplitude, per mode: \[ \sigma_p^{\text{eff}}=\sigma_p-\frac{G\,\phi_p(x_s)\,\phi_p(x_d)\,\mathrm{Re}H(\omega_p)}{2m} \] \(\sigma_p^{\text{eff}}<0\): grows (Hopf, class 18). Lowest \(G_{c,p}\) wins.
Energy (class 16): \[ \frac{dH}{dt}=-2\sum_p\sigma_p\,m\,(q_p')^2+F\,u_t(x_d),\quad |F|\le F_{\max} \]
fig, ax = plt.subplots(figsize=(5.0, 2.6))
P8 = EB.p[:8]
for pol, col, off, lab in [(1, COL["ebow"], -0.2, "normal polarity"), (-1, "0.55", 0.2, "reversed (harmonic switch)")]:
r = ebow_thresholds(EB, XS, XD, pol=pol)[:8] / GC
ok = np.isfinite(r)
ax.bar(P8[ok] + off, r[ok], width=0.4, color=col, label=lab)
ax.plot(P8[~ok] + off, np.full((~ok).sum(), 1.4), "x", color=col, ms=5, mew=1.4)
j = np.argmin(np.where(ok, r, np.inf))
ax.text(P8[j] + off, r[j] * 1.3, "starts\nfirst", fontsize=7, color=col, ha="center", va="bottom", linespacing=0.9)
ax.plot([], [], "x", color="0.3", label="$\\times$: never grows ($\\phi_p(x_s)\\phi_p(x_d)$ wrong sign)")
ax.set_yscale("log"); ax.set_ylim(0.7, 5000); ax.set_xticks(range(1, 9)); ax.set_xlabel("mode $p$")
ax.set_ylabel("onset gain $G_{c,p}\\ /\\ G_{c,1}$")
ax.set_title("gain at which mode $p$ starts to grow", fontsize=9); ax.legend(fontsize=6.5, loc="upper left")
plt.tight_layout(); plt.show()
fig, ax = plt.subplots(figsize=(5.0, 2.6))
for name, col, lab in [("below", "0.55", "$G=0.8\\,G_c$: loss wins, decays"), ("above", COL["ebow"], "$G=20\\,G_c$ with $\\tanh$ limit: grows, then levels off"),
("nosat", COL["pickup"], "$G=20\\,G_c$, no limit: grows forever")]:
E = eb_runs[name][1]; tE = np.arange(len(E)) * 64 * k
ax.plot(tE, 10 * np.log10(E / E[1]), color=col, lw=1.8, label=lab)
En = eb_runs["nosat"][1]; Efin = 10 * np.log10(En[-2] / En[1])
ax.annotate(f"reaches {Efin:.0f} dB at 3 s", (0.4, 58), (0.55, 36), fontsize=7, color=COL["pickup"],
arrowprops=dict(arrowstyle="->", color=COL["pickup"], lw=0.8))
ax.set_ylim(-50, 60); ax.set_xlim(0, 3); ax.axhline(0, color="0.8", lw=0.8)
ax.set_xlabel("time (s)"); ax.set_ylabel("string energy (dB re start)")
ax.set_title("energy $H(t)$: the limit keeps it bounded", fontsize=9); ax.legend(fontsize=6.5, loc="lower right")
plt.tight_layout(); plt.show()
fig, axs = plt.subplots(1, 4, figsize=(9.6, 2.3), sharey=True)
for ax, (name, title) in zip(axs, [("pluck", "pluck only ($G=0$)"), ("below", "$G=0.8\\,G_c$: decays"),
("above", "$G=20\\,G_c$: sustain"), ("harmonic", "reversed: 3rd partial")]):
show_spec(ax, eb_runs[name][0], title, fmax=2.5); ax.set_xlabel("time (s)")
axs[0].set_ylabel("kHz")
plt.tight_layout()
plt.show()
pluck only
\(G=0.8\,G_c\)
\(G=20\,G_c\)
harmonic mode
Bow (class 16): friction of the relative velocity \[ F=-F_B\,\phi(v_{\text{rel}}) \]
E-bow: a magnetic force from the sensed velocity \[ F=F_{\max}\tanh\bigl(G\,(H*v_s)/F_{\max}\bigr) \]

fig, axs = plt.subplots(2, 1, figsize=(5.0, 2.7))
T0 = int(round(fs / 196.0)); n0 = int(2.5 * fs); sl = slice(n0, n0 + 3 * T0)
for (y, col, lab), off in zip([(bow_v, "#a0522d", "bow, $F_B=0.2$ N"), (eb_runs["above"][0], COL["ebow"], "E-bow, $20\\,G_c$")], [-0.2, 0.2]):
axs[0].plot(1e3 * np.arange(3 * T0) * k, y[sl] / np.abs(y[sl]).max(), color=col, lw=1.3, label=lab)
axs[1].bar(np.arange(1, 11) + off, harmonics_db(y[n0:], 196.0, 10) + 70, bottom=-70, width=0.4, color=col)
axs[0].set_xlabel("ms", labelpad=0); axs[0].set_yticks([]); axs[0].legend(fontsize=7, loc="lower center", ncol=2, bbox_to_anchor=(0.5, 0.98), frameon=False)
axs[0].set_title("velocity at the sensor point, 3 periods", fontsize=8.5, pad=16)
axs[1].set_ylim(-70, 3); axs[1].set_xlabel("harmonic", labelpad=0); axs[1].set_ylabel("dB")
plt.tight_layout(h_pad=0.3)
plt.show()
bow, 0.2 N
E-bow, \(20\,G_c\)
bow, pressed (1 N)
Analog effects
Virtual analog (the circuit, simulated)
| element | law | role in the ODE | mechanical analog |
|---|---|---|---|
| resistor \(R\) | \(v=R\,i\) | algebraic | damper: \(F=c\,\dot x\) |
| capacitor \(C\) | \(i=C\,v'\) | a state (its voltage) | spring: \(F=\kappa x\), \(C\leftrightarrow1/\kappa\) |
| inductor \(L\) | \(v=L\,i'\) | a state (its current) | mass: \(F=m\,\ddot x\) |
| diode | \(i=I_s\bigl(e^{v/V_t}-1\bigr)\) | nonlinear, algebraic | one-way damper (check valve) |
| triode | \(I_p(v_{gk},v_{pk})\) (Koren) | nonlinear, algebraic | valve: a small \(v_{gk}\) throttles a large flow \(I_p\) |
\(v\): voltage across the element (V) \(\leftrightarrow\) force \(F\);
\(i\): current through it (A) \(\leftrightarrow\) velocity \(\dot x\); \('=d/dt\).
\(I_s\): diode saturation current; \(V_t\approx26\) mV: thermal voltage.
\(I_p\): plate current; \(v_{gk}\), \(v_{pk}\): grid–cathode and plate–cathode voltages.

Kirchhoff, state \(\mathbf{x}=(i,v)\): \[ L\,i'=e-R\,i-v,\quad C\,v'=i-v/R_L\ \Rightarrow\ \mathbf{x}'=A\mathbf{x}+B\,e \] Trapezoid (class 12) \(=\) bilinear \(s\to\frac2k\frac{1-z^{-1}}{1+z^{-1}}\)

b_, a_ = pickup_tf(**PU)
f = np.logspace(np.log10(300), np.log10(20000), 2000)
Ha = freqs(b_, a_, 2 * np.pi * f)[1] # analog
Hb = freqz(*bilinear(b_, a_, fs), f, fs=fs)[1] # trapezoid = bilinear
fpk = f[np.argmax(np.abs(Ha))]
kw = 2 * np.tan(np.pi * fpk / fs) / (2 * np.pi * fpk) # prewarped step for the peak
Hw = freqz(*bilinear(b_, a_, 1 / kw), f, fs=fs)[1]
e_test = np.random.default_rng(1).standard_normal(2000)
gap_ss = np.abs(trapezoid_ss(*pickup_ss(**PU), e_test) - pickup_filter(e_test)).max()
fig, ax = plt.subplots(figsize=(5.0, 2.6))
ax.semilogx(f, 20 * np.log10(np.abs(Ha)), color="k", lw=2.4, label=f"analog: peak {fpk:.0f} Hz")
ax.semilogx(f, 20 * np.log10(np.abs(Hb)), color=COL["circuit"], lw=1.6, label=f"trapezoid: peak {f[np.argmax(np.abs(Hb))]:.0f} Hz")
ax.semilogx(f, 20 * np.log10(np.abs(Hw)), "--", color=COL["pickup"], lw=1.4, label="trapezoid, prewarped")
ax.set_xlabel("frequency (Hz)"); ax.set_ylabel("dB"); ax.set_ylim(-40, 12); ax.legend(fontsize=7, loc="lower left")
ax.set_title(f"pickup + cable (state space loop = scipy bilinear to {gap_ss:.0e})", fontsize=8.5)
plt.tight_layout()
plt.show()
s = ModalString(110.0, OPEN["A2"], B_open=1.5e-4)
(u_,), (ut_,) = s.response(s.pluck(0.12), 2.0, [s.pickup_weights(0.16, width=0.02)])
e_raw = pickup_emf(u_, ut_)
save_wav("circuit_raw", e_raw); save_wav("circuit_rlc", pickup_filter(e_raw))
EMF only (velocity)
through the RLC circuit
Kirchhoff at the node, Shockley for the pair: \[ C\,V'=\frac{u-V}{R}-2I_s\sinh\frac{V}{V_t}=C\,f(V,u) \]
\[ J(V)=-\frac{1}{RC}-\frac{2I_s}{CV_t}\cosh\frac{V}{V_t} \]

V = np.linspace(0, 0.72, 400)
kJ = k * (1 / (R_D * C_D) + 2 * IS_D / (C_D * VT_D) * np.cosh(V / VT_D))
fig, ax = plt.subplots(figsize=(5.0, 2.8))
ax.semilogy(V, kJ, color=COL["circuit"], lw=2.2, label="$k|J(V)|$ at 44.1 kHz")
for L_, ls in [(1, "-"), (8, "--"), (32, ":")]:
ax.axhline(2 * L_, color=COL["pickup"], ls=ls, lw=1.2)
Vb = V[np.argmax(kJ > 2 * L_)]
ax.text(0.01, 2 * L_ * 1.25, f"forward Euler, {L_}x: stable for $V<{Vb:.2f}$ V", fontsize=7.5, color=COL["pickup"])
ax.axvspan(0.55, 0.72, color="0.92", zorder=0); ax.text(0.635, 0.3, "clipping\nregion", ha="center", fontsize=8, color="0.4")
ax.set_xlabel("capacitor voltage $V$ (V)"); ax.set_ylabel("$k\\,|J(V)|$"); ax.set_ylim(0.2, 3e3); ax.legend(fontsize=7.5, loc="upper left")
ax.set_title(f"$R={R_D / 1e3:.1f}$ k$\\Omega$, $C={C_D * 1e9:.0f}$ nF, $I_s={IS_D * 1e9:.2f}$ nA, $V_t={1e3 * VT_D:.1f}$ mV", fontsize=8.5)
plt.tight_layout()
plt.show()
Trapezoid: solve \(F(V^{n+1})=p\) each sample, \[ \begin{aligned} F(V)&=\Bigl(1+\tfrac{k}{2RC}\Bigr)V+\tfrac{kI_s}{C}\sinh\tfrac{V}{V_t}\\ p&=V^n+\tfrac k2\Bigl(f^n+\tfrac{u^{n+1}}{RC}\Bigr) \end{aligned} \] \(F\) monotone: one root. Newton (5) or a table of \(F^{-1}\) (8).
| step (5 V, 220 Hz) | RMS error (V) | \(f\) evals / sample |
|---|---|---|
| forward Euler, 1x | blows up | 1 |
| forward Euler, 32x | 5.5e-02 | 32 |
| trapezoid + Newton | 4.8e-04 | 3.7 |
| trapezoid by table | 4.8e-04 | 1 lookup |
| memoryless table (\(C=0\)) | 3.0e-02 | 1 lookup |

t3 = 1e3 * np.arange(len(u3)) * k; sl = slice(0, int(1.6 * fs / 220))
fig, ax = plt.subplots(figsize=(5.0, 2.5))
ax.plot(t3[sl], ref3[sl], color="k", lw=3, alpha=0.35, label="reference (32x)")
ax.plot(t3[sl], y_fe32[sl], color=COL["pickup"], lw=1, ls="--", label="Euler, 32x")
ax.plot(t3[sl], y_tr[sl], color=COL["circuit"], lw=1.4, label="trapezoid + Newton, 1x")
ax.plot(t3[sl], y_st[sl], color=COL["tube"], lw=1, ls=":", label="memoryless")
ax.plot(t3[blow], 0, "x", color=COL["pickup"], ms=10, mew=2.5)
ax.annotate(f"Euler 1x: overflow at sample {blow}", (t3[blow], 0), (2.5, 0.08), fontsize=7.5,
color=COL["pickup"], arrowprops=dict(arrowstyle="->", color=COL["pickup"], lw=0.8))
ax.set_xlabel("time (ms)"); ax.set_ylabel("$V$ (V)"); ax.set_ylim(-0.85, 0.85)
ax.legend(fontsize=6.5, ncol=4, loc="lower center", bbox_to_anchor=(0.5, 1.0), frameon=False, handlelength=1.5)
plt.tight_layout()
plt.show()
a1, b1 = 1 + k / (2 * R_D * C_D), k * IS_D / C_D
Vs = 0.55; p = a1 * Vs + b1 * np.sinh(Vs / VT_D) # a sample whose root is 0.55 V
Fv = lambda v: a1 * v + b1 * np.sinh(v / VT_D) - p
path = [0.0]
for _ in range(25): # Newton from a cold start
v = path[-1]; path.append(v - Fv(v) / (a1 + b1 / VT_D * np.cosh(v / VT_D)))
if abs(path[-1] - path[-2]) < 1e-9: break
vv = np.linspace(-0.1, 1.15, 600)
fig, ax = plt.subplots(figsize=(5.0, 2.6))
ax.plot(vv, np.arcsinh(Fv(vv)), "k", lw=1.8, label="$\\mathrm{asinh}\\,(F(V)-p)$")
ax.plot(path, np.arcsinh(Fv(np.array(path))), "o-", color=COL["pickup"], ms=4, lw=0.8, label=f"cold start: {len(path) - 1} iterations")
ax.axhline(0, color="0.7", lw=0.8); ax.axvline(Vs, color=COL["circuit"], ls=":", lw=1.2)
ax.set_xlabel("$V$ (V)"); ax.set_ylabel("residual (asinh)"); ax.legend(fontsize=7.5, loc="upper left")
ax.set_title("the first tangent overshoots; then about $V_t$ per step", fontsize=9)
plt.tight_layout()
plt.show()
fig, ax = plt.subplots(figsize=(5.0, 2.6))
bins = np.arange(0.5, 40.5)
for (lab, its), col in zip(nt_runs.items(), [COL["circuit"], COL["pickup"], COL["tube"]]):
ax.hist(np.minimum(its, 39), bins, color=col, alpha=0.55, label=f"{lab}: mean {its.mean():.1f}, max {its.max()}")
ax.set_yscale("log"); ax.set_xlabel("Newton iterations per sample"); ax.legend(fontsize=7)
ax.set_title("guitar riff, gain 20, 44.1 kHz", fontsize=9)
plt.tight_layout()
plt.show()

fig, axs = plt.subplots(2, 1, figsize=(5.0, 2.5), sharex=True)
for ax, (y, title) in zip(axs, [(y_naive, "memoryless clipper, 44.1 kHz"), (y_os8, "8x oversampled")]):
f, S = spectrum_db(y)
ax.plot(f / 1e3, S, color="k", lw=0.6)
for h in range(1, 18):
ax.axvline(h * 1.2445, color=COL["circuit"], ls=":", lw=0.8)
ax.set_ylim(-120, 3); ax.set_ylabel("dB"); ax.set_title(title + f": aliases {alias_db(y, 1244.5):.0f} dB", fontsize=8.5)
axs[1].set_xlabel("kHz (dotted: harmonics of 1244.5 Hz)"); axs[1].set_xlim(0, 22.05)
plt.tight_layout(h_pad=0.3)
plt.show()
sweep 300 Hz to 5 kHz, naive: listen for tones going down
Oversample by \(L\): \(\uparrow L\), \(g\) at \(Lf_s\), lowpass, \(\downarrow L\)

fig, ax = plt.subplots(figsize=(5.0, 2.3))
for (lab, r), col, mk in zip(al_res.items(), ["k", COL["tube"], COL["circuit"], COL["string"]], ["o", "s", "^", "D"]):
ax.semilogx(f_list, r, mk + "-", color=col, lw=1.5, ms=4, label=lab)
ax.set_xlabel("input frequency (Hz), 5 V sine"); ax.set_ylabel("aliased energy (dB)")
ax.set_title("energy between the harmonics, re the harmonics", fontsize=9); ax.legend(fontsize=7.5)
ax.set_xticks(f_list); ax.set_xticklabels([str(v) for v in f_list], fontsize=7); ax.minorticks_off()
plt.tight_layout()
plt.show()
naive, 1x
ADAA, 1x
oversampled 8x
At each port: incident \(a=v+R\,i\), reflected \(b=v-R\,i\) (\(R\): port resistance, our choice)
| element | port \(R\) | with the trapezoidal rule |
|---|---|---|
| capacitor \(C\) | \(k/(2C)\) | \(b^{n}=a^{n-1}\): a unit delay |
| inductor \(L\) | \(2L/k\) | \(b^{n}=-a^{n-1}\) |
| source \(u\) with \(R\) | \(R\) | \(b=u\) |
One sample, in the order of the circled numbers:

y_wdf = clip_wdf(u3); y_ref, _ = clip_trap(u3, tol=1e-13)
sl = slice(0, int(1.3 * fs / 220))
fig, ax = plt.subplots(figsize=(5.0, 2.2))
ax.plot(t3[sl], u3[sl] / 5 * 0.8, color="0.75", lw=1, label="input $u$ (scaled)")
ax.plot(t3[sl], y_ref[sl], color=C_SRC if "C_SRC" in dir() else COL["circuit"], lw=2.4, alpha=0.6, label="trapezoid + Newton")
ax.plot(t3[sl][::6], y_wdf[sl][::6], "o", color=COL["pickup"], ms=3, label="wave digital filter (every 6th sample)")
ax.set_xlabel("time (ms)"); ax.set_ylabel("$V$ (V)"); ax.legend(fontsize=7, loc="lower left")
ax.set_title(f"same output: max $|v_{{\\mathrm{{WDF}}}}-v_{{\\mathrm{{trap}}}}|$ = {np.abs(y_wdf - y_ref).max():.0e} V (rounding)", fontsize=8.5)
plt.tight_layout()
plt.show()
Pros: modular, passive by construction. Limit: one nonlinearity (the root).





The same recipe as the diode clipper (Steps 1 to 4):
vp0, vk0, Ip0, it0 = triode_bias()
t_c = np.arange(int(0.2 * fs)) * k; per = slice(len(t_c) - int(fs / 50), len(t_c))
fig, ax = plt.subplots(figsize=(4.6, 2.8))
for A, col in [(0.5, "0.55"), (8.0, COL["tube"])]:
u_ = A * np.sin(2 * np.pi * 50 * t_c); y_ = triode(u_)
ax.plot(u_[per], y_[per] - vp0, color=col, lw=2 if A > 1 else 1.4, label=f"input amplitude {A:g} V")
ax.axhline(0, color="0.85", lw=0.8); ax.axvline(0, color="0.85", lw=0.8)
ax.annotate("cutoff: the current\ncannot go below 0", xy=(-6.5, 70), xytext=(-7.8, 20), fontsize=8, arrowprops=dict(arrowstyle="->", color="0.3"))
ax.annotate("grid conducts:\nthe output stops falling", xy=(5.5, -95), xytext=(2.6, -45), fontsize=8, arrowprops=dict(arrowstyle="->", color="0.3"))
ax.annotate("small input: a straight line,\nslope $\\approx -60$ (the gain)", xy=(0.2, -10), xytext=(-7.8, -75), fontsize=8, color="0.3", arrowprops=dict(arrowstyle="->", color="0.5"))
ax.set_xlabel("grid input $u$ (V)"); ax.set_ylabel("plate output $\\Delta v_p$ (V)"); ax.legend(fontsize=7, loc="upper right")
ax.set_title("one triode stage: input vs output", fontsize=9)
plt.tight_layout(); plt.show()


fig, axs = plt.subplots(1, 2, figsize=(5.5, 2.4), width_ratios=[1.2, 1])
axs[0].bar(np.arange(1, 9) - 0.2, h_diode + 110, bottom=-110, width=0.4, color=COL["circuit"], label="diode")
axs[0].bar(np.arange(1, 9) + 0.2, h_tri + 110, bottom=-110, width=0.4, color=COL["tube"], label="triode")
axs[0].set_ylim(-110, 3); axs[0].set_xlabel("harmonic of 110 Hz"); axs[0].set_ylabel("dB"); axs[0].legend(fontsize=7)
f = np.logspace(np.log10(40), np.log10(20000), 1500); H = np.ones(len(f), complex)
for sec in CAB:
H *= freqz(*biquad(*sec), f, fs=fs)[1]
axs[1].semilogx(f, 20 * np.log10(np.abs(H)), color="0.3", lw=1.8)
axs[1].set_ylim(-50, 10); axs[1].set_xlabel("Hz"); axs[1].set_title("cabinet response", fontsize=9)
plt.tight_layout()
plt.show()
overdrive (diode, 4x) + cabinet
triode (2x) + cabinet
triode, no cabinet: fizz

fig, ax = plt.subplots(figsize=(4.6, 2.3))
f = np.logspace(np.log10(60), np.log10(10000), 800)
for p in [0, 0.25, 0.5, 0.75, 1.0]:
fc_ = wah_fc(p); w0 = 2 * np.pi * fc_ / fs; al = np.sin(w0) / 12
H = freqz([al, 0, -al], [1 + al, -2 * np.cos(w0), 1 - al], f, fs=fs)[1]
ax.semilogx(f, 20 * np.log10(np.abs(H)), color=plt.cm.RdPu(0.35 + 0.6 * p), lw=1.8)
ax.text(fc_, 1.0, "heel" if p == 0 else ("toe" if p == 1 else ""), ha="center", fontsize=8, color=plt.cm.RdPu(0.35 + 0.6 * p))
ax.annotate("", xy=(2200, -26), xytext=(350, -26), arrowprops=dict(arrowstyle="-|>", color="0.3", lw=1.2))
ax.text(880, -24.5, "pedal moves $f_c$", ha="center", fontsize=8, color="0.3")
ax.set_ylim(-30, 5); ax.set_xlabel("frequency (Hz)"); ax.set_ylabel("dB"); ax.set_title("bandpass for 5 pedal positions ($Q=6$)", fontsize=9)
plt.tight_layout(); plt.show()

clean riff (no wah)
wah, foot rocking
auto-wah
wah → overdrive → tube + cabinet
Same \(H(z)\) at every instant, different states:
Rule: when parameters move, use a structure whose states are physical (state-variable, ladder, wave digital filter).
t_s = np.arange(int(0.08 * fs)) * k; x_s = np.sin(2 * np.pi * 400 * t_s)
snap = lambda tr: np.clip((t_s - 0.04) / max(tr, 1e-9), 0, 1)
fig, axs = plt.subplots(1, 2, figsize=(5.4, 2.5), width_ratios=[1.5, 1])
y_svf, y_df = wah_svf(x_s, snap(0.002)), wah_df2(x_s, snap(0.002))
axs[0].plot(1e3 * t_s, y_df, color="0.55", lw=1.1, label="direct form II")
axs[0].plot(1e3 * t_s, y_svf, color=COL["wah"], lw=1.5, label="state-variable (trapezoid)")
axs[0].axvspan(40, 42, color="0.85"); axs[0].text(41, 3.0, "heel $\\to$ toe\nin 2 ms", fontsize=7.5, ha="left", va="top")
axs[0].set_xlim(20, 70); axs[0].set_xlabel("time (ms)"); axs[0].set_ylabel("output"); axs[0].legend(fontsize=7, loc="lower left"); axs[0].set_title("400 Hz sine, pedal snapped", fontsize=9)
trs = np.array([0.1, 0.3, 1, 3, 10, 30]) * 1e-3
for fn, col, lab in [(wah_df2, "0.55", "direct form II"), (wah_svf, COL["wah"], "state-variable")]:
pk = [(lambda y: np.abs(y[int(0.04 * fs):]).max() / np.abs(y[int(0.02 * fs):int(0.04 * fs)]).max())(fn(x_s, snap(tr))) for tr in trs]
axs[1].semilogx(1e3 * trs, pk, "o-", color=col, ms=4, lw=1.4, label=lab)
axs[1].axhline(1, color="0.7", lw=0.8, ls=":"); axs[1].set_xlabel("snap time (ms)"); axs[1].set_ylabel("peak after / before"); axs[1].set_yscale("log"); axs[1].legend(fontsize=7)
axs[1].set_title("burst size", fontsize=9)
plt.tight_layout(); plt.show()
\[ \begin{aligned} u_{tt}&=-\kappa^2\bigl(u_{xxxx}+2q^2u_{xx}+q^4u\bigr)+\gamma^2q^2(\zeta_x-u)\\ \zeta_{tt}&=\gamma^2(\zeta_{xx}-u_x) \end{aligned} \] \(q\): coil curvature. \(q\to0\): a bar (15) + a 1D wave (14).

b = np.linspace(1, 1900, 800); lo, hi = [], []
for bb in b: # 2 x 2 generalized eigenproblem per wavenumber
Kb = np.array([[KAP**2 * (bb**2 - QQ**2)**2 + 2511.0**2 * QQ**2, 2511.0**2 * QQ**2 * bb],
[2511.0**2 * QQ**2 * bb, 2511.0**2 * QQ**2 * bb**2]])
lam = np.linalg.eigvalsh(np.diag([1, 1 / QQ]) @ Kb @ np.diag([1, 1 / QQ]))
lo.append(np.sqrt(max(lam[0], 0)) / (2 * np.pi)); hi.append(np.sqrt(lam[1]) / (2 * np.pi))
fig, axs = plt.subplots(1, 2, figsize=(5.0, 2.7), width_ratios=[2.2, 1])
axs[0].plot(b, np.array(lo) / 1e3, color=COL["spring"], lw=2)
axs[0].plot(SP[:, 0], SP[:, 1] / (2 * np.pi * 1e3), ".", color="k", ms=1.5, label=f"modes $\\beta=m\\pi$: {len(SP)}")
axs[0].axhline(fc_formula / 1e3, color=COL["pickup"], ls="--", lw=1)
axs[0].text(30, 6.0, f"$f_c$: formula {fc_formula:.0f} Hz,\ncomputed {SP[SP[:, 0] < QQ, 1].max() / (2 * np.pi):.0f} Hz",
fontsize=7, color=COL["pickup"])
axs[0].axvline(QQ, color="0.6", ls=":"); axs[0].text(QQ - 40, 15, "$\\beta=q$", fontsize=8, ha="right")
axs[0].set_ylim(0, 20); axs[0].set_xlabel("$\\beta$"); axs[0].set_ylabel("kHz"); axs[0].legend(fontsize=7, loc="upper left")
axs[0].set_title("lower branch: what we hear", fontsize=9)
axs[1].plot(b, np.array(hi) / 1e3, color="0.5", lw=2); axs[1].set_xlabel("$\\beta$")
axs[1].set_title("upper branch", fontsize=9); axs[1].set_ylim(390, 420)
plt.tight_layout()
plt.show()
Check (class 10): a packet at \(f\) moves at \(v_g=d\omega/d\beta\), arrives at \[ t_j=\frac{2j+1}{|v_g|},\quad j=0,1,2,\dots \]

fig, ax = plt.subplots(figsize=(5.4, 2.6))
show_spec(ax, h_spring[:int(1.0 * fs)], f"spring impulse response ({n_spring} modes); dotted: $t_j$", fmax=5, win=1024, vmin=-70)
for j in range(4):
for sel in [(bS < 520), (bS > 560) & (bS < 980), (bS > 1020)]:
tj = (2 * j + 1) / np.abs(vg[sel])
ax.plot(tj, wS[sel] / (2 * np.pi * 1e3), ":", color="w", lw=1.1)
ax.set_xlim(0, 1.0); ax.set_xlabel("time (s)"); ax.set_ylabel("kHz")
plt.tight_layout()
plt.show()
impulse response (tap the tank)
clean riff + spring reverb
Spring: 1D, sparse modes, a hump: distinct chirps, dark cutoff. Same method: the character is in \(\omega(\beta)\)

fig, axs = plt.subplots(1, 2, figsize=(5.8, 2.6), sharey=True)
show_spec(axs[0], h_plate[:int(1.0 * fs)], f"plate, {n_plate} modes: smooth", fmax=8, win=1024, vmin=-70)
show_spec(axs[1], h_spring[:int(1.0 * fs)], f"spring, {n_spring} modes: chirps", fmax=8, win=1024, vmin=-70)
axs[0].set_ylabel("kHz")
for ax in axs:
ax.set_xlabel("time (s)")
plt.tight_layout()
plt.show()
riff + plate
riff + spring

1 string
2 + pickup
3 + wah
4 + overdrive
5 + tube + cabinet
6 + spring reverb
| stage | method | Python time for 3.6 s of audio | real-time factor |
|---|---|---|---|
| string + pickup | 12 notes, exact free vibration + flux | 1.44 s | 0.40 |
| pickup circuit | bilinear biquad | 0.00 s | 0.00 |
| wah (state-variable, foot rocking) | trapezoid, coefficients per sample | 0.09 s | 0.02 |
| overdrive (4x, Newton) | trapezoid + Newton per sample | 0.76 s | 0.21 |
| triode (2x, 2x2 Newton) + cabinet | Newton per sample + 5 biquads | 2.60 s | 0.72 |
| spring (FFT convolution) | one FFT convolution | 0.01 s | 0.00 |
| explicit (Euler, RK) | trapezoid + Newton | table | wave digital filter | modal | |
|---|---|---|---|---|---|
| where today | E-bow loop, contacts | pickup RLC, wah (no Newton: linear), diode clipper, triode | inverse of \(F\), memoryless clipper | diode clipper | string, tine, spring, plate |
| accuracy | 1st order (Euler); warps less | 2nd order; frequency warping (prewarp) | trapezoid + interpolation error; memoryless loses \(C\) | identical to trapezoid | exact frequencies |
| stability | \(k\lvert\lambda\rvert\) bound: needs \(\times30\) for diodes | linear part: unconditional; Newton must converge | as the scheme it tabulates | passive by construction | always (linear) |
| cost per sample | \(\times\) oversampling | iterations (watch the worst case) | one lookup | one scalar Newton at the root | \(O(\text{modes})\) |
| breaks down | stiff circuits | many unknowns: an \(n\times n\) solve per iteration | more than 1 or 2 inputs (curse of dimension) | several nonlinearities | nonlinear or time-varying parts |
Checklist

| question | how to show it | where we did it |
|---|---|---|
| Consistent? order of accuracy | halve \(h\) or \(k\); the error drops by \(2^{p}\) (log-log slope) | 9, 10, 12 |
| Stable? | CFL or eigenvalues (linear); a conserved or bounded energy (nonlinear); Newton iterations: mean and worst | 14, 13, today (E-bow, clipper) |
| Converged? | a reference at a finer resolution; the error against it | 15, today (32x clipper reference) |
| Matches reality? | partial frequencies, \(T_{60}\), spectral envelope, impulse response vs a recording or the built object | 16, 17 |
| Matches theory? | overlay an analytic prediction (dispersion, group delay, threshold) | today (chirps, E-bow thresholds), 16 |
| Cost? | real-time factor; cost against accuracy | 17, today (chain) |
| Why this method? | what another method would gain or lose, in one paragraph | 18, today |
Before 12/03: 11/26 no class (admission interviews); 12/01 open office hour day: bring your project questions.
Suggested outline (mapped to the course ILO):
The report is due after the presentation.


Class 19: Sound Effects