From 67f052c0c97d62a4eb43e08a0a136274798a4a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 12 Feb 2021 11:05:50 +0100 Subject: [PATCH] lockin: add rounding bias --- dsp/src/lockin.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dsp/src/lockin.rs b/dsp/src/lockin.rs index 843a793..100a845 100644 --- a/dsp/src/lockin.rs +++ b/dsp/src/lockin.rs @@ -16,6 +16,7 @@ impl Lockin { } /// Update the lockin with a sample taken at a given phase. + /// The lowpass has a gain of `1 << k`. pub fn update(&mut self, sample: i16, phase: i32, k: u8) -> Complex { // Get the LO signal for demodulation. let lo = Complex::from_angle(phase); @@ -23,8 +24,10 @@ impl Lockin { // Mix with the LO signal, filter with the IIR lowpass, // return IQ (in-phase and quadrature) data. Complex( - self.state[0].update((sample as i32 * (lo.0 >> 16)) >> 16, k), - self.state[1].update((sample as i32 * (lo.1 >> 16)) >> 16, k), + self.state[0] + .update((sample as i32 * (lo.0 >> 16) + (1 << 15)) >> 16, k), + self.state[1] + .update((sample as i32 * (lo.1 >> 16) + (1 << 15)) >> 16, k), ) } }