Parseval identity in FFT

708 Views Asked by At

I was recreating in Matlab a certain function using FFT. In particular I was interesting in knowing how modes are sufficient to approximate quite well my function.

To do that, I calculate the norm in L2 of the function and the sum of modulus squares of Fourier coefficients.

Of course, if I used all the wave vectors, by Parseval identity, I would approximate perfectly my function. However when I compute the code, I notice a strange thing happening and I am not able to understand.

The code is

 clear all;

 L= 8;

 N=100;

 x = (linspace(0,L,N))';

 f= @(x) (x/L).*sin(10*pi/L*x);

 ft = (1/N)*fft(f(x));

 nmodes = 70;

 mask = ones(N,1);

 mask(2+nmodes:end-nmodes)=0;

 norm_f_2 = (norm(f(x),2))^2;

 norm_ft_2 = sum((abs(ft.*mask)).^2);

The problem is that the square of the norm of the function is N times larger than the 'norm_ft_2'.

1

There are 1 best solutions below

0
On

Two remarks:

  • When computing the fourier transform, there is no need to divide over the number of datapoints (i.e., N).
  • Parseval's theorem states that $$ \sum_{n=0}^{N-1} |f[n]|^2=\frac{1}{N}\sum_{k=0}^{N-1}|F(k)|^2, $$ thus you have to divide by Nin your last line of code.

When you fix both things, you should get the same result for norm_f_2and norm_ft_2.