From dcc71d5d11ab93acf9dad1ce8a3ed79d738dc295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 2 Feb 2021 15:41:47 +0100 Subject: [PATCH] iir: tweak math a bit --- dsp/src/iir_int.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dsp/src/iir_int.rs b/dsp/src/iir_int.rs index 93626de..daff43c 100644 --- a/dsp/src/iir_int.rs +++ b/dsp/src/iir_int.rs @@ -22,8 +22,9 @@ impl Vec5 { pub fn lowpass(f: f32, q: f32, k: f32) -> Self { // 3rd order Taylor approximation of sin and cos. let f = f * 2. * PI; - let fsin = f - f * f * f / 6.; - let fcos = 1. - f * f / 2.; + let f2 = f * f * 0.5; + let fcos = 1. - f2; + let fsin = f * (1. - f2 / 3.); let alpha = fsin / (2. * q); // IIR uses Q2.30 fixed point let a0 = (1. + alpha) / (1 << IIR::SHIFT) as f32;