diff --git a/dsp/src/complex.rs b/dsp/src/complex.rs index 2bdb9ea..bb928e0 100644 --- a/dsp/src/complex.rs +++ b/dsp/src/complex.rs @@ -1,7 +1,6 @@ use super::{atan2, cossin}; -use serde::{Deserialize, Serialize}; -#[derive(Copy, Clone, Default, PartialEq, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Default, PartialEq, Debug)] pub struct Complex(pub T, pub T); impl Complex { @@ -17,7 +16,8 @@ impl Complex { /// ``` #[inline(always)] pub fn from_angle(angle: i32) -> Complex { - cossin(angle) + let (c, s) = cossin(angle); + Complex(c, s) } /// Return the absolute square (the squared magnitude). diff --git a/dsp/src/cossin.rs b/dsp/src/cossin.rs index f9cc42e..e5746a3 100644 --- a/dsp/src/cossin.rs +++ b/dsp/src/cossin.rs @@ -1,4 +1,3 @@ -use super::Complex; use core::f64::consts::PI; include!(concat!(env!("OUT_DIR"), "/cossin_table.rs")); @@ -11,10 +10,10 @@ include!(concat!(env!("OUT_DIR"), "/cossin_table.rs")); /// * `phase` - 32-bit phase. /// /// # Returns -/// The cos and sin values of the provided phase as a `Complex` -/// value. With a 7-bit deep LUT there is 1e-5 max and 6e-8 RMS error +/// The cos and sin values of the provided phase as a `(i32, i32)` +/// tuple. With a 7-bit deep LUT there is 1e-5 max and 6e-8 RMS error /// in each quadrature over 20 bit phase. -pub fn cossin(phase: i32) -> Complex { +pub fn cossin(phase: i32) -> (i32, i32) { // Phase bits excluding the three highes MSB const OCTANT_BITS: usize = 32 - 3; @@ -69,12 +68,13 @@ pub fn cossin(phase: i32) -> Complex { sin *= -1; } - Complex(cos, sin) + (cos, sin) } #[cfg(test)] mod tests { use super::*; + use crate::Complex; use core::f64::consts::PI; #[test]