Reputation: 942
Essentially, CPP_FFTW(N, signal, backwards) = NP_IFFT(N, signal) * N
where CPP_FFTW
is the (float version of the) FFTW library in C++, and NP_IFFT
is numpy.fft.ifft
from Python.
The problem here is CPP_FFTW(N, CPP_FFTW(N, signal, forwards), backwards)
is equal to N * signal
, not signal
as one might expect.
I can divide by N
but my issue is that my N
is very big, so I'm losing floating-point precision. It's basically breaking my program; I have near-identical complex coefficients in the C++ and Python applications. However, I'm losing all of my precision because I'm essentially using (c*N)/N
after performing the backwards transform.
Is it possible to stop this multiplication from happening?
Up until IFFT
, the coefficients are near-identical. This is following IFFT:
Upvotes: 2
Views: 1218
Reputation: 60761
As you can see in the documentation, FFTW computes an unnormalized transform. That is, an additional division by the length of the signal is necessary to recover the input signal after a forward and an inverse transform: IFFT(FFT(signal))/N = signal
.
The Python NumPy FFT is normalized, it includes the division by N
in the inverse transform.
Do note that this additional division will not change your relative precision, as all values in the signal are divided by exactly the same number.
Additional information:
Some libraries (such as FFTW) compute the unnormalized FFT, skipping the division by N
in the inverse transform, for speed, since sometimes it might not be necessary. Other libraries define a different normalization altogether, for example they might do the division by N
in the forward transform instead of the inverse, or they might divide by the square root of N
in both forward and backward transforms.
Upvotes: 3