@@ -9,28 +9,28 @@ Fourier Transforms (:mod:`scipy.fft`)
9
9
10
10
11
11
Fourier analysis is a method for expressing a function as a sum of periodic
12
- components, and for recovering the signal from those components. When both
12
+ components, and for recovering the signal from those components. When both
13
13
the function and its Fourier transform are replaced with discretized
14
- counterparts, it is called the discrete Fourier transform (DFT). The DFT has
14
+ counterparts, it is called the discrete Fourier transform (DFT). The DFT has
15
15
become a mainstay of numerical computing in part because of a very fast
16
16
algorithm for computing it, called the Fast Fourier Transform (FFT), which was
17
17
known to Gauss (1805) and was brought to light in its current form by Cooley
18
- and Tukey [CT65 ]_. Press et al. [NR07 ]_ provide an accessible introduction to
18
+ and Tukey [CT65 ]_. Press et al. [NR07 ]_ provide an accessible introduction to
19
19
Fourier analysis and its applications.
20
20
21
21
.. note ::
22
22
23
23
PyFFTW _ provides a way to replace a number of functions in `scipy.fft `
24
24
with its own functions, which are usually significantly faster, via
25
- pyfftw.interfaces _. Because PyFFTW _ relies on the GPL-licensed FFTW _ it
26
- cannot be included in SciPy. Users for whom the speed of FFT routines is
25
+ pyfftw.interfaces _. Because PyFFTW _ relies on the GPL-licensed FFTW _ it
26
+ cannot be included in SciPy. Users for whom the speed of FFT routines is
27
27
critical should consider installing PyFFTW _.
28
28
29
29
30
30
Fast Fourier transforms
31
31
-----------------------
32
32
33
- One dimensional discrete Fourier transforms
33
+ 1-D discrete Fourier transforms
34
34
___________________________________________
35
35
36
36
The FFT `y[k] ` of length :math: `N` of the length-:math: `N` sequence `x[n] ` is
@@ -47,7 +47,7 @@ and the inverse transform is defined as follows
47
47
x[n] = \frac {1 }{N} \sum _{k=0 }^{N-1 } e^{2 \pi j \frac {k n}{N} } y[k] \, .
48
48
49
49
These transforms can be calculated by means of :func: `fft ` and :func: `ifft `,
50
- respectively as shown in the following example.
50
+ respectively, as shown in the following example.
51
51
52
52
>>> from scipy.fft import fft, ifft
53
53
>>> x = np.array([1.0 , 2.0 , 1.0 , - 1.0 , 1.5 ])
@@ -76,8 +76,8 @@ which corresponds to :math:`y[0]`. For N even, the elements
76
76
:math: `y[1 ]...y[N/2 -1 ]` contain the positive-frequency terms, and the elements
77
77
:math: `y[N/2 ]...y[N-1 ]` contain the negative-frequency terms, in order of
78
78
decreasingly negative frequency. For N odd, the elements
79
- :math: `y[1 ]...y[(N-1 )/2 ]` contain the positive- frequency terms, and the
80
- elements :math: `y[(N+1 )/2 ]...y[N-1 ]` contain the negative- frequency terms, in
79
+ :math: `y[1 ]...y[(N-1 )/2 ]` contain the positive-frequency terms, and the
80
+ elements :math: `y[(N+1 )/2 ]...y[N-1 ]` contain the negative-frequency terms, in
81
81
order of decreasingly negative frequency.
82
82
83
83
In case the sequence x is real-valued, the values of :math: `y[n]` for positive
@@ -104,7 +104,7 @@ The example plots the FFT of the sum of two sines.
104
104
>>> plt.show()
105
105
106
106
107
- The FFT input signal is inherently truncated. This truncation can be modelled
107
+ The FFT input signal is inherently truncated. This truncation can be modeled
108
108
as multiplication of an infinite signal with a rectangular window function. In
109
109
the spectral domain this multiplication becomes convolution of the signal
110
110
spectrum with the window function spectrum, being of form :math: `\sin (x)/x`.
@@ -181,7 +181,7 @@ The function :func:`rfft` calculates the FFT of a real sequence and outputs the
181
181
complex FFT coefficients :math: `y[n]` for only half of the frequency range. The
182
182
remaining negative frequency components are implied by the Hermitian symmetry of
183
183
the FFT for a real input (``y[n] = conj(y[-n]) ``). In case of N being even:
184
- :math: `[Re(y[0 ]) + 0 j, y[1 ], ..., Re(y[N/2 ]) + 0 j]`; in case N being odd
184
+ :math: `[Re(y[0 ]) + 0 j, y[1 ], ..., Re(y[N/2 ]) + 0 j]`; in case of N being odd
185
185
:math: `[Re(y[0 ]) + 0 j, y[1 ], ..., y[N/2 ]`. The terms shown explicitly as
186
186
:math: `Re(y[k]) + 0 j` are restricted to be purely real since, by the hermitian
187
187
property, they are their own complex conjugate.
@@ -210,34 +210,34 @@ array([ 4.5 +0.j , 2.08155948-1.65109876j,
210
210
array([ 4.5 +0.j , 2.08155948-1.65109876j,
211
211
-1.83155948+1.60822041j])
212
212
213
- Notice that the :func: `rfft ` of odd and even length signals are the same shape.
214
- By default, :func: `irfft ` assumes the ouput signal should be of even length. And
215
- so for odd signals, will give the wrong result:
213
+ Notice that the :func: `rfft ` of odd and even length signals are of the same shape.
214
+ By default, :func: `irfft ` assumes the output signal should be of even length. And
215
+ so, for odd signals, it will give the wrong result:
216
216
217
217
>>> irfft(yr)
218
218
array([ 1.70788987, 2.40843925, -0.37366961, 0.75734049])
219
219
220
- To recover the original odd length signal, we **must ** pass the output shape by
220
+ To recover the original odd- length signal, we **must ** pass the output shape by
221
221
the `n ` parameter.
222
222
223
223
>>> irfft(yr, n = len (x))
224
224
array([ 1. , 2. , 1. , -1. , 1.5])
225
225
226
226
227
227
228
- Two and n-dimensional discrete Fourier transforms
228
+ 2- and N-D discrete Fourier transforms
229
229
_________________________________________________
230
230
231
- The functions :func: `fft2 ` and :func: `ifft2 ` provide 2-dimensional FFT, and
232
- IFFT, respectively. Similar , :func: `fftn ` and :func: `ifftn ` provide
233
- n-dimensional FFT, and IFFT, respectively.
231
+ The functions :func: `fft2 ` and :func: `ifft2 ` provide 2-D FFT and
232
+ IFFT, respectively. Similarly , :func: `fftn ` and :func: `ifftn ` provide
233
+ N-D FFT, and IFFT, respectively.
234
234
235
- For real input signals, similar to :func: `rfft `, we have the functions
236
- :func: `rfft2 ` and :func: `irfft2 ` for 2-dimensional real transforms;
237
- :func: `rfftn ` and :func: `irfftn ` for n-dimensional real transforms.
235
+ For real- input signals, similarly to :func: `rfft `, we have the functions
236
+ :func: `rfft2 ` and :func: `irfft2 ` for 2-D real transforms;
237
+ :func: `rfftn ` and :func: `irfftn ` for N-D real transforms.
238
238
239
- The example below demonstrates a 2-dimensional IFFT and plots the resulting
240
- (2-dimensional ) time-domain signals.
239
+ The example below demonstrates a 2-D IFFT and plots the resulting
240
+ (2-D ) time-domain signals.
241
241
242
242
.. plot ::
243
243
@@ -294,7 +294,7 @@ SciPy uses the following definition of the unnormalized DCT-I
294
294
\cos \left (\frac {\pi nk}{N-1 }\right ),
295
295
\qquad 0 \le k < N.
296
296
297
- Note that the DCT-I is only supported for input size > 1
297
+ Note that the DCT-I is only supported for input size > 1.
298
298
299
299
Type II DCT
300
300
___________
@@ -320,7 +320,7 @@ In this case, the DCT "base functions" :math:`\phi_k[n] = 2 f \cos
320
320
321
321
.. math ::
322
322
323
- \sum _{n=0 }^{N-1 } \phi _k[n] \phi _l[n] = \delta _{lk}
323
+ \sum _{n=0 }^{N-1 } \phi _k[n] \phi _l[n] = \delta _{lk}.
324
324
325
325
326
326
Type III DCT
@@ -347,23 +347,23 @@ ____________
347
347
348
348
349
349
The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up to a
350
- factor `2N `. The orthonormalized DCT-III is exactly the inverse of the
350
+ factor of `2N `. The orthonormalized DCT-III is exactly the inverse of the
351
351
orthonormalized DCT- II. The function :func: `idct ` performs the mappings between
352
- the DCT and IDCT types, as well as performing the correct normalization.
352
+ the DCT and IDCT types, as well as the correct normalization.
353
353
354
354
The following example shows the relation between DCT and IDCT for different
355
355
types and normalizations.
356
356
357
357
>>> from scipy.fft import dct, idct
358
358
>>> x = np.array([1.0 , 2.0 , 1.0 , - 1.0 , 1.5 ])
359
359
360
- The DCT-II and DCT-III are each others inverses, so for an orthonormal transform
360
+ The DCT-II and DCT-III are each other's inverses, so for an orthonormal transform
361
361
we return back to the original signal.
362
362
363
363
>>> dct(dct(x, type = 2 , norm = ' ortho' ), type = 3 , norm = ' ortho' )
364
364
array([ 1. , 2. , 1. , -1. , 1.5])
365
365
366
- Doing the same under default normalization however, we pick up an extra scaling
366
+ Doing the same under default normalization, however, we pick up an extra scaling
367
367
factor of :math: `2 N=10 ` since the forward transform is unnormalized.
368
368
369
369
>>> dct(dct(x, type = 2 ), type = 3 )
@@ -376,8 +376,8 @@ giving a correctly normalized result.
376
376
>>> idct(dct(x, type = 2 ), type = 2 )
377
377
array([ 1. , 2. , 1. , -1. , 1.5])
378
378
379
- Analogous results can be seen for the DCT-I which is its own inverse up to a
380
- factor of :math: `2 (N-1 )`
379
+ Analogous results can be seen for the DCT-I, which is its own inverse up to a
380
+ factor of :math: `2 (N-1 )`.
381
381
382
382
>>> dct(dct(x, type = 1 , norm = ' ortho' ), type = 1 , norm = ' ortho' )
383
383
array([ 1. , 2. , 1. , -1. , 1.5])
@@ -388,7 +388,7 @@ array([ 8. , 16., 8. , -8. , 12.])
388
388
>>> idct(dct(x, type = 1 ), type = 1 )
389
389
array([ 1. , 2. , 1. , -1. , 1.5])
390
390
391
- And for the DCT-IV which is also its own inverse up to a factor of :math: `2 N`
391
+ And for the DCT-IV, which is also its own inverse up to a factor of :math: `2 N`.
392
392
393
393
>>> dct(dct(x, type = 4 , norm = ' ortho' ), type = 4 , norm = ' ortho' )
394
394
array([ 1. , 2. , 1. , -1. , 1.5])
@@ -408,7 +408,7 @@ Zeroing out the other coefficients leads to a small reconstruction error, a
408
408
fact which is exploited in lossy signal compression (e.g. JPEG compression).
409
409
410
410
The example below shows a signal x and two reconstructions (:math: `x_{20 }` and
411
- :math: `x_{15 }`)from the signal's DCT coefficients. The signal :math: `x_{20 }`
411
+ :math: `x_{15 }`) from the signal's DCT coefficients. The signal :math: `x_{20 }`
412
412
is reconstructed from the first 20 DCT coefficients, :math: `x_{15 }` is
413
413
reconstructed from the first 15 DCT coefficients. It can be seen that the
414
414
relative error of using 20 coefficients is still very small (~0.1%), but
@@ -446,7 +446,7 @@ Discrete Sine Transforms
446
446
SciPy provides a DST [Mak ]_ with the function :func: `dst ` and a corresponding IDST
447
447
with the function :func: `idst `.
448
448
449
- There are theoretically 8 types of the DST for different combinations of
449
+ There are, theoretically, 8 types of the DST for different combinations of
450
450
even/odd boundary conditions and boundary off sets [WPS ]_, only the first 3
451
451
types are implemented in scipy.
452
452
@@ -462,7 +462,7 @@ definition of the unnormalized DST-I (``norm=None``):
462
462
\right ), \qquad 0 \le k < N.
463
463
464
464
Note also that the DST-I is only supported for input size > 1. The
465
- (unnormalized) DST-I is its own inverse, up to a factor `2(N+1) `.
465
+ (unnormalized) DST-I is its own inverse, up to a factor of `2(N+1) `.
466
466
467
467
Type II DST
468
468
___________
@@ -491,19 +491,19 @@ DST and IDST
491
491
____________
492
492
493
493
494
- The following example below shows the relation between DST and IDST for
494
+ The following example shows the relation between DST and IDST for
495
495
different types and normalizations.
496
496
497
497
>>> from scipy.fft import dst, idst
498
498
>>> x = np.array([1.0 , 2.0 , 1.0 , - 1.0 , 1.5 ])
499
499
500
- The DST-II and DST-III are each others inverses, so for an orthonormal transform
500
+ The DST-II and DST-III are each other's inverses, so for an orthonormal transform
501
501
we return back to the original signal.
502
502
503
503
>>> dst(dst(x, type = 2 , norm = ' ortho' ), type = 3 , norm = ' ortho' )
504
504
array([ 1. , 2. , 1. , -1. , 1.5])
505
505
506
- Doing the same under default normalization however, we pick up an extra scaling
506
+ Doing the same under default normalization, however, we pick up an extra scaling
507
507
factor of :math: `2 N=10 ` since the forward transform is unnormalized.
508
508
509
509
>>> dst(dst(x, type = 2 ), type = 3 )
@@ -515,8 +515,8 @@ giving a correctly normalized result.
515
515
>>> idst(dst(x, type = 2 ), type = 2 )
516
516
array([ 1. , 2. , 1. , -1. , 1.5])
517
517
518
- Analogous results can be seen for the DST-I which is its own inverse up to a
519
- factor of :math: `2 (N-1 )`
518
+ Analogous results can be seen for the DST-I, which is its own inverse up to a
519
+ factor of :math: `2 (N-1 )`.
520
520
521
521
>>> dst(dst(x, type = 1 , norm = ' ortho' ), type = 1 , norm = ' ortho' )
522
522
array([ 1. , 2. , 1. , -1. , 1.5])
@@ -527,7 +527,7 @@ array([ 12., 24., 12., -12., 18.])
527
527
>>> idst(dst(x, type = 1 ), type = 1 )
528
528
array([ 1. , 2. , 1. , -1. , 1.5])
529
529
530
- And for the DST-IV which is also its own inverse up to a factor of :math: `2 N`
530
+ And for the DST-IV, which is also its own inverse up to a factor of :math: `2 N`.
531
531
532
532
>>> dst(dst(x, type = 4 , norm = ' ortho' ), type = 4 , norm = ' ortho' )
533
533
array([ 1. , 2. , 1. , -1. , 1.5])
0 commit comments