MATLAB: Using fft() to calculate PSD.

fft frequency analysis spectrum

I used the code below perform spectral analysis of signal with known period of 4 s:
load lujan.dat
data_out.time = lujan(:,1);
data_out.disp = lujan(:,2);
Y = fft(data_out.disp,1000);
Y(1)=[];
NY = length(Y);
Pyy = abs(Y(1:floor(NY/2))).^2;
nyquist = 1/2;
f = (1:NY/2)/(NY/2)*nyquist;
plot(f,Pyy,'-b','LineWidth',3);
title('Power spectral density');
xlabel('Frequency (Hz)');
However the output graph shows a peak at 0.05 Hz which is not correct! IS there something obvious i'm doing wrong?
thanks

Best Answer

Are you sure the sampling frequency is 1 ? If so, how far off is the peak from where you expect it to be? Is it almost correct or way off? You also don't tell us how long the time series is, so we don't know why you are adding the length input argument to fft() . Your frequency increment of 1/NY (0.0025) is correct.