Skip to main content

low_pass_zero_phase

Function low_pass_zero_phase 

Source
pub fn low_pass_zero_phase(
    samples: &[f64],
    rate: SampleRate,
    cutoff: Hz,
) -> Result<Vec<f64>, FilterError>
Expand description

Low-passes a signal forward and then backward with a fourth-order Butterworth, so the result has no delay: an attack stays where it is. For attack envelopes use ATTACK_LOW_PASS_HZ.

The two passes square the magnitude response, so the gain at cutoff is -6 dB, not -3 dB, and the slope is 48 dB per octave. As filtfilt does, each end is extended by an odd reflection, 2 x[0] - x[k], of three cutoff periods, and each pass starts in the steady state of its first input. A constant or a ramp then passes without a start-up or an end transient, so a release at the end of a stem keeps its level.

ยงErrors

Returns a FilterError when the cutoff is zero or not below the Nyquist frequency.