What is the fastest FFT implementation in Python?
It seems numpy.fft and scipy.fftpack both are based on fftpack, and not FFTW. Is fftpack as fast as FFTW? What about using multithreaded FFT, or using distributed (MPI) FFT?
Use the FFT function to calculate the Fourier transform of the above signal. Plot the amplitude spectrum for both the two-sided and one-side frequencies. TRY IT! Generate a simple signal for length 2048, and time how long it will run the FFT and compare the speed with the DFT.
Unlike many of the array operations in numpy , the fft operation is not threaded for execution across multiple processors.
You could certainly wrap whatever FFT implementation that you wanted to test using Cython or other like-minded tools that allow you to access external libraries.
If you're going to test FFT implementations, you might also take a look at GPU-based codes (if you have access to the proper hardware). There are several: reikna.fft, scikits.cuda.
There's also a CPU based python FFTW wrapper pyFFTW.
(There is pyFFTW3 as well, but it is not so actively maintained as pyFFTW, and it does not work with Python3. (source))
I don't have experience with any of these. It's probably going to fall to you to do some digging around and benchmark different codes for your particular application if speed is important to you.
For a test detailed at https://gist.github.com/fnielsen/99b981b9da34ae3d5035 I find that scipy.fftpack performs fine compared to my simple application of pyfftw via pyfftw.interfaces.scipy_fftpack
, except for data with a length corresponding to a prime number.
There seems to be some setup cost associated with evoking pyfftw.interfaces.scipy_fftpack.fft the first time. The second time it is faster. Numpy's and scipy's fftpack with a prime number performs terribly for the size of data I tried. CZT is faster in that case. Some months ago an issue was put up at Scipy's Github about the problem, see https://github.com/scipy/scipy/issues/4288
20000 prime=False padded_fft : 0.003116 numpy_fft : 0.003502 scipy_fft : 0.001538 czt : 0.035041 fftw_fft : 0.004007 ------------------------------------------------------------ 20011 prime=True padded_fft : 0.001070 numpy_fft : 1.263672 scipy_fft : 0.875641 czt : 0.033139 fftw_fft : 0.009980 ------------------------------------------------------------ 21803 prime=True padded_fft : 0.001076 numpy_fft : 1.510341 scipy_fft : 1.043572 czt : 0.035129 fftw_fft : 0.011463 ------------------------------------------------------------ 21804 prime=False padded_fft : 0.001108 numpy_fft : 0.004672 scipy_fft : 0.001620 czt : 0.033854 fftw_fft : 0.005075 ------------------------------------------------------------ 21997 prime=True padded_fft : 0.000940 numpy_fft : 1.534876 scipy_fft : 1.058001 czt : 0.034321 fftw_fft : 0.012839 ------------------------------------------------------------ 32768 prime=False padded_fft : 0.001222 numpy_fft : 0.002410 scipy_fft : 0.000925 czt : 0.039275 fftw_fft : 0.005714 ------------------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With