begin cleaning ffts

This commit is contained in:
2025-09-24 19:24:40 +02:00
parent bd7ae2b19e
commit 3cc4144747
11 changed files with 152 additions and 99 deletions

View File

@ -5,8 +5,6 @@ use crate::fft::{DFT, FFTDirection};
use std::f32::consts::PI;
pub struct Radix2FFT {
output_buffer: Box<[Complex32]>,
input_buffer: Box<[Complex32]>,
direction: FFTDirection,
size: usize,
length: usize,
@ -20,19 +18,17 @@ impl DFT for Radix2FFT {
}
Radix2FFT {
output_buffer: vec![Complex32::zero(); size].into_boxed_slice(),
input_buffer: vec![Complex32::zero(); size].into_boxed_slice(),
size: size.ilog2() as usize,
direction,
length: size,
}
}
fn execute(&mut self, window: fn(f32) -> f32) {
fn execute(&mut self, input: &[Complex32], output: &mut [Complex32], window: fn(f32) -> f32) {
// Reorder samples
for (i, x) in self.output_buffer.iter_mut().enumerate() {
for (i, x) in output.iter_mut().enumerate() {
let k = reverse_bits(i, self.size as u32);
*x = self.input_buffer[k] * window(k as f32 / self.size as f32);
*x = input[k] * window(k as f32 / self.size as f32);
}
for step in 1..(self.size + 1) {
@ -41,24 +37,16 @@ impl DFT for Radix2FFT {
for s in (0..(self.length / pol_length)).map(|i| i * pol_length) {
for i in 0..mid_point {
// Compute current polynomial at each unit root
let a = self.output_buffer[s + i];
let b = self.output_buffer[s + i + mid_point];
let a = output[s + i];
let b = output[s + i + mid_point];
let angle = -2. * self.direction.sign() * PI * (i as f32) / (pol_length as f32);
let phasor = Complex32::cexp(angle);
self.output_buffer[i + s] = a + phasor * b;
self.output_buffer[i + s + mid_point] = a - phasor * b;
output[i + s] = a + phasor * b;
output[i + s + mid_point] = a - phasor * b;
}
}
}
}
fn get_input(&mut self) -> &mut [Complex32] {
&mut self.input_buffer
}
fn get_output(&self) -> &[Complex32] {
&self.output_buffer
}
}
// Utilities