FFT - wrong frequency

조회 수: 21 (최근 30일)
clpi
clpi 2020년 4월 11일
댓글: clpi 2020년 4월 11일
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

답변 (1개)

Peng Li
Peng Li 2020년 4월 11일
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
Peng Li
Peng Li 2020년 4월 11일
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.
clpi
clpi 2020년 4월 11일
It is a bit better indeed, thank you very much for your time.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Transforms에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by