|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Digital sections from analog ones, and the cascades of an equalizer. More...
#include <FilterDesign.h>
Classes | |
| class | Band |
| The frequencies a design is fitted over at one sample rate. More... | |
Static Public Member Functions | |
| static BiquadCoeffs | bilinear (const AnalogSection §ion, double sampleRate, double exactHz) noexcept |
| The bilinear transform of a section, with one frequency mapped exactly. | |
| static bool | bilinearPolynomial (const double *analogNum, const double *analogDen, int order, double sampleRate, double exactHz, double *digitalNum, double *digitalDen) noexcept |
| The bilinear transform of a whole analog network, polynomial to polynomial, with no factoring. | |
| static BiquadCoeffs | digital (const AnalogSection §ion, const Band &band) noexcept |
| The biquad whose magnitude follows an analog section up to Nyquist. | |
| static BiquadCoeffs | digital (const AnalogSection §ion, double sampleRate) noexcept |
| digital() for one design: builds the Band of the rate on the spot. | |
| static int | digital (const AnalogCascade &cascade, const Band &band, BiquadCoeffs *out, int capacity) noexcept |
| Every section of a cascade through digital(). | |
| static int | digital (const AnalogCascade &cascade, double sampleRate, BiquadCoeffs *out, int capacity) noexcept |
| Every section of a cascade through digital(), for one design. | |
| static double | magnitudeDb (const BiquadCoeffs *sections, int n, double hz, double sampleRate) noexcept |
| Magnitude in decibels of n digital sections in series at a frequency. | |
| static AnalogCascade | highCut (double hz, double slopeDbPerOctave, double q=kButterworthQ) noexcept |
| High cut (low-pass) of any slope from 0 to 96 dB per octave. | |
| static AnalogCascade | lowCut (double hz, double slopeDbPerOctave, double q=kButterworthQ) noexcept |
| Low cut (high-pass) of any slope from 0 to 96 dB per octave: highCut() mirrored about the corner. | |
| static AnalogCascade | lowShelf (double hz, double gainDb, double order, double q=kButterworthQ) noexcept |
| Low shelf of any order from 1, whole or not: gainDb below the corner, half of it (in decibels) at the corner, 6 dB per octave of transition per order. | |
| static AnalogCascade | highShelf (double hz, double gainDb, double order, double q=kButterworthQ) noexcept |
| High shelf of any order: lowShelf() mirrored about the corner. | |
| static AnalogCascade | bell (double hz, double q, double gainDb, double order) noexcept |
| Bell of any order: the higher the order, the flatter the top and the steeper the sides (6 dB per octave each per order). | |
| static AnalogCascade | bandPass (double hz, double q, double order) noexcept |
| Butterworth band-pass: 0 dB at the centre, -3 dB at the two edges hz / q apart, 6 dB per octave on each side per order. One biquad per order (a part of an order takes one more: between whole orders the band is that of highCut() at that slope, moved to the centre). | |
| static AnalogCascade | bandStop (double hz, double q, double order) noexcept |
| Butterworth band-stop: a null at the centre, -3 dB at the two edges hz / q apart, and a floor that widens with the order. One biquad per order (a part of an order takes one more). | |
| static AnalogCascade | allPass (double hz, double q, double order) noexcept |
| All-pass of any order: the magnitude stays at 1 and the phase turns 180 degrees per order around the frequency. | |
| static AnalogCascade | tilt (double pivotHz, double slopeDbPerOctave) noexcept |
| Tilt: the same slope across the whole band, 0 dB at the pivot. | |
| static double | tiltSlopeWithin (double pivotHz, double slopeDbPerOctave, double ceilingDb) noexcept |
| The slope a tilt can have at a pivot without lifting the end that rises (20 kHz for a positive slope, 20 Hz for a negative one) by more than a ceiling: the slope asked for, or the one that lands that end on the ceiling. The end that falls is not limited. | |
| static AnalogCascade | ellipticHighCut (double hz, int order=12, double rippleDb=0.05, double stopDb=100.0) noexcept |
| Elliptic high cut: flat to the corner within the ripple, then a wall down to the stop level. | |
| static AnalogCascade | ellipticLowCut (double hz, int order=12, double rippleDb=0.05, double stopDb=100.0) noexcept |
| Elliptic low cut: ellipticHighCut() mirrored about the corner. | |
| static double | ellipticStopRatio (int order=12, double rippleDb=0.05, double stopDb=100.0) noexcept |
| Where the stop band of an elliptic cut starts, as a ratio to its corner (above 1; the same for the high cut and, inverted, for the low cut). | |
Static Public Attributes | |
| static constexpr int | kFitSteps = 2 |
| Most joint steps a fit takes. | |
| static constexpr double | kButterworthQ = 0.7071067811865476 |
| The Q that leaves a cut maximally flat. | |
| static constexpr double | kMaxCutSlope = 96.0 |
| Steepest cut, in decibels per octave. | |
| static constexpr int | kMaxOrder = AnalogCascade::kMaxSections |
| Highest order of bells, shelves and band filters. | |
Digital sections from analog ones, and the cascades of an equalizer.
See the file notes for the method. The figures (worst case and mean distance to the analog magnitude, and the cost of a design) are in the changelog entry of this header and are asserted by its tests.
Definition at line 284 of file FilterDesign.h.
|
inlinestaticnoexcept |
All-pass of any order: the magnitude stays at 1 and the phase turns 180 degrees per order around the frequency.
The poles are those of the cut of the same order (q acts on the sharpest pair, from order 2 up). The order is any from 1, whole or not: the phase at the frequency moves 90 degrees per order all the way.
Definition at line 681 of file FilterDesign.h.
|
inlinestaticnoexcept |
Butterworth band-pass: 0 dB at the centre, -3 dB at the two edges hz / q apart, 6 dB per octave on each side per order. One biquad per order (a part of an order takes one more: between whole orders the band is that of highCut() at that slope, moved to the centre).
Definition at line 658 of file FilterDesign.h.
|
inlinestaticnoexcept |
Butterworth band-stop: a null at the centre, -3 dB at the two edges hz / q apart, and a floor that widens with the order. One biquad per order (a part of an order takes one more).
Definition at line 668 of file FilterDesign.h.
|
inlinestaticnoexcept |
Bell of any order: the higher the order, the flatter the top and the steeper the sides (6 dB per octave each per order).
Order 1 is AnalogSection::peak(). The gain is gainDb at the centre and half of it (in decibels) at the two edges hz / q apart, whatever the order, whole or not; a cut is the exact inverse of the boost. One biquad per order (a part of an order takes one more).
Definition at line 631 of file FilterDesign.h.
|
inlinestaticnoexcept |
The bilinear transform of a section, with one frequency mapped exactly.
| section | Analog section. |
| sampleRate | Sample rate in Hz. |
| exactHz | Frequency that keeps its place (from 0.49 of the rate up, none does and the plain transform is used). |
Definition at line 347 of file FilterDesign.h.
|
inlinestaticnoexcept |
The bilinear transform of a whole analog network, polynomial to polynomial, with no factoring.
H(s) = (n_0 + n_1 s + ... + n_N s^N) / (d_0 + d_1 s + ... + d_N s^N) becomes b(z) / a(z), of the same order: with s = K (1 - z^-1) / (1 + z^-1), each power s^j times (1 + z^-1)^N is K^j (1 - z^-1)^j (1 + z^-1)^(N - j), a fixed binomial row, so the digital coefficients are sums of the analog ones over those rows. The result is scaled so a[0] = 1; it feeds NormalizedLadderN directly.
| analogNum | N + 1 coefficients of the numerator, from s^0. |
| analogDen | N + 1 coefficients of the denominator, from s^0. |
| order | N, 1 to 16. |
| sampleRate | Sample rate in Hz. |
| exactHz | Frequency that keeps its place (from 0.49 of the rate up, or 0, none does and K = 2 fs). |
| digitalNum | Receives the N + 1 coefficients of b, from z^0. |
| digitalDen | Receives the N + 1 coefficients of a, from z^0. |
Definition at line 387 of file FilterDesign.h.
|
inlinestaticnoexcept |
Every section of a cascade through digital().
| cascade | Analog cascade. |
| band | The frequencies of the fit. |
| out | Receives the sections. |
| capacity | Room in out. |
Definition at line 523 of file FilterDesign.h.
|
inlinestaticnoexcept |
Every section of a cascade through digital(), for one design.
Definition at line 532 of file FilterDesign.h.
|
inlinestaticnoexcept |
The biquad whose magnitude follows an analog section up to Nyquist.
The section returned is minimum phase and has positive gain, whatever the sign and the phase of the prototype; an all-pass prototype gives an all-pass section with the poles of the prototype.
| section | Analog section with its poles in the left half plane. |
| band | The frequencies of the fit (it carries the sample rate). |
Definition at line 434 of file FilterDesign.h.
|
inlinestaticnoexcept |
digital() for one design: builds the Band of the rate on the spot.
Definition at line 509 of file FilterDesign.h.
|
inlinestaticnoexcept |
Elliptic high cut: flat to the corner within the ripple, then a wall down to the stop level.
With the defaults (order 12, 0.05 dB, 100 dB) the stop band starts a fifth of an octave above the corner.
| hz | End of the pass band. |
| order | 1 to 16. |
| rippleDb | Ripple of the pass band, 0.001 to 3 dB. |
| stopDb | Attenuation of the stop band, 20 to 140 dB. |
Definition at line 797 of file FilterDesign.h.
|
inlinestaticnoexcept |
Elliptic low cut: ellipticHighCut() mirrored about the corner.
Definition at line 807 of file FilterDesign.h.
|
inlinestaticnoexcept |
Where the stop band of an elliptic cut starts, as a ratio to its corner (above 1; the same for the high cut and, inverted, for the low cut).
Definition at line 821 of file FilterDesign.h.
|
inlinestaticnoexcept |
High cut (low-pass) of any slope from 0 to 96 dB per octave.
The slope is a real number. Every 6 dB per octave is one unit of order, and whole orders are Butterworth filters. Between them the poles sit on the same semicircle at the angles of a real order, and one section with a finite zero (a pair, or one real pole) keeps the corner at -3 dB and the cascade on the curve 1 / (1 + w^(2 order)) down to -36 dB. Under 6 dB per octave the filter is the fraction of a pole, (1 + s)^(-order), built from six real poles and zeros two octaves apart: it leaves 3 dB times the order at the corner and nothing at a slope of zero.
| hz | Corner frequency. |
| slopeDbPerOctave | Slope, 0 to 96 (0 gives an empty cascade). |
| q | Resonance of the sharpest pole pair, as the Q of a 12 dB per octave filter (0.7071 is Butterworth at every slope). It has no effect up to 6 dB per octave and comes in between 6 and 12. |
Definition at line 573 of file FilterDesign.h.
|
inlinestaticnoexcept |
High shelf of any order: lowShelf() mirrored about the corner.
Definition at line 614 of file FilterDesign.h.
|
inlinestaticnoexcept |
Low cut (high-pass) of any slope from 0 to 96 dB per octave: highCut() mirrored about the corner.
Definition at line 582 of file FilterDesign.h.
|
inlinestaticnoexcept |
Low shelf of any order from 1, whole or not: gainDb below the corner, half of it (in decibels) at the corner, 6 dB per octave of transition per order.
A Butterworth shelf (S. J. Orfanidis, "High-Order Digital Parametric Equalizer Design", J. Audio Eng. Soc., 2005): it never overshoots, and a cut is the exact inverse of the boost of the same size.
From order 2 up, q is the Q of the sharpest pair of poles and of zeros (0.7071: the Butterworth shelf). Above it the response rises over the plateau before the corner and dips after it; the plateau, the half gain at the corner and the inverse cut stay as they are.
Definition at line 605 of file FilterDesign.h.
|
inlinestaticnoexcept |
Magnitude in decibels of n digital sections in series at a frequency.
Definition at line 538 of file FilterDesign.h.
|
inlinestaticnoexcept |
Tilt: the same slope across the whole band, 0 dB at the pivot.
Eight real zeros and poles two octaves apart, from 2.5 Hz to 160 kHz, in four sections. The slope goes from -6 to +6 dB per octave (positive tilts towards the treble); at the two ends it is one zero and one pole.
| pivotHz | Frequency that keeps its level. |
| slopeDbPerOctave | Slope, -6 to +6 (0 gives an empty cascade). |
Definition at line 740 of file FilterDesign.h.
|
inlinestaticnoexcept |
The slope a tilt can have at a pivot without lifting the end that rises (20 kHz for a positive slope, 20 Hz for a negative one) by more than a ceiling: the slope asked for, or the one that lands that end on the ceiling. The end that falls is not limited.
| pivotHz | Frequency that keeps its level. |
| slopeDbPerOctave | Slope asked for, in dB per octave. |
| ceilingDb | Most the rising end may be lifted, in dB. |
Definition at line 776 of file FilterDesign.h.
|
staticconstexpr |
The Q that leaves a cut maximally flat.
Definition at line 550 of file FilterDesign.h.
|
staticconstexpr |
Most joint steps a fit takes.
Definition at line 287 of file FilterDesign.h.
|
staticconstexpr |
Steepest cut, in decibels per octave.
Definition at line 551 of file FilterDesign.h.
|
staticconstexpr |
Highest order of bells, shelves and band filters.
Definition at line 552 of file FilterDesign.h.