Expand description
§biquad
biquad
is a library for creating second order IIR filters for signal processing based on
Biquads. Both a
Direct Form 1 (DF1) and Direct Form 2 Transposed (DF2T) implementation is
available, where the DF1 is better used when the filter needs retuning
online, as it has the property to introduce minimal artifacts under retuning,
while the DF2T is best used for static filters as it has the least
computational complexity and best numerical stability.
§Examples
fn main() {
use biquad::*;
// Cutoff and sampling frequencies
let f0 = 10.hz();
let fs = 1.khz();
// Create coefficients for the biquads
let coeffs = Coefficients::<f32>::from_params(Type::LowPass, fs, f0, Q_BUTTERWORTH_F32).unwrap();
// Create two different biquads
let mut biquad1 = DirectForm1::<f32>::new(coeffs);
let mut biquad2 = DirectForm2Transposed::<f32>::new(coeffs);
let input_vec = vec![0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
let mut output_vec1 = Vec::new();
let mut output_vec2 = Vec::new();
// Run for all the inputs
for elem in input_vec {
output_vec1.push(biquad1.run(elem));
output_vec2.push(biquad2.run(elem));
}
}
§Errors
Coefficients::from_params(...)
can error if the cutoff frequency does not adhere to the
Nyquist Frequency, or if the Q value is
negative.
Hertz::from_hz(...)
and Hertz::from_dt(...)
will error if the frequency is negative.
§Panics
x.hz()
, x.khz()
, x.mhz()
, x.dt()
will panic for f32
/f64
if they are negative.
Re-exports§
pub use crate::coefficients::*;
pub use crate::frequency::*;
Modules§
- coefficients
- coefficients
- frequency
- frequency
Structs§
- Direct
Form1 - Internal states and coefficients of the Direct Form 1 form
- Direct
Form2 Transposed - Internal states and coefficients of the Direct Form 2 Transposed form
Enums§
- Errors
- Possible errors
Traits§
- Biquad
- The required functions of a biquad implementation