I am trying to write my own Matlab code to sample a Gaussian function and calculate its DFT, and make a plot of the temporal Gaussian waveform and its Fourier transform.
According to the FT pair:
\$ e^{-at^2} \iff \sqrt{\frac{\pi}{a}} e^{- \pi^2 \nu^2 /a}, \$
The FT of a Gaussian is a Gaussian, and it should also be a real function.
So here is my graph:
So, why is my FT a flat line instead of being Gaussian?
And why is it that when I plot the argument of the DFT, the imaginary part is nonzero? Shouldn't the FT be real?
Any help would be greatly appreciated.
Here is my code:
clear; clf; clc;
a=5;
n=50; % Length of DFT
k=[-n:1:n];
x=exp(-a.*k.^2); % Gaussian function
subplot(221);
plot(k,x);grid;
axis([1.5,n,-max(-x),max(x)]);
xlabel('Data waveform');
hold on; plot(k,x,'o'); hold off;
xx=fft(x)/n;
subplot(222);
plot(k, abs(xx));grid;xlabel('Transformed, magnitude');
axis([1,n,0,1]);
hold on; plot(k,abs(xx),'o'); hold off;
subplot(223);
plot(k, real(xx));grid;xlabel('Transformed, real');
hold on; plot(k, real(xx), 'o'); hold off;
axis([1,n,-1,1]);
subplot(224)
plot(k,imag(xx)); grid;
axis([1,n,-1,1]);
xlabel('Transformed, imaginary');
hold on; plot(k, imag(xx), 'o'); hold off;
figure(gcf);
x=exp(-a.*k.^2);
. I did try lower \$ a\$ values but I am still getting the same features on the graph. \$\endgroup\$