Recover gaussian by using fft and ifft.

1 次查看(过去 30 天)
I am trying to recover gaussian by using fft and ifft. But the result is correct only in case of the analytical fft. Please give me advice what should I do in discrete case.
clear all;
T=10;
N=256;
dt=T/(N-1);
t=linspace(-T/2,T/2,N);
f=exp(-t.^2);
g=sqrt(pi).*exp(-(pi^2).*t.^2);
F=fft(fftshift(f))*dt;
F1=F(1:N/2+1);
F2=F(N/2+1:N);
F=[F2,F1];
dnu=(N-1)/(N*T);
nuNyq=1/(2*dt);% Nyquist frequency
nu=-nuNyq+dnu*(0:N);
% plot(t,g);
% plot(nu(N/2+1-20:N/2+1+20),real(F(N/2+1-20:N/2+1+20)));
%------------ifft of analitical Fourier transform--------------------------
Z=ifft(ifftshift(g))*N*dt;
Z1=Z(1:N/2+1);
Z2=Z(N/2+1:N);
Z=[Z2,Z1];
figure
hold on;
plot(t,f);
plot(nu(N/2+1-20:N/2+1+20),real(Z(N/2+1-20:N/2+1+20)));
hold off;
%--------------------------------------------------------------------------
%----------------ifft of discrete Fourier transform------------------------
G=ifft(ifftshift((F)))*dt*N;
G1=G(1:N/2+1);
G2=G(N/2+1:N);
G=[G2,G1];
figure
hold on;
plot(t,f);
plot(nu(N/2+1-20:N/2+1+20),real(G(N/2+1-20:N/2+1+20)));
hold off;
%--------------------------------------------------------------------------

回答(1 个)

Youssef  Khmou
Youssef Khmou 2014-12-30
Try :
G(end)=[];
G=(sqrt(2*pi))*G;
figure; plot(t,f,'r',t,G,'g');

标签

Community Treasure Hunt

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

Start Hunting!

Translated by