How to Normalize a fft to plot in frequency domain?

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]);

 Réponse acceptée

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.

6 commentaires

So, I just did what you asked, and I think I understand this since, there is a 1/2 in the Fourier Transform of Cosines. But why do we have to divide by N while forward FFT, I thought we need to divided by N for Inverse FFT.
The division by ‘N’ is to normalise the Fourier transform for the energy in the signal. It is then necessary to multiply the inverse Fourier transform by ‘N’ to reconstruct the signal:
N = 1000;
t = linspace(0, 10*pi, N); % Time Vector
Fs = 1/(t(2)-t(1)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
s = sin(2*pi*5*t); % Signal Vector
FTs = fft(s)/N; % Divide By ‘N’ To Normalise Amplitudes
Fv2 = linspace(-N/2, N/2, N)*Fs; % Frequency Vector (2-Sided)
figure(1)
plot(Fv2, abs(fftshift(FTs)))
grid
IFTs = ifft(FTs)*N; % Multiply By ‘N’ To Reconstruct Signal
figure(2)
plot(t, s)
hold on
plot(t, IFTs, '--r')
hold off
grid
Hi, I've got another question- is it correct to say that we "normalise", i.e. divide the fft by the number of non-zero samples in the time domain, and not just the length of the signal in the time domain?
Not quite.
Normalise the fft by dividing it by the length of the original signal in the time domain.
Zero values within the signal are considered to be part of the signal, so ‘non-zero samples’ is inappropriate. The length to use to normalise the signal is the length before adding zero-padding.
Hello, If we perform fft2, should we normalize dividing by length(x)*length(y)?
@Mustafa Rifat — Apparently not. The discussion in the fft2 secton on 2-D Fourier Transform does not normalise by the lengths or the number of elements in the matrix, however a similar discussion on Discrete Fourier Transform of Vector in the fft documentation, does.
I admit that I have never thought about this before, because I infrequently use fft2.
There is nothing wrong with experimenting to see if dividing by numel(A), where ‘A’ is the matrix, gives the desired result.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by