numpy.fft)¶fft(a[, n, axis, norm]) | Compute the one-dimensional discrete Fourier Transform. |
ifft(a[, n, axis, norm]) | Compute the one-dimensional inverse discrete Fourier Transform. |
fft2(a[, s, axes, norm]) | Compute the 2-dimensional discrete Fourier Transform |
ifft2(a[, s, axes, norm]) | Compute the 2-dimensional inverse discrete Fourier Transform. |
fftn(a[, s, axes, norm]) | Compute the N-dimensional discrete Fourier Transform. |
ifftn(a[, s, axes, norm]) | Compute the N-dimensional inverse discrete Fourier Transform. |
rfft(a[, n, axis, norm]) | Compute the one-dimensional discrete Fourier Transform for real input. |
irfft(a[, n, axis, norm]) | Compute the inverse of the n-point DFT for real input. |
rfft2(a[, s, axes, norm]) | Compute the 2-dimensional FFT of a real array. |
irfft2(a[, s, axes, norm]) | Compute the 2-dimensional inverse FFT of a real array. |
rfftn(a[, s, axes, norm]) | Compute the N-dimensional discrete Fourier Transform for real input. |
irfftn(a[, s, axes, norm]) | Compute the inverse of the N-dimensional FFT of real input. |
hfft(a[, n, axis, norm]) | Compute the FFT of a signal that has Hermitian symmetry, i.e., a real spectrum. |
ihfft(a[, n, axis, norm]) | Compute the inverse FFT of a signal that has Hermitian symmetry. |
fftfreq(n[, d]) | Return the Discrete Fourier Transform sample frequencies. |
rfftfreq(n[, d]) | Return the Discrete Fourier Transform sample frequencies (for usage with rfft, irfft). |
fftshift(x[, axes]) | Shift the zero-frequency component to the center of the spectrum. |
ifftshift(x[, axes]) | The inverse offftshift. |
Fourier analysis is fundamentally a method for expressing a function as asum of periodic components, and for recovering the function from thosecomponents. When both the function and its Fourier transform arereplaced with discretized counterparts, it is called the discrete Fouriertransform (DFT). The DFT has become a mainstay of numerical computing inpart because of a very fast algorithm for computing it, called the FastFourier Transform (FFT), which was known to Gauss (1805) and was broughtto light in its current form by Cooley and Tukey[CT]. Press et al.[NR]provide an accessible introduction to Fourier analysis and itsapplications.
Because the discrete Fourier transform separates its input intocomponents that contribute at discrete frequencies, it has a great numberof applications in digital signal processing, e.g., for filtering, and inthis context the discretized input to the transform is customarilyreferred to as asignal, which exists in thetime domain. The outputis called aspectrum ortransform and exists in thefrequencydomain.
There are many ways to define the DFT, varying in the sign of theexponent, normalization, etc. In this implementation, the DFT is definedas

The DFT is in general defined for complex inputs and outputs, and asingle-frequency component at linear frequency
isrepresented by a complex exponential
, where
is the sampling interval.
The values in the result follow so-called “standard” order: IfA=fft(a,n), thenA[0] contains the zero-frequency term (the sum ofthe signal), which is always purely real for real inputs. ThenA[1:n/2]contains the positive-frequency terms, andA[n/2+1:] contains thenegative-frequency terms, in order of decreasingly negative frequency.For an even number of input points,A[n/2] represents both positive andnegative Nyquist frequency, and is also purely real for real input. Foran odd number of input points,A[(n-1)/2] contains the largest positivefrequency, whileA[(n+1)/2] contains the largest negative frequency.The routinenp.fft.fftfreq(n) returns an array giving the frequenciesof corresponding elements in the output. The routinenp.fft.fftshift(A) shifts transforms and their frequencies to put thezero-frequency components in the middle, andnp.fft.ifftshift(A) undoesthat shift.
When the inputa is a time-domain signal andA=fft(a),np.abs(A)is its amplitude spectrum andnp.abs(A)**2 is its power spectrum.The phase spectrum is obtained bynp.angle(A).
The inverse DFT is defined as

It differs from the forward transform by the sign of the exponentialargument and the default normalization by
.
The default normalization has the direct transforms unscaled and the inversetransforms are scaled by
. It is possible to obtain unitarytransforms by setting the keyword argumentnorm to"ortho" (default isNone) so that both direct and inverse transforms will be scaled by
.
When the input is purely real, its transform is Hermitian, i.e., thecomponent at frequency
is the complex conjugate of thecomponent at frequency
, which means that for realinputs there is no information in the negative frequency components thatis not already available from the positive frequency components.The family ofrfft functions isdesigned to operate on real inputs, and exploits this symmetry bycomputing only the positive frequency components, up to and including theNyquist frequency. Thus,n input points producen/2+1 complexoutput points. The inverses of this family assumes the same symmetry ofits input, and for an output ofn points usesn/2+1 input points.
Correspondingly, when the spectrum is purely real, the signal isHermitian. Thehfft family of functions exploits this symmetry byusingn/2+1 complex points in the input (time) domain forn realpoints in the frequency domain.
In higher dimensions, FFTs are used, e.g., for image analysis andfiltering. The computational efficiency of the FFT means that it canalso be a faster way to compute large convolutions, using the propertythat a convolution in the time domain is equivalent to a point-by-pointmultiplication in the frequency domain.
In two dimensions, the DFT is defined as

which extends in the obvious way to higher dimensions, and the inversesin higher dimensions also extend in the same way.
| [CT] | Cooley, James W., and John W. Tukey, 1965, “An algorithm for themachine calculation of complex Fourier series,”Math. Comput.19: 297-301. |
| [NR] | Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,2007,Numerical Recipes: The Art of Scientific Computing, ch.12-13. Cambridge Univ. Press, Cambridge, UK. |
For examples, see the various functions.