diff --git a/Cargo.toml b/Cargo.toml index 3facea89b9526de9e0b37b94fbae18406e31f9d8..0363e1545e1c267d7ed52ea95b3d5c15fbaa40d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "goertzel-nostd" -version = "0.1.0" +version = "0.2.0" authors = ["Stephen D"] repository = "https://github.com/mcpherrinm/goertzel.git" keywords = ["dsp", "goertzel", "fft", "fourier"] diff --git a/src/lib.rs b/src/lib.rs index 1c4486e5a9dbdc84a1f8292f049feacf99dbfa16..5a646a9dd589580e23dfec3c3bdbe5476b83a704 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,10 @@ impl Parameters { pub fn mag(self, samples: &[f32]) -> f32 { self.start().add_samples(samples).finish_mag() } + + pub fn mag_squared(self, samples: &[f32]) -> f32 { + self.start().add_samples(samples).finish_mag_squared() + } } impl Partial { @@ -69,8 +73,12 @@ impl Partial { } pub fn finish_mag(self) -> f32 { + libm::sqrtf(self.finish_mag_squared()) + } + + pub fn finish_mag_squared(self) -> f32 { let (real, imag) = self.finish(); - libm::sqrtf(real * real + imag * imag) + real * real + imag * imag } }