Skip to content

Commit

Permalink
move config docs to config
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jul 20, 2023
1 parent 7af3762 commit 2dd513c
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/lowpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ use crate::Filter;
///
/// The filter will cleanly saturate towards the `i32` range.
///
/// The filter configuration `Config` contains its gains.
///
/// For the first-order lowpass this the corner frequency in scaled Q31:
/// `k = pi*(1 << 31)*f0/fn` where
/// `f0` is the 3dB corner frequency and
/// `fn` is the Nyquist frequency.
/// The corner frequency is warped in the usual way.
///
/// For the second-order lowpass this is `[k**2/(1 << 32), -k/q]` with `q = 1/sqrt(2)`
/// for a Butterworth response.
/// In addition to the poles at the corner frequency The filters have zeros at Nyquist.
///
/// The first-order lowpass works fine and accurate for any positive gain
/// `1 <= k <= (1 << 31) - 1`.
/// The second-order lowpass works and is accurate for
/// `1 << 16 <= k <= q*(1 << 31)`.
///
/// Both filters have been optimized for accuracy, dynamic range, and
/// speed on Cortex-M7.
#[derive(Copy, Clone)]
pub struct Lowpass<const N: usize>(pub(crate) [i64; N]);
impl<const N: usize> Filter for Lowpass<N> {
/// The filter configuration `Config` contains the filter gains.
///
/// For the first-order lowpass this is a single element array `[k]` with
/// the corner frequency in scaled Q31:
/// `k = pi*(1 << 31)*f0/fn` where
/// `f0` is the 3dB corner frequency and
/// `fn` is the Nyquist frequency.
/// The corner frequency is warped in the usual way.
///
/// For the second-order lowpass this is `[k**2/(1 << 32), -k/q]` with `q = 1/sqrt(2)`
/// for a Butterworth response.
///
/// In addition to the poles at the corner frequency the filters have zeros at Nyquist.
///
/// The first-order lowpass works fine and accurate for any positive gain
/// `1 <= k <= (1 << 31) - 1`.
/// The second-order lowpass works and is accurate for
/// `1 << 16 <= k <= q*(1 << 31)`.
type Config = [i32; N];
fn update(&mut self, x: i32, k: &Self::Config) -> i32 {
let mut d = x.saturating_sub((self.0[0] >> 32) as i32) as i64 * k[0] as i64;
Expand Down

0 comments on commit 2dd513c

Please sign in to comment.