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 ?

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!

Our Comprehensive Matlab Assignment Help Services

Personalized Tutoring:Our team of MATLAB experts offers one-on-one tutoring sessions tailored to your specific needs. Whether you’re struggling with basic concepts or advanced algorithms, we provide clear, step-by-step guidance to help you understand and master MATLAB.

Assignment Assistance:Facing tight deadlines or complex assignments? We’re here to help! From initial problem analysis to code development and debugging, we offer full-spectrum support to ensure your assignments meet the highest standards.

Project Development: Need help with a research project? Our specialists can assist you in designing and implementing robust MATLAB solutions. We cover everything from project planning and data collection to coding, simulation, and result analysis.

Coursework Support: We provide comprehensive support for your coursework, helping you understand lectures, complete lab exercises, and prepare for exams. Our goal is to ensure you grasp the core principles and practical applications of MATLAB.

Thesis and Dissertation Guidance:Writing a thesis or dissertation? Our experts can assist you in incorporating MATLAB for data analysis, modeling, and simulation. We help you develop a strong methodological framework and ensure your research stands out.

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com