FFT of a simple harmonic data

5 visualizzazioni (ultimi 30 giorni)
Rehan Rehan
Rehan Rehan il 4 Ott 2016
Commentato: Star Strider il 5 Ott 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)|')

Risposta accettata

Star Strider
Star Strider il 4 Ott 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 Commenti
Star Strider
Star Strider il 4 Ott 2016
I can’t open the .zip files for some reason.
Save the contents as a .mat file and upload that instead.
Star Strider
Star Strider il 5 Ott 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')

Accedi per commentare.

Più risposte (1)

David Goodmanson
David Goodmanson il 4 Ott 2016
Modificato: David Goodmanson il 4 Ott 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 Commento
Rehan Rehan
Rehan Rehan il 5 Ott 2016
Modificato: Rehan Rehan il 5 Ott 2016
Thanks a lot. Now it does show the peak but the peak is at wrong Freq. The data suggests the peak around 0.3 more or less but the peak is at 6. Still need a little help.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by