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

Expert 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 ?

Looking for reliable MATLAB assignment help? Our expert MATLAB tutors deliver high-quality, easy-to-understand solutions tailored to your academic needs. Whether you're studying at Monash University, the University of Sydney, UNSW, or the University of Melbourne, we provide trusted MATLAB assistance to help you excel. Contact us today for the best MATLAB solutions online and achieve academic success!

MATLAB Assignment Help Services

Personalized Tutoring: Get one-on-one guidance from our MATLAB experts. Whether you're tackling basic concepts or advanced algorithms, we provide clear, step-by-step explanations to help you master MATLAB with confidence.

Assignment Assistance: Struggling with tight deadlines or complex assignments? Our team offers end-to-end support, from problem analysis to code development and debugging, ensuring your assignments meet the highest academic standards.

Project Development: Need expert help with your MATLAB research project? We assist in designing and implementing robust solutions, covering project planning, data collection, coding, simulation, and result analysis.

Coursework Support: Enhance your understanding of MATLAB with our comprehensive coursework assistance. We help you grasp lecture concepts, complete lab exercises, and prepare effectively for exams.

Thesis and Dissertation Guidance: Incorporate MATLAB seamlessly into your thesis or dissertation. Our experts provide support for data analysis, modeling, and simulation, ensuring your research is methodologically sound and impactful.

Contact us on WhatsApp for MATLAB help

Contact us on Telegram for MATLAB solutions