Finding the dominant frequency of a time series data using fft matlab

조회 수: 25 (최근 30일)
I'm trying to determine the dominant frequency of a time series data using the fft function in matlab. my data is represented as a vector while my time scale is also a vector. Below is my sample code:
Fs = 10; % sampling frequency 1 kHz
t = [0,10,20,30,40,50,60,70,80,90]; % time scale
x = [10,120,130,120,120,100,123,456,78,89]; % time series
plot(t,x), axis('tight'), grid('on'), title('Time series'), figure
nfft = 512; % next larger power of 2
y = fft(x,nfft); % Fast Fourier Transform
y = abs(y.^2); % raw power spectrum density
y = y(1:1+nfft/2); % half-spectrum
[v,k] = max(y); % find maximum
f_scale = (0:nfft/2)* Fs/nfft; % frequency scale
plot(f_scale, y),axis('tight'),grid('on'),title('Dominant Frequency')
fest = f_scale(k); % dominant frequency estimate
fprintf('Dominant freq.: true %f Hz, estimated %f Hznn', f, fest)
fprintf('Frequency step (resolution) = %f Hznn', f_scale(2))
The problem is that my dominant frequency here is 0 which am not quite sure if it is correct. Could some provide feedback on this please especially if the Fs matters alot in this case!
  댓글 수: 4
Mehdi
Mehdi 2024년 8월 7일
hi guys. I have a question. I have a time series of data and using the FFT, I have found the dominant frequencies. FFT sohws me some frequencies that have high power. However, I know that some of thos frequencies are wrong. I mean my periodic time series does not contain all frequencies that are shown by FFT. Just some of them. is there any way to choose exactly the correct frequencies?
thank you
Star Strider
Star Strider 2024년 8월 7일
@Mehdi — Be sure that you are plotting a one-sided Fourier transform and using a frequency vector that is appropriate for it.

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

채택된 답변

Star Strider
Star Strider 2015년 3월 17일
The ‘frequency’ at 0 is the mean of your signal (or D-C offset). To eliminate it, subtract the mean before doing the fft.
This gives you the result you want:
Fs = 10; % sampling frequency 1 kHz
t = [0,10,20,30,40,50,60,70,80,90]; % time scale
x = [10,120,130,120,120,100,123,456,78,89]; % time series
x = x - mean(x); % <= ADDED LINE
plot(t,x), axis('tight'), grid('on'), title('Time series'), figure
nfft = 512; % next larger power of 2
y = fft(x,nfft); % Fast Fourier Transform
y = abs(y.^2); % raw power spectrum density
y = y(1:1+nfft/2); % half-spectrum
[v,k] = max(y); % find maximum
f_scale = (0:nfft/2)* Fs/nfft; % frequency scale
plot(f_scale, y),axis('tight'),grid('on'),title('Dominant Frequency')
fest = f_scale(k); % dominant frequency estimate
fprintf('Dominant freq.: true %f Hz, estimated %f Hznn\n', fest, fest)
fprintf('Frequency step (resolution) = %f Hznn\n', f_scale(2))
  댓글 수: 4
Vanisa Syahra
Vanisa Syahra 2020년 6월 22일
hello, I have the same problem with David, but here, eventhough I subtract the signal with the mean, I still get the zero frequency which has the highest power. Why this still happen? i am pretty sure that the dminant freq is not 0.
Walter Roberson
Walter Roberson 2020년 6월 22일
Is it possible that you have a 2D signal and that you are subtracting the mean along the wrong dimension?

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

추가 답변 (1개)

Eric Marshal
Eric Marshal 2017년 5월 4일
hello mr. David Gureya, may i ask you how you get 512 as NFFT ? are the n(number) from time series is diffrent with NFFT ?

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by