Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between numpy.fft and scipy.fftpack?

Is the later just a synonym of the former, or are they two different implementations of FFT? Which one is better?

like image 567
Charles Brunet Avatar asked Jun 15 '11 19:06

Charles Brunet


People also ask

Is SciPy FFT better than Numpy?

fft vs numpy. fft. SciPy's fast Fourier transform (FFT) implementation contains more features and is more likely to get bug fixes than NumPy's implementation. If given a choice, you should use the SciPy implementation.

What is SciPy Fftpack?

SciPy offers the fftpack module, which lets the user compute fast Fourier transforms. Following is an example of a sine function, which will be used to calculate Fourier transform using the fftpack module.

What does SciPy FFT return?

fftpack. fft. Return discrete Fourier transform of real or complex sequence.

What is FFT Numpy?

This function computes the one-dimensional n-point discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm [CT]. Parameters aarray_like. Input array, can be complex. nint, optional. Length of the transformed axis of the output.


2 Answers

SciPy does more:

  • http://docs.scipy.org/doc/numpy/reference/routines.fft.html
  • http://docs.scipy.org/doc/scipy/reference/fftpack.html#

In addition, SciPy exports some of the NumPy features through its own interface, for example if you execute scipy.fftpack.helper.fftfreq and numpy.fft.helper.fftfreq you're actually running the same code.

However, SciPy has its own implementations of much functionality. The source has performance benchmarks that compare the original NumPy and new SciPy versions. My archaic laptop shows something like this:

                 Fast Fourier Transform =================================================       |    real input     |   complex input     -------------------------------------------------  size |  scipy  |  numpy  |  scipy  |  numpy  -------------------------------------------------   100 |    0.07 |    0.06 |    0.06 |    0.07  (secs for 7000 calls)  1000 |    0.06 |    0.09 |    0.09 |    0.09  (secs for 2000 calls)   256 |    0.11 |    0.11 |    0.12 |    0.11  (secs for 10000 calls)   512 |    0.16 |    0.21 |    0.20 |    0.21  (secs for 10000 calls)  1024 |    0.03 |    0.04 |    0.04 |    0.04  (secs for 1000 calls)  2048 |    0.05 |    0.09 |    0.08 |    0.08  (secs for 1000 calls)  4096 |    0.05 |    0.08 |    0.07 |    0.09  (secs for 500 calls)  8192 |    0.10 |    0.20 |    0.19 |    0.21  (secs for 500 calls) 

It does seem that SciPy runs significantly faster as the array increases in size, though these are just contrived examples and it would be worth experimenting with both for your particular project.

It's worth checking out the source code http://www.scipy.org/Download#head-312ad78cdf85a9ca6fa17a266752069d23f785d1 . Yes those .f files really are Fortran! :-D

like image 55
jond3k Avatar answered Oct 12 '22 13:10

jond3k


I found that numpy's 2D fft was significantly faster than scipy's, but FFTW was faster than both (using the PyFFTW bindings). Performance tests are here: code.google.com/p/agpy/source/browse/trunk/tests/test_ffts.py

And the results (for n x n arrays):

           n                sp               np             fftw            8:         0.010189         0.005077         0.028378           16:         0.010795         0.008069         0.028716           32:         0.014351         0.008566         0.031076           64:         0.028796         0.019308         0.036931          128:         0.093085         0.074986         0.088365          256:         0.459137         0.317680         0.170934          512:         2.652487         1.811646         0.571402         1024:        10.722885         7.796856         3.509452 
like image 21
keflavich Avatar answered Oct 12 '22 12:10

keflavich