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'.
Two remarks:
N).Nin your last line of code.When you fix both things, you should get the same result for
norm_f_2andnorm_ft_2.