Axes the effect the fftshift operation
Sometimes having the “negative” frequencies at the end of the output returned by fft can be a little confusing. There are two ways to deal with this confusion. In my opinion, the most useful way is to get a collection of DFT sample frequencies and use them to keep track of where each frequency is. The function fftfreq provides these sample frequencies. Making an x-y plot, where the sample frequencies are along the “x”-axis and the result of the DFT is along the “y”-axis provides a useful visualization with the zero-frequency at the center of the plot. The advantage of this approach is that your data is still in proper order for using the ifft function. Some people, however, prefer to simply swap one-half of the output with the other. This is exactly what the function fftshift does. Of course, now the data is not in the proper order for the ifft function, but to each his own.
The reason that the “negative” frequencies are in the upper part of the return signal was given in the description of the DFT. The reason is that the output of the DFT is just one period of a periodic function (with period n). The traditional output of the FFT algorithm is to provide the portion of the function from from k = 0 to k = n − 1.
fftfreq (n, d=1.0)
Provide the DFT sample frequencies. The returned float array contains the fre-quency bins in the order returned from the fft function. If given, d represents the sample-spacing. The units on the frequency bins are cycles / unit. For example, the following example computes the output frequencies (in Hz) of the fft of 256 samples of a voice signal sampled at 20000Hz.
X [k0, k1] = | s[0]−1 m0=0� |
x [m0, m1] exp | �−j2πk0m0 | � | exp | �−j2πk1m1 |
---|
ifft2 (X, s=None, axes=(-2,-1))
Return the inverse of the two-dimension fft. Thus, ifft2(fft2(x)) == x to within numerical precision. Note that the “negative frequencies” must be
The Discrete Fourier transform returns complex-valued data (even for real-valued input). If the data was originally real-valued, then much of the output of the full DFT is redundant. Notice that if x [m] is real, then
X [n − k] | = |
|
|
---|---|---|---|
= | |||
= |