12
12
def fftshift(x,axes=None):
14
Shift zero-frequency component to center of spectrum.
14
Shift the zero-frequency component to the center of the spectrum.
16
16
This function swaps half-spaces for all axes listed (defaults to all).
17
If len(x) is even then the Nyquist component is y[0].
17
Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
23
23
axes : int or shape tuple, optional
24
Axes over which to shift. Default is None which shifts all axes.
24
Axes over which to shift. Default is None, which shifts all axes.
33
ifftshift : The inverse of `fftshift`.
37
>>> freqs = np.fft.fftfreq(10, 0.1)
39
array([ 0., 1., 2., 3., 4., -5., -4., -3., -2., -1.])
40
>>> np.fft.fftshift(freqs)
41
array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.])
43
Shift the zero-frequency component only along the second axis:
45
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
50
>>> np.fft.fftshift(freqs, axes=(1,))
44
69
def ifftshift(x,axes=None):
71
The inverse of fftshift.
52
77
axes : int or shape tuple, optional
53
Axes over which to calculate. Defaults to None which is over all axes.
78
Axes over which to calculate. Defaults to None, which shifts all axes.
87
fftshift : Shift zero-frequency component to the center of the spectrum.
91
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
96
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
72
114
def fftfreq(n,d=1.0):
74
Discrete Fourier Transform sample frequencies.
116
Return the Discrete Fourier Transform sample frequencies.
76
118
The returned float array contains the frequency bins in
77
119
cycles/unit (with zero at the start) given a window length `n` and a
81
f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n) if n is even
82
f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n) if n is odd
122
f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even
123
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd
93
out : ndarray, shape(`n`,)
135
The array of length `n`, containing the sample frequencies.
98
>>> signal = np.array([-2., 8., -6., 4., 1., 0., 3., 5.])
139
>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
99
140
>>> fourier = np.fft.fft(signal)
101
142
>>> timestep = 0.1
102
143
>>> freq = np.fft.fftfreq(n, d=timestep)