fftshift with even and odd number of data points (scaling the positive and negative frequency axis)
65 次查看(过去 30 天)
显示 更早的评论
If we wish to draw double sided frequency axis, i.e., positive and negative frequencies with odd and even number of data points respectively, how should we scale the frequency axis in each case? There is perhaps a very subtle point here.
Fs= sampling frequency
1) In the case of an even number of data points (N), the maximum values on the frequency axis are (Fs/2). However, there is one extra value in the output corresponding to the "negative" frequency when N is even as shown in this table after fftshift. Apparently, the extreme FT values are not the same after fftshift (as shown in the Table) when N is even.
2) In the case of an odd number of data points (N), the maximum values on the frequency axis are not (Fs/2), they are always less than (Fs/2). However, FT output are symmetric after fftshift.
What is the proper way to address this scaling issue in MATLAB for a double sided spectrum? Let us say we have the following, with Fs= 20 Hz
A_even=[0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]
length(A_even)
B=fft(A_even)
C=fftshift(B)
X_odd=[0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 ]
length(X_odd)
Y=fft(X_odd)
Z=fftshift(Y)
3) This Table from an online FFT Primer summarizes the above query. It does not explain why MATLAB prefers a negative frequency value first in case of even number of data points. Please see the case of N=2, 4, 6.
Thanks.
![DSP discussionpost.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/222454/DSP%20discussionpost.jpeg)
0 个评论
采纳的回答
David Goodmanson
2019-6-3
编辑:David Goodmanson
2019-6-3
Hi Farooq,
[1] For N odd, the frequencies before and after using fftshift (or ifftshift) are as you say:
N = 9 example:
for frequencies with spacing deltaf,
frequency array corresponding to the fft output array is
[0 1 2 3 4 -4 -3 -2 -1]*deltaf
if fftshift is then employed,
frequency array corresponding to the shifted fft output array is
[-4 -3 -2 -1 0 1 2 3 4]*deltaf
Fairlly straigthforward.
You can use ifftshift to undo the effect of fftshift, but note that for odd N, fftshift and its inverse function ifftshift are different functions. Consequently fftshift is not its own inverse.
[2] For even N, aside from zero, pos and neg frequencies there is also the Nyquist frequency, corresponding to exactly half an oscillation in each time interval. That frequency is really no more negative than it is positive.
N = 10 example:
frequency array corresponding to the fft output array is
[0 1 2 3 4 ny -4 -3 -2 -1]*deltaf
if fftshift is then employed,
frequency array corresponding to the shifted fft output array is
[ny -4 -3 -2 -1 0 1 2 3 4]*deltaf
Using the 'ny' label removes the unsatisfying asymmetry in the indices that you saw in Table 1.
Here fftshift and ifftshift are identical and both swap the two halves of the array. For even N, fftshift is its own inverse.
4 个评论
David Goodmanson
2019-6-7
Hi Farooq,
The odd case is as you say. As is mentioned, for N even If you splint the array in half, 0 frequency is at the lower end of the lower half and the nyquist frequency is at the lower end of the upper half.
For even N there is no real middle point and there are two possible choices to place 0 frequency with an fftshift.
a) highest point of lower half, point N/2
b) lowest point of upper half, point N/2+1.
simply swapping the two halves of the array accomplishes b) so that's what they did. You end up with a frequency array -(N/2) : (N/2)-1
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!