MATLAB: FFT is finding a max amplitude at 0 Hz

fftMATLABsignal processing

Can anyone explain why fft is giving a maximum amplitude at 0 Hz if the actual signal is pretty clear?
In my code, x is the signal as a function of time and r = length(x):
NFFT = 2^nextpow2(r);
X = fft(x,NFFT)/r;
Fs = 1/dt; % sampling frequency
f = Fs/2*linspace(0,1,NFFT/2+1); % frequency
A = 2*abs(X(1:NFFT/2+1)); % ampitude spectrum

Best Answer

You need to remove the DC component first. Just do
x = x-mean(x)
or
x = detrend(x)
before applying FFT