IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
16.2 FFT Python Interface


16.2 FFT Python Interface

The Python user imports the numarray.fft module, which provides a set of utility functions of the most commonly used FFT routines, and allows the specification of which axes (dimensions) of the input arrays are to be used for the FFT's. These routines are:

fft( a, n=None, axis=-1)
Performs a n-point discrete Fourier transform of the array a, n defaults to the size of a. It is most efficient for n a power of two. If n is larger than len(a), then a will be zero-padded to make up the difference. If n is smaller than len(a), then a will be aliased to reduce its size. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's.

The FFT is performed along the axis indicated by the axis argument, which defaults to be the last dimension of a.

The format of the returned array is a complex array of the same shape as a, where the first element in the result array contains the DC (steady-state) value of the FFT.

Some examples are:

>>> a = array([1., 0., 1., 0., 1., 0., 1., 0.]) + 10
>>> b = array([0., 1., 0., 1., 0., 1., 0., 1.]) + 10
>>> c = array([0., 1., 0., 0., 0., 1., 0., 0.]) + 10
>>> print numarray.fft.fft(a).real
[ 84.   0.   0.   0.   4.   0.   0.   0.]
>>> print numarray.fft.fft(b).real
[ 84.   0.   0.   0.  -4.   0.   0.   0.]
>>> print numarray.fft.fft(c).real
[ 82.   0.   0.   0.  -2.   0.   0.   0.]

inverse_fft( a, n=None, axis=-1)
Will return the n point inverse discrete Fourier transform of a; n defaults to the length of a. It is most efficient for n a power of two. If n is larger than a, then a will be zero-padded to make up the difference. If n is smaller than a, then a will be aliased to reduce its size. This also stores a cache of working memory for different sizes of FFT's, so you could theoretically run into memory problems if you call this too many times with too many different n's.

real_fft( a, n=None, axis=-1)
Will return the n point discrete Fourier transform of the real valued array a; n defaults to the length of a. It is most efficient for n a power of two. The returned array will be one half of the symmetric complex transform of the real array.

>>> x = cos(arange(30.0)/30.0*2*pi)
>>> print numarray.fft.real_fft(x)
[ -5.82867088e-16 +0.00000000e+00j   1.50000000e+01 -3.08862614e-15j
   7.13643755e-16 -1.04457106e-15j   1.13047653e-15 -3.23843935e-15j
  -1.52158521e-15 +1.14787259e-15j   3.60822483e-16 +3.60555504e-16j
   1.34237661e-15 +2.05127011e-15j   1.98981960e-16 -1.02472357e-15j
   1.55899290e-15 -9.94619821e-16j  -1.05417678e-15 -2.33364171e-17j
  -2.08166817e-16 +1.00955541e-15j  -1.34094426e-15 +8.88633386e-16j
   5.67513742e-16 -2.24823896e-15j   2.13735778e-15 -5.68448962e-16j
  -9.55398954e-16 +7.76890265e-16j  -1.05471187e-15 +0.00000000e+00j]

inverse_real_fft( a, n=None, axis=-1)
Will return the inverse FFT of the real valued array a.

fft2d( a, s=None, axes=(-2,-1))
Will return the 2-dimensional FFT of the array a. This is really just fft_nd() with different default behavior.

inverse_fft2d( a, s=None, axes=(-2,-1))
The inverse of fft2d(). This is really just inverse_fftnd() with different default behavior.

real_fft2d( a, s=None, axes=(-2,-1))
Will return the 2-D FFT of the real valued array a.

inverse_real_fft2d( a, s=None, axes=(-2,-1))
The inverse of real_fft2d(). This is really just inverse_real_fftnd() with different default behavior.

Send comments to the NumArray community.