Filter löschen
Filter löschen

Recover gaussian by using fft and ifft.

1 Ansicht (letzte 30 Tage)
Mikhail
Mikhail am 30 Dez. 2014
Beantwortet: Youssef Khmou am 30 Dez. 2014
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;
%--------------------------------------------------------------------------

Antworten (1)

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

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by