FFT of a simple harmonic data
5 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have the two data vectors, Time and Displacement. When I plot them as plot(Time,displ), I can see the harmonic behavior but when I do the FFT using following code, I get strange plot and do not get frequency peak. I shall be grateful for the help. Here Fs=180 and L=180, the two being the sampling frequency and length of signal respectively. Both have dimensions 180x1. I just used the following code available from Matlab help for simple sine function.
Thanks...
Fs=180;
L=180;
Y=fft(displ);
f = Fs*(0:(L/2))/L;
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1)
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
0 件のコメント
採用された回答
Star Strider
2016 年 10 月 4 日
It is difficult for me to follow your code. I always use (and recommend) the code from the R2015a documentation for fft (link). Especially note the code between the first (top) two plot figures.
3 件のコメント
Star Strider
2016 年 10 月 4 日
I can’t open the .zip files for some reason.
Save the contents as a .mat file and upload that instead.
Star Strider
2016 年 10 月 5 日
In order to calculate a frequency vector for the plot, you need to use the time data as well:
fidi1 = fopen('Rehan Rehan time.dat','rt');
tc = textscan(fidi1, '%f');
t = tc{:};
fclose(fidi1);
fidi2 = fopen('Rehan Rehan displ.dat','rt');
displc = textscan(fidi2, '%f');
fclose(fidi2);
displ = displc{:};
L = length(displ); % Data Length
Ts = mean(diff(t)); % Sampling Time Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTdisp = fft(displ)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
figure(1)
semilogy(Fv, abs(FTdisp(Iv)))
grid
xlabel('Frequency')
ylabel('Amplitude')

その他の回答 (1 件)
David Goodmanson
2016 年 10 月 4 日
編集済み: David Goodmanson
2016 年 10 月 4 日
Your signal has a large offset of -2, with some small oscillations about that value. Therefore your plot has a large peak at zero frequency (the DC offset), along with some much smaller frequency components that are too hard to see. If you do a 'semilogy' plot of P1, or replace the zero frequency component of P1 by NaN and plot that result, or subtract the DC offset from your 'displ' data before the fft, frequency peaks will appear.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!