MATLAB: FFT of a simple harmonic data

fft

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 180×1. 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)|')

Best Answer

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.