Finding the dominant frequency of a time series data using fft
조회 수: 9 (최근 30일)
이전 댓글 표시
% Hi can anyone explain me why using this two procedures I get two diferent dominant frequencies for the same signal? % Note: the data can be downloaded from here: http://www.filedropper.com/data_21
s = load('data.mat'); % load the data
Signal= s.data;
Fs = 60;
t = 0: 1/Fs:length(Signal)/Fs-(1/Fs);
% plot data
subplot(3,1,1); plot(t,Signal,'m');
xlabel('Time','FontWeight','bold','FontSize',10)
ylabel('Amplitude','FontWeight','bold','FontSize',10)
%%Procedure 1
N = length(Signal);
Signal = Signal - mean(Signal); % to remove the frequency at 0 (or D-C offset)
sigFFT = (abs(fft(Signal)).^2);
bin_vals = 0 : N-1;
fax_Hz = bin_vals*Fs/N;
N_2 = ceil(N/2);
power = sigFFT(1:N_2); % get magnitude
freq = fax_Hz(1:N_2); % get freq in Hz
subplot(3,1,2); plot(freq,power,'k')
xlabel('Frequency (Hz)','FontWeight','bold','FontSize',10)
ylabel('Power','FontWeight','bold','FontSize',10)
xlim([0 35]); title('Periodogram')
%%Procedure 2
%(obtained from here: http://www.mathworks.com/matlabcentral/answers/183642-finding-the-dominant-frequency-of-a-time-series-data-using-fft-matlab)
x = Signal - mean(Signal);
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
subplot(3,1,3);
plot(f_scale, y),axis('tight'),grid('on'),title('Dominant Frequency')
xlim([0 35]);
But insted of this if I use this signals below I get the same results between procedure 1 and 2
Fs =500; % sample frequency
f1 = 3; f2 = 13; f3 = 30; % frequency
theta =0; % phase shift
A0 =0; % offset
A = 1; % amplitude
t = 0: 1/Fs:1 -(1*1/Fs); % time
Sig1 = A0 + A*sin(2*pi*f1*t + theta);
Sig2 = A0 + A*cos(2*pi*f2*t + theta) ;
Sig3 = A0 + A*sin(2*pi*f3*t + theta);
SignalSum = Sig1 + Sig2 + Sig3;
댓글 수: 1
Luis Omar
2020년 7월 8일
fft works better when the total number of the N-points is multiple of power of 2^n like 1024, 512, 2048 etc
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!