Azzera filtri
Azzera filtri

How to use fft to find Fourier series coefficients

19 visualizzazioni (ultimi 30 giorni)
Ronald
Ronald il 26 Dic 2017
Risposto: Star Strider il 27 Dic 2017
I have a Gaussian function which is on an interval [a,b] and I want to represent it via a Fourier series. Unfortunately, I got stuck with the calculating the Fourier series coefficients using fft Matlab function. It would be great if someone can give me some insight. Here is the code:
clear all
n=8;
mu1=0.1
sigma1=0.2;
xMax=20*sigma1;
xMin=-xMax;
Nmax=round(2.^n);
%k=-Nmax:1:Nmax;
k=0:1:(Nmax-1);
xj=linspace(xMin,xMax,length(k));
testing=@(u) 1./(sqrt(2*pi)*sigma1).*exp(-0.5.*(u-mu1).^2./sigma1.^2);
tmpvalues=testing(xj);
Bk1x =1./length(xj).*fft(tmpvalues).*exp(-(2*pi*1i)./(xMin-xMax).*k.*xMin);
for ni=1:1:length(xj)
value1(ni)=real(sum(Bk1x.*exp((2*pi*1i)./(xMin-xMax).*k.*(xj(ni)))));
end
plot(value1)
In the meantime, when should I use fftshift as I don't have a clue to use this command even though I read the documentation of it.

Risposte (1)

Star Strider
Star Strider il 27 Dic 2017
First I do not understand what you are doing in this assignment:
Bk1x =1./length(xj).*fft(tmpvalues).*exp(-(2*pi*1i)./(xMin-xMax).*k.*xMin);
So I would just use:
Bk1x = fft(tmpvalues)/length(xj);
This will give you a complex result. To understand how the complex result relates to the sin and cos transforms, see Wikipedia: Relation with complex exponentials (link). There are related Wikipedia links, including Fourier transform (link) and Product-to-sum and sum-to-product identities (link). (Wikipedia explains it much better than I can.)
Second With respect to this question:
‘In the meantime, when should I use fftshift as I don't have a clue to use this command even though I read the documentation of it.’
Use it to plot a two-sided Fourier transform. It puts the centre (or zero Hz) frequency in the centre of the plot. (You have to create a matching frequency vector yourself to plot it against. That vector goes from -Fn to +Fn, where ‘Fn’ is the Nyquist frequency, or half the sampling frequency, Fs/2.) I rarely find the two-sided Fourier transform useful, and instead plot the one-sided Fourier transform as described in this documentation for the fft (link) function.
All good signal processing textbooks (for both discrete and continuous signal processing and filter design) discuss discrete and continuous Fourier transforms in detail. I encourage you to search these out and read them on your own. A good source for relevant titles are university course requirement sites that you can find online. You can also ask professors at your local university for recommendations.

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by