Your axis command is not correct. The frequency axis should only run to 20000 because that is the Nyquist frequency and I'm not sure why you picked the Y-limits on your axis command -- those may not be appropriate either.
I'll just create a signal using your sampling frequency and data length and show you
Fs = 40000;
t = 0:1/Fs:(2e3*1/Fs)-1/Fs;
y = cos(2*pi*5000*t)+randn(size(t));
T = 1/Fs;
L = 2000;
NFFT = 2^nextpow2(L);
Y = abs(fft(y,NFFT))/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
Also, I understand you've taken this example from the documentation, but there may be no need at all to zero pad and/or do some of the other operations you have included above. But the code you have should give you an idea of the distribution of energy by frequency.
Best Answer