lockin: use single iir instance for both in-phase and quadrature signals

This commit is contained in:
Matt Huszagh 2020-11-28 14:21:48 -08:00
parent 785c98f93d
commit fcdfcb0be7
1 changed files with 5 additions and 7 deletions

View File

@ -102,7 +102,7 @@ pub struct Lockin {
sample_period: u32, sample_period: u32,
harmonic: u32, harmonic: u32,
timestamps: [Option<i32>; 2], timestamps: [Option<i32>; 2],
iir: [IIR; 2], iir: IIR,
iirstate: [IIRState; 2], iirstate: [IIRState; 2],
} }
@ -118,9 +118,7 @@ impl Lockin {
/// * `harmonic` - Integer scaling factor used to adjust the /// * `harmonic` - Integer scaling factor used to adjust the
/// demodulation frequency. E.g., 2 would demodulate with the /// demodulation frequency. E.g., 2 would demodulate with the
/// first harmonic. /// first harmonic.
/// * `iir` - IIR biquad filter. Two identical copies of this IIR /// * `iir` - IIR biquad filter.
/// filter are used: one for the in-phase signal and the other for
/// the quadrature signal.
/// ///
/// # Returns /// # Returns
/// ///
@ -136,7 +134,7 @@ impl Lockin {
sample_period: sample_period, sample_period: sample_period,
harmonic: harmonic, harmonic: harmonic,
timestamps: [None, None], timestamps: [None, None],
iir: [iir, iir], iir: iir,
iirstate: [[0.; 5]; 2], iirstate: [[0.; 5]; 2],
} }
} }
@ -236,8 +234,8 @@ impl Lockin {
.iter_mut() .iter_mut()
.zip(quadrature.iter_mut()) .zip(quadrature.iter_mut())
.for_each(|(i, q)| { .for_each(|(i, q)| {
*i = self.iir[0].update(&mut self.iirstate[0], *i); *i = self.iir.update(&mut self.iirstate[0], *i);
*q = self.iir[1].update(&mut self.iirstate[1], *q); *q = self.iir.update(&mut self.iirstate[1], *q);
}); });
} }
} }