Still not working
This commit is contained in:
@ -26,14 +26,19 @@ impl DFT for MixedRadixFFT {
|
||||
fn create(size: usize) -> Self {
|
||||
let q = decide_radix_factor(size);
|
||||
let p = size / q;
|
||||
// TODO: Figure out why it does not work in the other direction ...
|
||||
let (p, q) = (q, p);
|
||||
let qfft = create_fft(q);
|
||||
let pfft = create_fft(p);
|
||||
|
||||
//let qfft = Box::new(NaiveDFT::create(q));
|
||||
//let pfft = Box::new(NaiveDFT::create(p));
|
||||
|
||||
MixedRadixFFT {
|
||||
input_buffer: vec![Complex32::zero(); size].into_boxed_slice(),
|
||||
output_buffer: vec![Complex32::zero(); size].into_boxed_slice(),
|
||||
size,
|
||||
twiddle_factors: compute_twiddle_factors(q, p),
|
||||
twiddle_factors: compute_twiddle_factors(size),
|
||||
qfft,
|
||||
pfft,
|
||||
|
||||
@ -55,8 +60,8 @@ impl DFT for MixedRadixFFT {
|
||||
|
||||
for j0 in 0..self.q {
|
||||
// "Store j0'th of k0'th fft into staging buffer"
|
||||
self.staging_buffer[k0 * self.q + j0] =
|
||||
self.qfft.get_output()[j0] * self.twiddle_factors[k0 * self.q + j0];
|
||||
self.staging_buffer[j0 * self.p + k0] =
|
||||
self.qfft.get_output()[j0] * self.twiddle_factors[j0 * k0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +69,7 @@ impl DFT for MixedRadixFFT {
|
||||
for j0 in 0..self.q {
|
||||
// Copy input
|
||||
for k0 in 0..self.p {
|
||||
self.pfft.get_input()[k0] = self.staging_buffer[k0 * self.q + j0];
|
||||
self.pfft.get_input()[k0] = self.staging_buffer[j0 * self.p + k0];
|
||||
}
|
||||
|
||||
self.pfft.execute();
|
||||
@ -84,14 +89,11 @@ impl DFT for MixedRadixFFT {
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_twiddle_factors(q: usize, p: usize) -> Box<[Complex32]> {
|
||||
let mut factors = vec![Complex32::zero(); q * p].into_boxed_slice();
|
||||
let n = p * q;
|
||||
fn compute_twiddle_factors(size: usize) -> Box<[Complex32]> {
|
||||
let mut factors = vec![Complex32::zero(); size].into_boxed_slice();
|
||||
|
||||
for i in 0..q {
|
||||
for j in 0..p {
|
||||
factors[i * p + j] = Complex32::cexp(2. * PI / (n as f32));
|
||||
}
|
||||
for i in 0..size {
|
||||
factors[i] = Complex32::cexp(2. * PI * i as f32 / (size as f32));
|
||||
}
|
||||
factors
|
||||
}
|
||||
@ -99,6 +101,7 @@ fn compute_twiddle_factors(q: usize, p: usize) -> Box<[Complex32]> {
|
||||
// This will decide on a good factor to use for the mixed radix fft
|
||||
fn decide_radix_factor(n: usize) -> usize {
|
||||
let factors = prime_factors(n);
|
||||
//factors.iter().for_each(|a| print!(" {a} "));
|
||||
let two_count = factors.iter().take_while(|i| **i == 2).count();
|
||||
|
||||
// If there is a lot of two, we can use them as q factor to be able to use radix2 later on
|
||||
@ -107,5 +110,5 @@ fn decide_radix_factor(n: usize) -> usize {
|
||||
}
|
||||
|
||||
// Otherwise take next big prime
|
||||
return *factors.iter().skip(two_count).next().unwrap();
|
||||
*factors.get(two_count).unwrap()
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ pub struct RaderFFT {
|
||||
output_buffer: Box<[Complex32]>,
|
||||
|
||||
size: usize,
|
||||
g: usize,
|
||||
|
||||
// Fourrier transform of the exponential terms
|
||||
convolution_operand: Box<[Complex32]>,
|
||||
@ -33,10 +32,9 @@ impl DFT for RaderFFT {
|
||||
output_buffer: vec![Complex32::zero(); size].into_boxed_slice(),
|
||||
|
||||
size,
|
||||
g,
|
||||
|
||||
convolution_operand: compute_convolution_operand(size, &permutation),
|
||||
convolution_fft: Box::new(NaiveDFT::create(size - 1)),
|
||||
convolution_fft: create_fft(size - 1),
|
||||
permutation,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user