From 728e5d8395d74e72be86b5fad75acaa6fb219bc7 Mon Sep 17 00:00:00 2001 From: ozpv <39195175+ozpv@users.noreply.github.com> Date: Sat, 16 May 2026 22:42:51 -0500 Subject: account for latency --- src/retain.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/retain.rs') diff --git a/src/retain.rs b/src/retain.rs index bc3934a..49730e1 100644 --- a/src/retain.rs +++ b/src/retain.rs @@ -1,10 +1,17 @@ -use hashbrown::HashSet; use num_complex::Complex; +use rustc_hash::FxHashSet; #[inline(always)] pub fn retain_top_n_magnitudes(fft_real_signal: &mut [Complex], n: usize) { // you'd be keeping the entire signal + // or keeping nothing at all if n >= fft_real_signal.len() { + return; + } else if n == 0 { + for phasor in fft_real_signal { + *phasor = Complex::ZERO; + } + return; } @@ -20,11 +27,11 @@ pub fn retain_top_n_magnitudes(fft_real_signal: &mut [Complex], n: usize) { let top_indices = indexed[target..] .iter() .map(|&(i, _)| i) - .collect::>(); + .collect::>(); - for (i, val) in fft_real_signal.iter_mut().enumerate() { + for (i, phasor) in fft_real_signal.iter_mut().enumerate() { if !top_indices.contains(&i) { - *val = Complex::ZERO; + *phasor = Complex::ZERO; } } } -- cgit v1.2.3