DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
WDF.h File Reference

Wave Digital Filters: physical circuit modelling building blocks. More...

#include "DspMath.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <tuple>
#include <utility>
Include dependency graph for WDF.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::wdf::Resistor< T >
 Ideal resistor. Absorbs its incident wave (b = 0). More...
 
class  dspark::wdf::Capacitor< T >
 Capacitor, bilinear discretization: b[n] = a[n-1], Rp = 1/(2 fs C). More...
 
class  dspark::wdf::Inductor< T >
 Inductor, bilinear discretization: b[n] = -a[n-1], Rp = 2 fs L. More...
 
class  dspark::wdf::ResistiveVoltageSource< T >
 Voltage source with series resistance (Thévenin leaf): b = Vs. More...
 
class  dspark::wdf::Series< T, Child1, Child2 >
 Adapted three-port series connector. More...
 
class  dspark::wdf::Parallel< T, Child1, Child2 >
 Adapted three-port parallel connector. More...
 
class  dspark::wdf::Inverter< T, Child >
 Two-port polarity inverter (flips the connected subtree's polarity). More...
 
class  dspark::wdf::IdealVoltageSourceRoot< T, Tree >
 Ideal voltage source closing a linear tree: b = 2 Vs - a. More...
 
class  dspark::wdf::DiodePairRoot< T, Tree >
 Antiparallel diode pair root (the classic clipper nonlinearity). More...
 
class  dspark::wdf::DiodeRoot< T, Tree >
 Single Shockley diode root: i(v) = Is (e^{v/(n Vt)} - 1). More...
 
class  dspark::wdf::RType< T, Children >
 N-port R-type adaptor for non-series/parallel interconnections. More...
 
class  dspark::wdf::ToneStackFMV< T >
 Exact Fender '59 Bassman treble/bass/middle tone stack. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 
namespace  dspark::wdf
 
namespace  dspark::wdf::detail
 

Detailed Description

Wave Digital Filters: physical circuit modelling building blocks.

Implements the classical WDF toolkit (Fettweis 1986): one-port elements (resistor, capacitor, inductor, resistive voltage source), adapted three-port series/parallel connectors, a polarity inverter, and circuit roots – an ideal voltage source for linear networks and Newton-Raphson nonlinear roots (Shockley diode, antiparallel diode pair).

Wave convention: voltage waves with a = v + R*i (incident) and b = v - R*i (reflected), so v = (a+b)/2 and i = (a-b)/(2R). Reactances use the bilinear (trapezoidal) discretization: a WDF network is therefore sample-exact against the bilinear transform of its analog transfer function, which is how this header is verified (RC and RLC against the analytic discrete response; diode clippers against a high-precision trapezoidal reference solve of the circuit ODE – the same integration SPICE .tran uses).

Trees are composed statically from references – no virtual dispatch, all scattering inlines. Per sample: call root.process() after updating source voltages, then read element voltages/currents.

// Diode clipper: Vin --[Rs]--+--> out across antiparallel pair
// |
// [C] (parallel)
using namespace dspark::wdf;
Capacitor<float> c { 10e-9f };
Parallel<float, decltype(vs), decltype(c)> tree { vs, c };
DiodePairRoot<float, decltype(tree)> clipper { tree }; // 1N4148-ish
clipper.prepare(48000.0);
// per sample:
vs.setVoltage(in);
clipper.process();
out = clipper.getVoltage();
Capacitor, bilinear discretization: b[n] = a[n-1], Rp = 1/(2 fs C).
Definition WDF.h:114
Antiparallel diode pair root (the classic clipper nonlinearity).
Definition WDF.h:437
Adapted three-port parallel connector.
Definition WDF.h:278
void prepare(double sampleRate) noexcept
Definition WDF.h:282
Voltage source with series resistance (Thévenin leaf): b = Vs.
Definition WDF.h:179

Beyond series/parallel trees, the header provides an R-type adaptor (after K. Werner's thesis): an N-port connector for arbitrary – non series/parallel – topologies. Its scattering matrix is derived numerically from the interconnection network via Modified Nodal Analysis: each port is replaced by its instantaneous Thévenin equivalent (source a_i, resistance R_i), the linear node system is solved once per topology/parameter change, and S = 2M - I where M maps incident waves to port voltages. The up-facing port is adapted to the Thévenin resistance seen looking into the network, so R-types nest under any root. ToneStackFMV builds on it: the exact Fender '59 Bassman treble/bass/middle network (topology and verification transfer function after Yeh & Smith, DAFx-06).

Scope note: nonlinear roots cover one-port nonlinearities; multi-port nonlinear roots (triode inside the WDF tree) remain future work.

Dependencies: DspMath.h.

Definition in file WDF.h.