numpy.fft
fft(a[, n, axis, norm])
fft
Compute the one-dimensional discrete Fourier Transform.
ifft(a[, n, axis, norm])
ifft
Compute the one-dimensional inverse discrete Fourier Transform.
fft2(a[, s, axes, norm])
fft2
Compute the 2-dimensional discrete Fourier Transform
ifft2(a[, s, axes, norm])
ifft2
Compute the 2-dimensional inverse discrete Fourier Transform.
fftn(a[, s, axes, norm])
fftn
Compute the N-dimensional discrete Fourier Transform.
ifftn(a[, s, axes, norm])
ifftn
Compute the N-dimensional inverse discrete Fourier Transform.
rfft(a[, n, axis, norm])
rfft
Compute the one-dimensional discrete Fourier Transform for real input.
irfft(a[, n, axis, norm])
irfft
Compute the inverse of the n-point DFT for real input.
rfft2(a[, s, axes, norm])
rfft2
Compute the 2-dimensional FFT of a real array.
irfft2(a[, s, axes, norm])
irfft2
Compute the 2-dimensional inverse FFT of a real array.
rfftn(a[, s, axes, norm])
rfftn
Compute the N-dimensional discrete Fourier Transform for real input.
irfftn(a[, s, axes, norm])
irfftn
Compute the inverse of the N-dimensional FFT of real input.
hfft(a[, n, axis, norm])
hfft
Compute the FFT of a signal that has Hermitian symmetry, i.e., a real spectrum.
ihfft(a[, n, axis, norm])
ihfft
Compute the inverse FFT of a signal that has Hermitian symmetry.
fftfreq(n[, d])
fftfreq
Return the Discrete Fourier Transform sample frequencies.
rfftfreq(n[, d])
rfftfreq
Return the Discrete Fourier Transform sample frequencies (for usage with rfft, irfft).
fftshift(x[, axes])
fftshift
Shift the zero-frequency component to the center of the spectrum.
ifftshift(x[, axes])
ifftshift
The inverse of fftshift.
Fourier analysis is fundamentally a method for expressing a function as a sum of periodic components, and for recovering the function from those components. When both the function and its Fourier transform are replaced with discretized counterparts, it is called the discrete Fourier transform (DFT). The DFT has become a mainstay of numerical computing in part because of a very fast algorithm for computing it, called the Fast Fourier Transform (FFT), which was known to Gauss (1805) and was brought to light in its current form by Cooley and Tukey [CT]. Press et al. [NR] provide an accessible introduction to Fourier analysis and its applications.
Because the discrete Fourier transform separates its input into components that contribute at discrete frequencies, it has a great number of applications in digital signal processing, e.g., for filtering, and in this context the discretized input to the transform is customarily referred to as a signal, which exists in the time domain. The output is called a spectrum or transform and exists in the frequency domain.
There are many ways to define the DFT, varying in the sign of the exponent, normalization, etc. In this implementation, the DFT is defined as
System Message: WARNING/2 (A_k = \sum_{m=0}^{n-1} a_m \exp\left\{-2\pi i{mk \over n}\right\} \qquad k = 0,\ldots,n-1. )
latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2017-04-15> Babel <3.18> and hyphenation patterns for 3 language(s) loaded. (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty (/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def (/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu) (/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu) (/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu))) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) ! LaTeX Error: File `anyfontsize.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: ! Emergency stop. <read *> l.8 \usepackage {bm}^^M No pages of output. Transcript written on math.log.
The DFT is in general defined for complex inputs and outputs, and a single-frequency component at linear frequency
System Message: WARNING/2 (f)
System Message: WARNING/2 (a_m = \exp\{2\pi i\,f m\Delta t\})
System Message: WARNING/2 (\Delta t)
The values in the result follow so-called “standard” order: If A = fft(a, n), then A[0] contains the zero-frequency term (the sum of the signal), which is always purely real for real inputs. Then A[1:n/2] contains the positive-frequency terms, and A[n/2+1:] contains the negative-frequency terms, in order of decreasingly negative frequency. For an even number of input points, A[n/2] represents both positive and negative Nyquist frequency, and is also purely real for real input. For an odd number of input points, A[(n-1)/2] contains the largest positive frequency, while A[(n+1)/2] contains the largest negative frequency. The routine np.fft.fftfreq(n) returns an array giving the frequencies of corresponding elements in the output. The routine np.fft.fftshift(A) shifts transforms and their frequencies to put the zero-frequency components in the middle, and np.fft.ifftshift(A) undoes that shift.
A = fft(a, n)
A[0]
A[1:n/2]
A[n/2+1:]
A[n/2]
A[(n-1)/2]
A[(n+1)/2]
np.fft.fftfreq(n)
np.fft.fftshift(A)
np.fft.ifftshift(A)
When the input a is a time-domain signal and A = fft(a), np.abs(A) is its amplitude spectrum and np.abs(A)**2 is its power spectrum. The phase spectrum is obtained by np.angle(A).
A = fft(a)
np.abs(A)
np.abs(A)**2
np.angle(A)
The inverse DFT is defined as
System Message: WARNING/2 (a_m = \frac{1}{n}\sum_{k=0}^{n-1}A_k\exp\left\{2\pi i{mk\over n}\right\} \qquad m = 0,\ldots,n-1. )
It differs from the forward transform by the sign of the exponential argument and the default normalization by
System Message: WARNING/2 (1/n)
numpy.fft promotes float32 and complex64 arrays to float64 and complex128 arrays respectively. For an FFT implementation that does not promote input arrays, see scipy.fftpack.
float32
complex64
float64
complex128
The default normalization has the direct transforms unscaled and the inverse transforms are scaled by
norm
"ortho"
System Message: WARNING/2 (1/\sqrt{n})
When the input is purely real, its transform is Hermitian, i.e., the component at frequency
System Message: WARNING/2 (f_k)
System Message: WARNING/2 (-f_k)
n
n/2+1
Correspondingly, when the spectrum is purely real, the signal is Hermitian. The hfft family of functions exploits this symmetry by using n/2+1 complex points in the input (time) domain for n real points in the frequency domain.
In higher dimensions, FFTs are used, e.g., for image analysis and filtering. The computational efficiency of the FFT means that it can also be a faster way to compute large convolutions, using the property that a convolution in the time domain is equivalent to a point-by-point multiplication in the frequency domain.
In two dimensions, the DFT is defined as
System Message: WARNING/2 (A_{kl} = \sum_{m=0}^{M-1} \sum_{n=0}^{N-1} a_{mn}\exp\left\{-2\pi i \left({mk\over M}+{nl\over N}\right)\right\} \qquad k = 0, \ldots, M-1;\quad l = 0, \ldots, N-1, )
which extends in the obvious way to higher dimensions, and the inverses in higher dimensions also extend in the same way.
Cooley, James W., and John W. Tukey, 1965, “An algorithm for the machine calculation of complex Fourier series,” Math. Comput. 19: 297-301.
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.