But it might have an effect on the precision of the final results.
$ g++ -o fft FFT.cpp FFT.h && ./fft
k=1; len=2;
fft_forward(1..len):
in: 1+0im, 2+0im,
out: 3+0im, -1+0im,
fft_inverse(fft_forward(1..len))
in: 3+0im, -1+0im,
out: 2+0im, 4+0im,
fft_inverse(1..len):
in: 1+0im, 2+0im,
out: 3+0im, -1+0im,
k=2; len=4;
fft_forward(1..len):
in: 1+0im, 2+0im, 3+0im, 4+0im,
out: 10+0im, -2+0im, -2+-2im, -2+2im,
fft_inverse(fft_forward(1..len))
in: 10+0im, -2+0im, -2+-2im, -2+2im,
out: 4+0im, 8+-2.288e-17im, 12+0im, 16+2.288e-17im,
fft_inverse(1..len):
in: 1+0im, 2+0im, 3+0im, 4+0im,
out: 10+0im, -1+1im, -4+0im, -1+-1im,
k=3; len=8;
fft_forward(1..len):
in: 1+0im, 2+0im, 3+0im, 4+0im, 5+0im, 6+0im, 7+0im, 8+0im,
out: 36+0im, -4+0im, -4+-4im, -4+4im, -4+-9.657im, -4+1.657im, -4+-1.657im, -4+9.657im,
fft_inverse(fft_forward(1..len))
in: 36+0im, -4+0im, -4+-4im, -4+4im, -4+-9.657im, -4+1.657im, -4+-1.657im, -4+9.657im,
out: 8+0im, 16+-1.822e-15im, 24+7.966e-16im, 32+-1.731e-15im, 40+0im, 48+1.731e-15im, 56+-7.966e-16im, 64+1.822e-15im,
fft_inverse(1..len):
in: 1+0im, 2+0im, 3+0im, 4+0im, 5+0im, 6+0im, 7+0im, 8+0im,
out: 36+0im, -1+2.414im, -4+4im, -1+0.4142im, -16+0im, -1+-0.4142im, -4+-4im, -1+-2.414im,
>> bitrevorder((1:2))
ans =
1 2
>> bitrevorder((1:4))
ans =
1 3 2 4
>> bitrevorder((1:8))
ans =
1 5 3 7 2 6 4 8
The output of
fft_forwardandfft_inverseseems inconsistent with other reference implementations.I'm not sure if this is a bug.
But it might have an effect on the precision of the final results.
CPP test code
Details
Add those code to the end of https://github.com/Mysticial/Mini-Pi/blob/master/decomposed/src/FFT.cpp
Compile and Run:
g++ -o fft FFT.cpp FFT.h && ./fftTest code output:
issues
fft_inverse(fft_forward(1..len)) != 1..lenSimply take the
out * 1/lento get the correct result.This may be due to the lack of the necessary
1/nfactor in ifft (fft_inverse).fft_inverse(1..2) != [1.5 + 0.0im, -0.5 + 0.0im]Same as
1.fft_forwardgive correct answer only when len=2The output of
fft_forwardis in bit-reversed order.But the positions of the first and last elements of the array should remain unchanged.
So the result is still wrong.
bitrevorderposition map