Borrar filtros
Borrar filtros

Failed to calculate Fourier Coefficients via FFT

1 visualización (últimos 30 días)
Ronald
Ronald el 19 de Jul. de 2018
Editada: Ronald el 19 de Jul. de 2018
Dear all, I am still learning how to use fft to produce the coefficients of a complex Fourier series. However, I can not get them right. It would be great if you could point out my mistakes. My program is about to produce a complex Fourier series representation of a Gaussian function in an interval of [-2,2]. Here is the source code:
clear all
m1=10;
n1=8;
xMin=-2;xMax=2;
x=linspace(-1,1,100+2^n1);
xn=(-xMin)*x+(xMax+xMin);
%fj=heaviside(xn);
fj=1./(sqrt(2*pi*0.4))*exp(-0.5*(xn-(0.2)).^2./0.4);
Nmax=round(2.^n1);
k=0:1:(Nmax-1);
xMax=repmat(xMax, [1, Nmax]);
xMin=repmat(xMin, [1, Nmax]);
Bk1x=ifft(fj(1:length(x)),length(x))./length(x);
Bk2x=Bk1x(1:Nmax);
for j=1:1:length(x)
values(j) =real(sum(Bk2x.*exp((1i*x(j).*pi.*k))));
end
plot(xn,values);
If you plot values out, you would see a shrunk, wrong Gaussian function.

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by