A. Rapoport
A. Rapoport

Reputation: 113

Extra explanation concerning the mathwork example on using matlab fft

can someone explain why the result of an fft need to be divided by the number of sampling points (length of the signal)?

The example can be found on this page: https://fr.mathworks.com/help/matlab/ref/fft.html

Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)*T;        % Time vector

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
Y = fft(S);

P2 = abs(Y/L);

P1 = P2(1:L/2+1);

Why do they include this operation: P2 = abs(Y/L);?

They do it for each example in the link.

Also, why wouldn't they include that operation directly in the in-built fft function if they have to perform that operation after each fft calculation? Are there some cases where it's better not to perform that extra operation?.

Thanks!

Upvotes: 2

Views: 107

Answers (2)

hotpaw2
hotpaw2

Reputation: 70673

Not including 1/N in the FFT allows Parseval's theorem to be true. e.g. a signal twice as long in the time domain (because the FFT is longer, etc.) would show up with twice the power in the frequency domain.

Not all implementations of FFTs include the 1/N. Some instead put this factor in the IFFT. Some split the difference and use 1/sqrt(N) in both. Without this factor somewhere, the IFFT would not be an inverse of the FFT.

Upvotes: 0

Cris Luengo
Cris Luengo

Reputation: 60444

As you can see from the definitions of the DFT and its inverse (from Wikipedia):

DFT equation

IDFT equation

the difference between the DFT and its inverse are the sign in the exponent, and the normalization term 1/N. But note that it does not matter where this 1/N is placed, it could be put into the forward transform and one would still preserve IDFT(DFT(f))==f. In fact, some people make these symmetric by putting 1/sqrt(N) in front of each of the two transforms.

The reason it is typically put in front of the inverse transform is that then you can do things like IDFT(DFT(f)DFT(g)) == f*g (with * the convolution). If the DFT had the 1/N normalization term, then computing the convolution through the frequency domain requires one additional operation. So this is just convenient.

But when using the DFT to examine signal power and so forth, one might want this normalization added to the forward transform. The DFT yields values that depend on the signal strength as well as its length. The normalization removes the dependence on length. For example:

>> fft(ones(1,4))
ans =
   4   0   0   0

>> fft(ones(1,8))
ans =
   8   0   0   0   0   0   0   0

but with normalization added:

>> fft(ones(1,4))/4
ans =
   1   0   0   0

>> fft(ones(1,8))/8
ans =
   1   0   0   0   0   0   0   0

Upvotes: 5

Related Questions