| 1 | # `biquad` |
| 2 | |
| 3 | [](https://www.travis-ci.org/korken89/biquad-rs) |
| 4 | |
| 5 | `biquad` is a `#![no_std]` library for creating first and second order IIR |
| 6 | filters for signal processing based on |
| 7 | [Biquads](https://en.wikipedia.org/wiki/Digital_biquad_filter). Both a |
| 8 | Direct Form 1 (DF1) and Direct Form 2 Transposed (DF2T) implementation is |
| 9 | available, where the DF1 is better used when the filter needs retuning |
| 10 | online, as it has the property to introduce minimal artifacts under retuning, |
| 11 | while the DF2T is best used for static filters as it has the least |
| 12 | computational complexity and best numerical stability. |
| 13 | |
| 14 | This crate implements the biquads for `f32` and `f64`. |
| 15 | |
| 16 | ## Example |
| 17 | |
| 18 | ```rust |
| 19 | fn main() { |
| 20 | use biquad::*; |
| 21 | |
| 22 | // Cutoff and sampling frequencies |
| 23 | let f0 = 10.hz(); |
| 24 | let fs = 1.khz(); |
| 25 | |
| 26 | // Create coefficients for the biquads |
| 27 | let coeffs = Coefficients::<f32>::from_params(Type::LowPass, fs, f0, Q_BUTTERWORTH_F32).unwrap(); |
| 28 | |
| 29 | // Create two different biquads |
| 30 | let mut biquad1 = DirectForm1::<f32>::new(coeffs); |
| 31 | let mut biquad2 = DirectForm2Transposed::<f32>::new(coeffs); |
| 32 | |
| 33 | let input_vec = vec![0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]; |
| 34 | let mut output_vec1 = Vec::new(); |
| 35 | let mut output_vec2 = Vec::new(); |
| 36 | |
| 37 | // Run for all the inputs |
| 38 | for elem in input_vec { |
| 39 | output_vec1.push(biquad1.run(elem)); |
| 40 | output_vec2.push(biquad2.run(elem)); |
| 41 | } |
| 42 | } |
| 43 | ``` |
| 44 | |
| 45 | # [Documentation](https://docs.rs/biquad) |
| 46 | |
| 47 | # License |
| 48 | |
| 49 | Licensed under either of |
| 50 | |
| 51 | - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or |
| 52 | http://www.apache.org/licenses/LICENSE-2.0) |
| 53 | |
| 54 | - MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 55 | |
| 56 | at your option. |
| 57 | |
| 58 | ## Contribution |
| 59 | |
| 60 | Unless you explicitly state otherwise, any contribution intentionally submitted |
| 61 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 62 | dual licensed as above, without any additional terms or conditions. |