scipy.fftpack interface

This module implements those functions that replace aspects of the scipy.fftpack module. This module provides the entire documented namespace of scipy.fftpack, but those functions that are not included here are imported directly from scipy.fftpack.

The exceptions raised by each of these functions are mostly as per their equivalents in scipy.fftpack, though there are some corner cases in which this may not be true.

It is notable that unlike scipy.fftpack, these functions will generally return an output array with the same precision as the input array, and the transform that is chosen is chosen based on the precision of the input array. That is, if the input array is 32-bit floating point, then the transform will be 32-bit floating point and so will the returned array. Half precision input will be converted to single precision. Otherwise, if any type conversion is required, the default will be double precision.

Some corner (mis)usages of scipy.fftpack may not transfer neatly. For example, using scipy.fftpack.fft2() with a non 1D array and a 2D shape argument will return without exception whereas pyfftw.interfaces.scipy_fftpack.fft2() will raise a ValueError.

pyfftw.interfaces.scipy_fftpack.fft(x, n=None, axis=-1, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 1D FFT.

The first three arguments are as per scipy.fftpack.fft(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.ifft(x, n=None, axis=-1, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 1D inverse FFT.

The first three arguments are as per scipy.fftpack.ifft(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.fftn(x, shape=None, axes=None, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform an n-D FFT.

The first three arguments are as per scipy.fftpack.fftn(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.ifftn(x, shape=None, axes=None, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform an n-D inverse FFT.

The first three arguments are as per scipy.fftpack.ifftn(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.rfft(x, n=None, axis=-1, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 1D real FFT.

The first three arguments are as per scipy.fftpack.rfft(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.irfft(x, n=None, axis=-1, overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 1D real inverse FFT.

The first three arguments are as per scipy.fftpack.irfft(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.fft2(x, shape=None, axes=(-2, -1), overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 2D FFT.

The first three arguments are as per scipy.fftpack.fft2(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.ifft2(x, shape=None, axes=(-2, -1), overwrite_x=False, planner_effort='FFTW_ESTIMATE', threads=1, auto_align_input=True, auto_contiguous=True)

Perform a 2D inverse FFT.

The first three arguments are as per scipy.fftpack.ifft2(); the rest of the arguments are documented in the additional argument docs.

pyfftw.interfaces.scipy_fftpack.next_fast_len(target)

Find the next fast transform length for FFTW.

FFTW has efficient functions for transforms of length 2**a * 3**b * 5**c * 7**d * 11**e * 13**f, where e + f is either 0 or 1.

Parameters:target (int) – Length to start searching from. Must be a positive integer.
Returns:out – The first fast length greater than or equal to target.
Return type:int

Examples

On a particular machine, an FFT of prime length takes 2.1 ms:

>>> from pyfftw.interfaces import scipy_fftpack
>>> min_len = 10007  # prime length is worst case for speed
>>> a = numpy.random.randn(min_len)
>>> b = scipy_fftpack.fft(a)

Zero-padding to the next fast length reduces computation time to 406 us, a speedup of ~5 times:

>>> next_fast_len(min_len)
10080
>>> b = scipy_fftpack.fft(a, 10080)

Rounding up to the next power of 2 is not optimal, taking 598 us to compute, 1.5 times as long as the size selected by next_fast_len.

>>> b = fftpack.fft(a, 16384)

Similar speedups will occur for pre-planned FFTs as generated via pyfftw.builders.