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

A whole filter of order N as one normalized ladder (Gray and Markel), designed from its polynomials, without roots. More...

#include <NormalizedLadder.h>

Classes

struct  Coeffs
 The ladder's rotations and taps. More...
 

Public Member Functions

bool setCoeffs (const double *b, const double *a) noexcept
 Takes a filter b(z) / a(z) at once; false (nothing changes) if it is not stable.
 
bool rampCoeffs (const double *b, const double *a, int samples) noexcept
 Moves every rotation and tap linearly to a filter's over samples; false if it is not stable.
 
Coeffs getLadder () const noexcept
 
bool isRamping () const noexcept
 
void reset () noexcept
 Clears the memory of every channel.
 
double getStateEnergy (int channel) const noexcept
 The energy of a channel's memory (the sum of the squares of its states).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Runs a block, in place; a ramp moves on by its samples. Channels beyond MaxChannels are left untouched.
 
double processSample (double input, int channel) noexcept
 One sample of one channel, in double, with the coefficients as they are (a ramp moves on with advanceRamp()).
 
void advanceRamp (int samples) noexcept
 Moves a ramp on by a number of samples (for processSample() callers).
 

Static Public Member Functions

static bool design (const double *b, const double *a, Coeffs &out) noexcept
 The ladder of a digital filter b(z) / a(z), each Order + 1 coefficients from z^0 (a[0] scales both).
 

Detailed Description

template<typename T, int Order, int MaxChannels = 8>
class dspark::NormalizedLadderN< T, Order, MaxChannels >

A whole filter of order N as one normalized ladder (Gray and Markel), designed from its polynomials, without roots.

The denominator 1 + a1 z^-1 + ... + aN z^-N is stepped down to its reflection coefficients: k_m is the last coefficient of the polynomial of order m, and the polynomial of order m - 1 is (A_m - k_m B_m) / (1 - k_m^2), where B_m is A_m reversed (z^-m A_m(1/z)). Each k_m is a plane rotation (s = k_m, c = sqrt(1 - k_m^2)); the input enters at the top and runs down through the rotations:

f_N = u
f_(m-1) = c_m f_m - s_m x_m g_m = s_m f_m + c_m x_m (m = N .. 1)
y = v_0 f_0 + v_1 g_1 + ... + v_N g_N
x_1 <- f_0, x_m <- g_(m-1)

The signal g_m is (c_(m+1) ... c_N) B_m / A, so the taps of a numerator come down from the top: v_m is what is left of it at z^-m over the product of the c above m, and v_m times that product times B_m comes off what is left. The filter is stable when every |k_m| < 1, which the design checks.

As the second-order NormalizedLadder, the step from the input and the memory to the memory and g_N is orthogonal, so with no input the memory can only lose energy whatever the coefficients do: a filter of order five whose knob moves at audio rate keeps bounded. A ramp moves every c, s and v linearly; the pairs (c, s) stay on or inside the unit circle on the way. FilterDesign::bilinearPolynomial() takes an analog network of any order (its numerator and denominator as polynomials in s) to the digital polynomials this class takes, so a network from components needs no factoring.

Threading: owner-managed, like NormalizedLadder.

Template Parameters
TSample type of the buffers (float or double); the recursion and its memory are double either way.
OrderOrder of the filter, 1 to 16.
MaxChannelsLargest number of channels.

Definition at line 361 of file NormalizedLadder.h.

Member Function Documentation

◆ advanceRamp()

template<typename T , int Order, int MaxChannels = 8>
void dspark::NormalizedLadderN< T, Order, MaxChannels >::advanceRamp ( int  samples)
inlinenoexcept

Moves a ramp on by a number of samples (for processSample() callers).

Definition at line 527 of file NormalizedLadder.h.

◆ design()

template<typename T , int Order, int MaxChannels = 8>
static bool dspark::NormalizedLadderN< T, Order, MaxChannels >::design ( const double *  b,
const double *  a,
Coeffs &  out 
)
inlinestaticnoexcept

The ladder of a digital filter b(z) / a(z), each Order + 1 coefficients from z^0 (a[0] scales both).

Returns
False, and out untouched, when the denominator is not stable (a reflection coefficient of 1 or more) or a[0] is 0.

Definition at line 380 of file NormalizedLadder.h.

◆ getLadder()

template<typename T , int Order, int MaxChannels = 8>
Coeffs dspark::NormalizedLadderN< T, Order, MaxChannels >::getLadder ( ) const
inlinenoexcept

Definition at line 458 of file NormalizedLadder.h.

◆ getStateEnergy()

template<typename T , int Order, int MaxChannels = 8>
double dspark::NormalizedLadderN< T, Order, MaxChannels >::getStateEnergy ( int  channel) const
inlinenoexcept

The energy of a channel's memory (the sum of the squares of its states).

Definition at line 468 of file NormalizedLadder.h.

◆ isRamping()

template<typename T , int Order, int MaxChannels = 8>
bool dspark::NormalizedLadderN< T, Order, MaxChannels >::isRamping ( ) const
inlinenoexcept

Definition at line 459 of file NormalizedLadder.h.

◆ processBlock()

template<typename T , int Order, int MaxChannels = 8>
void dspark::NormalizedLadderN< T, Order, MaxChannels >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Runs a block, in place; a ramp moves on by its samples. Channels beyond MaxChannels are left untouched.

Definition at line 477 of file NormalizedLadder.h.

◆ processSample()

template<typename T , int Order, int MaxChannels = 8>
double dspark::NormalizedLadderN< T, Order, MaxChannels >::processSample ( double  input,
int  channel 
)
inlinenoexcept

One sample of one channel, in double, with the coefficients as they are (a ramp moves on with advanceRamp()).

Precondition
channel in [0, MaxChannels).

Definition at line 520 of file NormalizedLadder.h.

◆ rampCoeffs()

template<typename T , int Order, int MaxChannels = 8>
bool dspark::NormalizedLadderN< T, Order, MaxChannels >::rampCoeffs ( const double *  b,
const double *  a,
int  samples 
)
inlinenoexcept

Moves every rotation and tap linearly to a filter's over samples; false if it is not stable.

Definition at line 435 of file NormalizedLadder.h.

◆ reset()

template<typename T , int Order, int MaxChannels = 8>
void dspark::NormalizedLadderN< T, Order, MaxChannels >::reset ( )
inlinenoexcept

Clears the memory of every channel.

Definition at line 462 of file NormalizedLadder.h.

◆ setCoeffs()

template<typename T , int Order, int MaxChannels = 8>
bool dspark::NormalizedLadderN< T, Order, MaxChannels >::setCoeffs ( const double *  b,
const double *  a 
)
inlinenoexcept

Takes a filter b(z) / a(z) at once; false (nothing changes) if it is not stable.

Definition at line 425 of file NormalizedLadder.h.


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