Skip to content

Commit

Permalink
refactor for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Sep 28, 2023
1 parent baa740d commit 9f3ad77
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/psd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,23 @@ impl<const N: usize> PsdStage for Psd<N> {
// convert positive frequency spectrum to power
// and accumulate
// TODO: accuracy for large counts
for (c, p) in c[..N / 2 + 1]
.iter()
.zip(self.spectrum[..N / 2 + 1].iter_mut())
{
let ci = c.norm_sqr();
*p += if self.count == 0 {
ci
} else if let Some(avg) = self.avg {
avg * (ci - *p)
} else {
ci
};
match self.avg {
Some(avg) if self.count != 0 => {
for (c, p) in c[..N / 2 + 1]
.iter_mut()
.zip(self.spectrum[..N / 2 + 1].iter_mut())
{
*p += avg * (c.norm_sqr() - *p);
}
}
_ => {
for (c, p) in c[..N / 2 + 1]
.iter_mut()
.zip(self.spectrum[..N / 2 + 1].iter_mut())
{
*p += c.norm_sqr();
}
}
}

let start = if self.count == 0 {
Expand Down

0 comments on commit 9f3ad77

Please sign in to comment.