DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::wdf::DiodeRoot< T, Tree > Class Template Reference

Single Shockley diode root: i(v) = Is (e^{v/(n Vt)} - 1). More...

#include <WDF.h>

Public Member Functions

 DiodeRoot (Tree &tree, T saturationCurrent=T(2.52e-9), T idealityTimesVt=T(1.752 *0.02585)) noexcept
 
void setSaturationCurrent (T amps) noexcept
 
void setIdealityTimesVt (T volts) noexcept
 
void prepare (double sampleRate) noexcept
 
void reset () noexcept
 
void process () noexcept
 
T getVoltage () const noexcept
 Voltage across the diode.
 

Detailed Description

template<FloatType T, typename Tree>
class dspark::wdf::DiodeRoot< T, Tree >

Single Shockley diode root: i(v) = Is (e^{v/(n Vt)} - 1).

Conducts for positive v, blocks (down to -Is) for negative v.

Solver: s + c (e^s - 1) = a / nVt (s = v/nVt, c = R Is / nVt) has the exact root s = A + c - omega(ln c + A + c) (Werner et al. 2015). It is read from series and tables, with no transcendental function and no division per sample, by constant and drive:

  • c up to 0.04 (the default constants behind up to about 0.7 M ohm): the exact reversion series of detail::DiodeSeries for incident waves below about 42-49 mV of either sign (default constants behind 0.7-2.2 k ohm), where A + c and omega would cancel, and the closed form from detail::DiodeOmegaTable beyond, up to ln c + A + c = 2^20.
  • c from 0.04 to 1e5 (germanium diodes, very large resistances): at low drive a series to y^33 from a recurrence for the constant (detail::DiodeLocal::originSingle()); outside the drives of the roots -1 and 1.5 the closed form from the table, with x + c, ln c and the constant term of the table each carried to twice the working precision so that their difference keeps it; and between the series and those two drives, on either side, local expansions of the root (detail::DiodeLocal): cells of sixteen terms found from the bits of the drive, at most 24 of them for 3000 constants over that range, in room for 32.

The series and the cells of a constant beyond 0.04 belong to it. prepare() builds them for the circuit as it stands (2 to 24 microseconds); when a value of the circuit or of the diode changes while running they are dropped, and once the new constants have held for 256 samples they are built again, the series in one sample and then one cell per sample. Until then between the two table drives, there as well for c beyond 1e5, at every drive for c beyond 1e7 and beyond ln c + A + c = 2^20, a tabulated omega estimate takes correction steps on the exact equation, with one exponential and one division each: one Newton step while c <= 1e-4, one Halley step up to c = 10, repeated Halley steps beyond.

Accuracy: against a long double reference over drives of either sign from 1e-6 to 1e6 times (1 + c), the worst relative error is 3.6e-16 for c from 1e-9 to 1e5 (3.3e-16 beyond c = 0.04), and under reverse drive it stays within 3.5e-16 up to c = 1e9. The result does not depend on the previous sample.

Cost for an RC circuit at 48 kHz, measured on four machines (GCC, Clang and MSVC on x64, GCC on arm64) next to the closed form with a fast omega estimate (D'Angelo et al., DAFx-19), 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 26 ns per sample, 0.48 to 0.81 times the estimate's cost (whose error is -53 to -153 dB); behind 1 M to 10 M ohm (c from 0.05 to 0.5) 17 to 27 ns, 0.49 to 0.87 times the estimate (-43 to -80 dB).

Memory: 6.2 KB per instance, most of it the cells.

Definition at line 2270 of file WDF.h.

Constructor & Destructor Documentation

◆ DiodeRoot()

template<FloatType T, typename Tree >
dspark::wdf::DiodeRoot< T, Tree >::DiodeRoot ( Tree &  tree,
T  saturationCurrent = T(2.52e-9),
T  idealityTimesVt = T(1.752 * 0.02585) 
)
inlineexplicitnoexcept

Definition at line 2273 of file WDF.h.

Member Function Documentation

◆ getVoltage()

template<FloatType T, typename Tree >
T dspark::wdf::DiodeRoot< T, Tree >::getVoltage ( ) const
inlinenoexcept

Voltage across the diode.

Definition at line 2350 of file WDF.h.

◆ prepare()

template<FloatType T, typename Tree >
void dspark::wdf::DiodeRoot< T, Tree >::prepare ( double  sampleRate)
inlinenoexcept

Definition at line 2281 of file WDF.h.

◆ process()

template<FloatType T, typename Tree >
void dspark::wdf::DiodeRoot< T, Tree >::process ( )
inlinenoexcept

Definition at line 2296 of file WDF.h.

◆ reset()

template<FloatType T, typename Tree >
void dspark::wdf::DiodeRoot< T, Tree >::reset ( )
inlinenoexcept

Definition at line 2294 of file WDF.h.

◆ setIdealityTimesVt()

template<FloatType T, typename Tree >
void dspark::wdf::DiodeRoot< T, Tree >::setIdealityTimesVt ( T  volts)
inlinenoexcept

Definition at line 2279 of file WDF.h.

◆ setSaturationCurrent()

template<FloatType T, typename Tree >
void dspark::wdf::DiodeRoot< T, Tree >::setSaturationCurrent ( T  amps)
inlinenoexcept

Definition at line 2278 of file WDF.h.


The documentation for this class was generated from the following file: