FFT of a simple harmonic data
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rehan Rehan
am 4 Okt. 2016
Kommentiert: Star Strider
am 5 Okt. 2016
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 Kommentare
Akzeptierte Antwort
Star Strider
am 4 Okt. 2016
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 Kommentare
Star Strider
am 4 Okt. 2016
I can’t open the .zip files for some reason.
Save the contents as a .mat file and upload that instead.
Star Strider
am 5 Okt. 2016
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')

Weitere Antworten (1)
David Goodmanson
am 4 Okt. 2016
Bearbeitet: David Goodmanson
am 4 Okt. 2016
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.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!