Skip to content
Snippets Groups Projects
Commit 6911c1eb authored by Stephen D's avatar Stephen D
Browse files

add mag_squared

parent da3f2c1c
No related branches found
No related tags found
No related merge requests found
Pipeline #245 passed
[package] [package]
edition = "2021" edition = "2021"
name = "goertzel-nostd" name = "goertzel-nostd"
version = "0.1.0" version = "0.2.0"
authors = ["Stephen D"] authors = ["Stephen D"]
repository = "https://github.com/mcpherrinm/goertzel.git" repository = "https://github.com/mcpherrinm/goertzel.git"
keywords = ["dsp", "goertzel", "fft", "fourier"] keywords = ["dsp", "goertzel", "fft", "fourier"]
......
...@@ -49,6 +49,10 @@ impl Parameters { ...@@ -49,6 +49,10 @@ impl Parameters {
pub fn mag(self, samples: &[f32]) -> f32 { pub fn mag(self, samples: &[f32]) -> f32 {
self.start().add_samples(samples).finish_mag() 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 { impl Partial {
...@@ -69,8 +73,12 @@ impl Partial { ...@@ -69,8 +73,12 @@ impl Partial {
} }
pub fn finish_mag(self) -> f32 { pub fn finish_mag(self) -> f32 {
libm::sqrtf(self.finish_mag_squared())
}
pub fn finish_mag_squared(self) -> f32 {
let (real, imag) = self.finish(); let (real, imag) = self.finish();
libm::sqrtf(real * real + imag * imag) real * real + imag * imag
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment