Skip to main content

RTypeAdaptor

Struct RTypeAdaptor 

pub struct RTypeAdaptor {
    pub num_ports: usize,
    pub port_resistance: f64,
    /* private fields */
}
Expand description

R-type adaptor for arbitrary N-port topologies in WDF.

Handles non-series/parallel circuit topologies that cannot be decomposed into binary adaptor trees. Examples include:

  • 3-winding transformers
  • Bridged-T and twin-T networks
  • Bassman/Marshall tone stacks
  • Op-amp feedback networks

The scattering matrix S is computed at compile time from the circuit’s MNA (Modified Nodal Analysis) system using element stamps.

Reference: Werner, Smith, Abel (2015) “Wave Digital Filter Adaptors for Arbitrary Topologies and Multiport Linear Elements”

Scattering equation: b = S · a

One port (typically the last) is adapted to be reflection-free (S_nn = 0).

Fields§

§num_ports: usize

Number of ports (children + 1 for parent)

§port_resistance: f64

Port resistance seen from parent (adapted port)

Implementations§

§

impl RTypeAdaptor

pub fn new( scattering_matrix: Vec<f64>, port_resistances: &[f64], ) -> RTypeAdaptor

Create an R-type adaptor from a pre-computed scattering matrix.

  • scattering_matrix — NxN matrix in row-major order
  • port_resistances — resistance for each port (last is adapted)

The last port is the “parent” port facing the root, and should be adapted (S[n-1][n-1] ≈ 0).

pub fn three_winding_transformer( n12: f64, n13: f64, r_sec1: f64, r_sec2: f64, ) -> RTypeAdaptor

Create an R-type adaptor for an ideal 3-winding transformer.

  • n12 — turns ratio primary:secondary₁ (e.g., 4.0 for 4:1)
  • n13 — turns ratio primary:secondary₂ (e.g., 9.5 for 9.5:1)
  • r_sec1 — port resistance of secondary₁ subtree
  • r_sec2 — port resistance of secondary₂ subtree

The primary (port 3) is adapted (reflection-free).

pub fn from_mna( num_ports: usize, mna_system: MnaSystem, port_resistances: &[f64], ) -> RTypeAdaptor

Create from MNA element stamps (general method).

This implements the Werner DAFx-15 algorithm for deriving scattering matrices from arbitrary linear circuits.

  • num_ports — number of WDF ports
  • mna_stamps — element stamps defining the internal circuit
  • port_resistances — resistance at each port

The last port is adapted to be reflection-free.

pub fn scatter_up(&mut self, b_children: &[f64]) -> f64

scatter_up: collect child reflected waves, produce parent reflected wave.

Children send b₁, b₂, …, b_{n-1}. We compute b_n (to parent). Uses power-normalized S̅ internally for bounded intermediate products.

pub fn scatter_up_gain(&self, child_gains: &[f64]) -> f64

Linear gain from child reflected-wave gains to the parent reflected wave. This mirrors scatter_up without mutating cached child waves.

pub fn scatter_down(&self, a_parent: f64) -> Vec<f64>

scatter_down: given parent incident wave, produce child incident waves.

Parent sends a_n. We compute a₁, a₂, …, a_{n-1} for children. Uses power-normalized S̅ internally for bounded intermediate products.

pub fn scatter_down_parent_gains(&self) -> Vec<f64>

Linear gains from parent incident wave to child incident waves. This is the a_parent part of scatter_down; cached child waves are constants.

pub fn scatter_all(&self, b_all: &[f64]) -> Vec<f64>

Perform full N×N scatter: a = S · b_all using power-normalized waves.

Equivalent to standard scattering but uses S̅ (power-normalized) internally. Since S̅ entries are bounded [-1,1] for passive networks, intermediate products cannot overflow even with extreme port resistance ratios (e.g., 0.1Ω cap vs 10kΩ NL port).

pub fn scatter_all_into(&self, b_all: &[f64], a_out: &mut [f64])

Like scatter_all, but writes into a pre-allocated output buffer to avoid per-sample heap allocation.

pub fn set_child_waves(&mut self, b_children: &[f64])

Manually set the cached child reflected waves.

After a multi-NL NR solve determines the correct b values for all ports, call this to update the cached state so that a subsequent scatter_down produces correct incident waves for passive children.

pub fn reset(&mut self)

Reset state.

pub fn power_scattering(&self) -> &[f64]

Return the power-normalized scattering matrix S̅ (row-major).

S̅[i][j] = S[i][j] · √(R_j / R_i). For passive networks all entries are bounded [-1, 1].

pub fn num_ports(&self) -> usize

Number of ports (children + 1 adapted parent port).

pub fn port_resistances(&self) -> Vec<f64>

Port resistances in port order (last entry is the adapted parent port).

Reconstructed from √R_i values stored internally as R_i = (√R_i)².

pub fn scattering_matrix(&self) -> Vec<f64>

Reconstruct the standard (non-power-normalized) scattering matrix S[i][j] (row-major, num_ports × num_ports).

Inverse of the power normalization applied in RTypeAdaptor::new: S̅[i][j] = S[i][j]·√(R_j/R_i) ⇒ S[i][j] = S̅[i][j]·√(R_i/R_j) = power_scattering[i][j]·sqrt_r[i]·inv_sqrt_r[j].

This is the same matrix MultiNlScattering::from_full_matrix slices, so the port ordering is [NL, passive, (vcc?), adapted] with the adapted port last. Used by the stiff-cap fold to retain the passive rows that the NL-only sub-blocks discard.

Trait Implementations§

§

impl Clone for RTypeAdaptor

§

fn clone(&self) -> RTypeAdaptor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for RTypeAdaptor

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more