Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Matlab FFT for gaussian function

Date: 2022-11-25 12:42:21

I am trying to obtain gaussian curve by using matlab's fft. The problem is that in one case my attemp to reduce noise by dividing F=dt.*F./exp(-1i.*nu.*T/2) is not working (img 1) and in the second case if I am trying to take absolute value of fft result's I dont have decent scale in graph (img 2). 

 

N=512;
T=10;
dt=T/(N-1);
t=linspace(-5,5,N);
f=exp(-t.^2);
F=fft(f);

F1=F(1:N/2+1);
F2=F(N/2+1:N);
F=[F2,F1];

dnu=(N-1)/(N*T);
nuNyq=1/(2*dt);
nu=-nuNyq+dnu*(0:N);
F=dt.*F;
%F=dt.*F./exp(-1i.*nu.*T/2);


y=linspace(-5,5,N);
F2=pi.^(1/2).*exp(-y.^2/4);

hold on
plot(y,F2); 
%plot(nu,real(F),'r');
plot(nu,abs(F),'r');
legend('analiticFT','FFT')
xlim([-5 5])
hold off 

img. 1

img. 2

Answer: 

It seems the scaling in your formula for the analytic Fourier Transform is not quite correct. According to this Fourier Transform table on Wikipedia, the transform of the continuous time-domain signal

y\left(t\right) = e^{-a t^2}

is

Y\left(f\right) = \sqrt{\frac{\pi}{a}} \cdot e^{-\frac{\left(\pi f\right)^2}{a}}

where in your case a=1. Correspondingly, you should compare the FFT of the time domain signal 

 

t=linspace(-5,5,N);
f=exp(-t.^2); 

with the analytic Fourier Transform 

 

F2 = sqrt(pi)*exp(-(pi*y).^2); 

So, plotting the comparison with:

 

hold off;
plot(y,F2); 
hold on;
plot(nu,abs(F),'r');
legend('analiticFT','FFT')
xlim([-5 5]) 

yields:

enter image description here

Now that we have establish a proper basis for comparison, we can look at why you are getting the oscillations in img 1. Simply put, the reference Gaussian pulse f=exp(-t.^2); you have generated has a peak at t=0. The corresponding "zero" discrete time instant is naturally the first index in the array (index 1). However in your array, this peak appears at index N/2. Under the Shift theorem, this causes an additional exp(-pi*j*k) term in the frequency domain, responsible for the oscillations you are seeing. To fix this, you should shift back your Gaussian pulse with ifftshift

 

F=fftshift(fft(ifftshift(f))); 

 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com