MATLAB: How to Normalize a fft to plot in frequency domain

fftnormalize

When I plot the frequency domain the power is not 3 and 5 as I expect. I read the documentation for fft() and cannot figure out how to normalize my fft properly. Can someone explain the procedure to normalize the cosines and a Gaussian wave? Thanks
clear all;
%generate the signal
t = 0:1/2000:.02;
x = 3*cos(2*pi*60*t) + 5*cos(2*pi*200*t);
%sample the signal
fs = 1000;
t1000 = 0:1/fs:.02; % number of sample points
n1000 = 0:length(t1000)-1; % number of intervals
x1000 = 3*cos(2*pi*60*n1000/1000) + 5*cos(2*pi*200*n1000/1000) ; %cos(2*pi*60*n*ts);
%Compute FT
z = fftshift(fft(x1000));
f = -fs/2: fs/(length(n1000)-1): fs/2 ;
%plot time domain
figure
subplot(2,1,1)
plot(t,x)
hold on;
grid on;
stem(t1000, x1000, 'filled', 'r', 'LineWidth', 2);
%plot freq domain
subplot(2,1,2);
plot(f,abs(z)); %normalization??
grid on;
xticks(-500:50:500);
xlim([-300 300]);

Best Answer

I am not certain what you intend by ‘normalise’. You need to scale it by dividing the fft result by the length of the time-domain signal:
z = fftshift(fft(x1000)/length(x1000));
This ‘normalises’ the result, correcting for the total energy in the time-domain signal. (You can use the numel function instead of length for a vector. Read about both to understand where each is appropriate.)
Note that you are using the two-sided Fourier transform, so the signal intensity will be equally divided between the negative frequencies and positive frequencies. In a one-sided Fourier transform, correct for this by multiplying the fft output by 2 to reproduce the amplitude of the original signals.