info.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. """
  2. Discrete Fourier Transform (:mod:`numpy.fft`)
  3. =============================================
  4. .. currentmodule:: numpy.fft
  5. Standard FFTs
  6. -------------
  7. .. autosummary::
  8. :toctree: generated/
  9. fft Discrete Fourier transform.
  10. ifft Inverse discrete Fourier transform.
  11. fft2 Discrete Fourier transform in two dimensions.
  12. ifft2 Inverse discrete Fourier transform in two dimensions.
  13. fftn Discrete Fourier transform in N-dimensions.
  14. ifftn Inverse discrete Fourier transform in N dimensions.
  15. Real FFTs
  16. ---------
  17. .. autosummary::
  18. :toctree: generated/
  19. rfft Real discrete Fourier transform.
  20. irfft Inverse real discrete Fourier transform.
  21. rfft2 Real discrete Fourier transform in two dimensions.
  22. irfft2 Inverse real discrete Fourier transform in two dimensions.
  23. rfftn Real discrete Fourier transform in N dimensions.
  24. irfftn Inverse real discrete Fourier transform in N dimensions.
  25. Hermitian FFTs
  26. --------------
  27. .. autosummary::
  28. :toctree: generated/
  29. hfft Hermitian discrete Fourier transform.
  30. ihfft Inverse Hermitian discrete Fourier transform.
  31. Helper routines
  32. ---------------
  33. .. autosummary::
  34. :toctree: generated/
  35. fftfreq Discrete Fourier Transform sample frequencies.
  36. rfftfreq DFT sample frequencies (for usage with rfft, irfft).
  37. fftshift Shift zero-frequency component to center of spectrum.
  38. ifftshift Inverse of fftshift.
  39. Background information
  40. ----------------------
  41. Fourier analysis is fundamentally a method for expressing a function as a
  42. sum of periodic components, and for recovering the function from those
  43. components. When both the function and its Fourier transform are
  44. replaced with discretized counterparts, it is called the discrete Fourier
  45. transform (DFT). The DFT has become a mainstay of numerical computing in
  46. part because of a very fast algorithm for computing it, called the Fast
  47. Fourier Transform (FFT), which was known to Gauss (1805) and was brought
  48. to light in its current form by Cooley and Tukey [CT]_. Press et al. [NR]_
  49. provide an accessible introduction to Fourier analysis and its
  50. applications.
  51. Because the discrete Fourier transform separates its input into
  52. components that contribute at discrete frequencies, it has a great number
  53. of applications in digital signal processing, e.g., for filtering, and in
  54. this context the discretized input to the transform is customarily
  55. referred to as a *signal*, which exists in the *time domain*. The output
  56. is called a *spectrum* or *transform* and exists in the *frequency
  57. domain*.
  58. Implementation details
  59. ----------------------
  60. There are many ways to define the DFT, varying in the sign of the
  61. exponent, normalization, etc. In this implementation, the DFT is defined
  62. as
  63. .. math::
  64. A_k = \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\}
  65. \\qquad k = 0,\\ldots,n-1.
  66. The DFT is in general defined for complex inputs and outputs, and a
  67. single-frequency component at linear frequency :math:`f` is
  68. represented by a complex exponential
  69. :math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t`
  70. is the sampling interval.
  71. The values in the result follow so-called "standard" order: If ``A =
  72. fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the sum of
  73. the signal), which is always purely real for real inputs. Then ``A[1:n/2]``
  74. contains the positive-frequency terms, and ``A[n/2+1:]`` contains the
  75. negative-frequency terms, in order of decreasingly negative frequency.
  76. For an even number of input points, ``A[n/2]`` represents both positive and
  77. negative Nyquist frequency, and is also purely real for real input. For
  78. an odd number of input points, ``A[(n-1)/2]`` contains the largest positive
  79. frequency, while ``A[(n+1)/2]`` contains the largest negative frequency.
  80. The routine ``np.fft.fftfreq(n)`` returns an array giving the frequencies
  81. of corresponding elements in the output. The routine
  82. ``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the
  83. zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes
  84. that shift.
  85. When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)``
  86. is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum.
  87. The phase spectrum is obtained by ``np.angle(A)``.
  88. The inverse DFT is defined as
  89. .. math::
  90. a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\}
  91. \\qquad m = 0,\\ldots,n-1.
  92. It differs from the forward transform by the sign of the exponential
  93. argument and the default normalization by :math:`1/n`.
  94. Normalization
  95. -------------
  96. The default normalization has the direct transforms unscaled and the inverse
  97. transforms are scaled by :math:`1/n`. It is possible to obtain unitary
  98. transforms by setting the keyword argument ``norm`` to ``"ortho"`` (default is
  99. `None`) so that both direct and inverse transforms will be scaled by
  100. :math:`1/\\sqrt{n}`.
  101. Real and Hermitian transforms
  102. -----------------------------
  103. When the input is purely real, its transform is Hermitian, i.e., the
  104. component at frequency :math:`f_k` is the complex conjugate of the
  105. component at frequency :math:`-f_k`, which means that for real
  106. inputs there is no information in the negative frequency components that
  107. is not already available from the positive frequency components.
  108. The family of `rfft` functions is
  109. designed to operate on real inputs, and exploits this symmetry by
  110. computing only the positive frequency components, up to and including the
  111. Nyquist frequency. Thus, ``n`` input points produce ``n/2+1`` complex
  112. output points. The inverses of this family assumes the same symmetry of
  113. its input, and for an output of ``n`` points uses ``n/2+1`` input points.
  114. Correspondingly, when the spectrum is purely real, the signal is
  115. Hermitian. The `hfft` family of functions exploits this symmetry by
  116. using ``n/2+1`` complex points in the input (time) domain for ``n`` real
  117. points in the frequency domain.
  118. In higher dimensions, FFTs are used, e.g., for image analysis and
  119. filtering. The computational efficiency of the FFT means that it can
  120. also be a faster way to compute large convolutions, using the property
  121. that a convolution in the time domain is equivalent to a point-by-point
  122. multiplication in the frequency domain.
  123. Higher dimensions
  124. -----------------
  125. In two dimensions, the DFT is defined as
  126. .. math::
  127. A_{kl} = \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1}
  128. a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\}
  129. \\qquad k = 0, \\ldots, M-1;\\quad l = 0, \\ldots, N-1,
  130. which extends in the obvious way to higher dimensions, and the inverses
  131. in higher dimensions also extend in the same way.
  132. References
  133. ----------
  134. .. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
  135. machine calculation of complex Fourier series," *Math. Comput.*
  136. 19: 297-301.
  137. .. [NR] Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,
  138. 2007, *Numerical Recipes: The Art of Scientific Computing*, ch.
  139. 12-13. Cambridge Univ. Press, Cambridge, UK.
  140. Examples
  141. --------
  142. For examples, see the various functions.
  143. """
  144. from __future__ import division, absolute_import, print_function
  145. depends = ['core']