FFT - wrong frequency
8 views (last 30 days)
Show older comments
Hello,
I have a problem when I try to retrieve the frequency of a signal with fft.
Here is a test I did with a simple cosine of frequency 14.5 Hz :
Lz = 0.075 ;
nZ = 501 ;
Z = linspace(0,Lz,nZ) ;
dZ = Lz/nZ ;
Y = cos(2*pi*14.5*Z) ;
df = 1/(Lz) ;
f = (0:1:nZ-1)*df;
FFT = fft(Y) ;
% figure(1)
% plot(Z,Y)
figure(2)
plot(f,abs(FFT))
My problem is that I get a peak at f=13.33 Hz instead of 14.5 Hz .
What is also really weird is that I get the same peak (13.33Hz) when I try with a frequency of 16Hz, 18Hz... but from 20Hz the peak I get is at 26.67Hz, same for 32 Hz .
I tried to get the frequency axis differently, but I always have the same result. I also tried to use the function given by Daniel kiracofe in this issue https://fr.mathworks.com/matlabcentral/answers/132021-fft-don-t-give-correct-result : http://www.mechanicalvibration.com/Making_matlab_s_fft_functio.html
but the problem is still there.
Could someone help me please?
Thank you
0 Comments
Answers (1)
Peng Li
on 11 Apr 2020
Well, you need to understand what you are doing with each of these variables. Your code is kind of weird as all things you need to known are kind of hidden somewhere.
Based on your time variable Z, your sampling frequency is 1 ./ diff(Z).
>> fs = 1./diff(Z);
>> fs = fs(1)
fs =
6.6667e+03
And your signal length (FFT size by default) is nZ = 501. Your frequency resolution is thus fs / nZ = 13.3067.
With such a frequency resolution, you cannot expect to identify your target signal 14.5, 16, or 18 Hz. And when it is for 20 Hz, it jumped to the second trace 26.6, and so on.
Your signal Y also has a fraction number of cycles. So you can expect some spectral leakage around your target frequency too.
5 Comments
Peng Li
on 11 Apr 2020
try fft(Y(:).*hann(length(Y)), 4000); you can compare this with your orignal one fft(Y, 4000). If you show y axis in dB, you might able to see the drop of traces around the target frequency using window fft. You only have a bit more than 1 cycle of the cos wave so the effect might be interesting as well.
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!