template<FloatType T, typename Tree>
class dspark::wdf::DiodePairRoot< T, Tree >
Antiparallel diode pair root (the classic clipper nonlinearity).
Shockley model: i(v) = 2 Is sinh(v / (n Vt)). Defaults approximate a 1N4148 (Is = 2.52 nA, n = 1.752, Vt = 25.85 mV).
Solver: in the normalised form s + c (e^s - e^-s) = |a| / nVt (s = v/nVt, c = R Is / nVt) the root is read from series and tables built for the constants of the circuit, with no transcendental function and no division per sample, by drive:
- Low drive: the exact reversion series of detail::DiodeSeries, to y^15 for incident waves below about 46-53 mV (default constants behind 0.7-2.2 k ohm; 23 mV at 0.35 M ohm) and, for 1e-4 < c <= 0.02, to y^35 above that, 1.2 to 2.5 units of nVt further (incident waves up to 159 mV behind 2.2 k ohm and 80 mV behind 0.33 M ohm). Beyond c = 0.02 (silicon diodes behind more than about 0.36 M ohm, germanium behind a few k ohm) the series to y^35 comes from a recurrence for the constant (detail::DiodeLocal::origin()).
- Medium drive, for c > 1e-4 where the series end below it: local expansions of the root itself (detail::DiodeLocal), up to 56 cells of sixteen terms found from the bits of the drive. They run from the end of the series to the drive from which the table's reverse-diode correction is short.
- High drive, up to ln c + x = 2^20: detail::DiodeOmegaTable gives the forward diode's root s1 = x - omega(ln c + x) to double precision, and the reverse diode's correction comes from the same table point, to three orders (c^2 / (omega (1 + omega)) <= 4.05e-5 and c^2 / (1 + omega)^2 <= 1.47e-5 there for c > 1e-4; for c <= 1e-4 the table starts at the end of the series).
The local expansions belong to one set of constants. prepare() builds them for the circuit as it stands; when a value of the circuit or of the diodes changes while running they are dropped, and once the new constants have held for 256 samples they are built again one cell per sample (at most about 4000 multiply-adds in a sample, 10 to 45 microseconds in all). Until then, and for c > 1e6 or beyond ln c + x = 2^20, the root comes from the closed forms of the two diodes with correction steps on the exact equation: each diode alone has the root s = A - omega(ln c + A) (Wright omega, Werner et al. 2015), the estimate s0 = A - omega(ln c + A) + omega(ln c - A) keeps both and is off by O(c^2), and a Newton step (c <= 1e-4), a Halley step (up to c = 0.02, where the table root with its full correction to seventh order answers first wherever it reaches) or repeated Halley steps until one is below 1e-6 relative (beyond) land on the root, with one expm1() and one division each. A circuit whose values move every sample therefore pays that path for c > 0.02 and at most the table's full correction below.
Accuracy: against a long double reference over drives from 1e-6 to 1e6 times (1 + 2c), the worst relative error is 3.2e-16 for c from 1e-9 to 1e5; with the correction steps alone, 1.1e-15 for c from 1e-15 to 1e5. The result does not depend on the previous sample.
Cost for an RC clipper at 48 kHz, measured on four machines (GCC, Clang and MSVC on x64, GCC on arm64) next to the single-omega approximation that ignores the reverse diode, from 0.05 to 8 V peak: behind 2.2 k to 330 k ohm with the default constants (c up to 0.018) 15 to 39 ns per sample, 0.54 to 0.88 times the approximation's cost (whose error is -39 to -88 dB); behind 1 M to 10 M ohm (c from 0.05 to 0.5) 18 to 39 ns, 0.55 to 0.81 times the approximation (-12 to -49 dB).
Memory: 9.8 KB per instance, most of it the cells.
Definition at line 1738 of file WDF.h.