function X = one_sided_scaled_fft(x)
% FFT with correct amplitude and only positive frequency range.

Y = fft(x);
L = length(x);
P2 = (Y./L);      % Normalize amplitude by sample length.
%P1 = fftshift(P2,1); % fft(x) returns vector with *positive* freq components first, then negative components. fftshift(X) switches the order.
P1 = P2(1:L/2+1);         % Extract positive frequency components.
P1(2:end-1) = 2*P1(2:end-1); % Normalize one-sided spectrum.
X = P1(1:end-1); % Truncate last element in order to be consistent with f vector.