MATLAB: Is there a factor of 2 in the example provided in the help documentation for the FFT command

2factorfftMATLABplotsidedsinglesingle-sidedspectrum

In the example provided in the help documentation for the FFT command, there seems to be an extra factor of 2 that the spectrum is multiplied by before being plotted.
The snippet of code is provided below:
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);
% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum of y(t)')

Best Answer

In this example, the single-sided spectrum is considered to be only the positive-frequency half of the frequency spectrum.
To compensate analytically for the notion that no negative frequencies exist, the symmetrical negative frequency components are truncated using Y(1:NFFT/2) and the positive frequency components are multiplied by two instead.