Merge #390
390: lowpass: make it work for k=0 r=jordens a=jordens Co-authored-by: Robert Jördens <rj@quartiq.de>
This commit is contained in:
commit
c935f97752
|
@ -25,7 +25,6 @@ impl<const N: usize> Lowpass<N> {
|
||||||
/// Filtered output y.
|
/// Filtered output y.
|
||||||
pub fn update(&mut self, x: i32, k: u8) -> i32 {
|
pub fn update(&mut self, x: i32, k: u8) -> i32 {
|
||||||
debug_assert!(k & 31 == k);
|
debug_assert!(k & 31 == k);
|
||||||
debug_assert!((k - 1) & 31 == k - 1);
|
|
||||||
// This is an unrolled and optimized first-order IIR loop
|
// This is an unrolled and optimized first-order IIR loop
|
||||||
// that works for all possible time constants.
|
// that works for all possible time constants.
|
||||||
// Note T-DF-I and the zeros at Nyquist.
|
// Note T-DF-I and the zeros at Nyquist.
|
||||||
|
@ -35,6 +34,6 @@ impl<const N: usize> Lowpass<N> {
|
||||||
*y += dy;
|
*y += dy;
|
||||||
x = *y - (dy >> 1);
|
x = *y - (dy >> 1);
|
||||||
}
|
}
|
||||||
x.saturating_add((self.y.len() as i32) << (k - 1))
|
x.saturating_add((self.y.len() as i32) << (k - 1).max(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue