Solid State Physics, 
Eric Toberer
Colorado School of Mines

Fourier Series & Transforms

Fourier Series

Let us look at some common periodic functions (step, sawtooth, etc) and how these can be approximated using a finite Fourier series.  The code is pretty un-readable but the visualization is useful.  
Recall that a Fourier Series can be expressed in complex exponential form:
(Subscript[s, N])(x)  = (∑_(n=-N)^N)(Subscript[c, n])(e^(i n k x ))
but here we simply consider the real component.

ClearAll["Global`*"]

Manipulate[Plot[{PeriodicExtension[k[[1]],x],Evaluate[k[[2]]+Sum[k[[3]] Sin[n x]+k[[4]] Cos[n x],{n,1,m}]]},{x,-r,r},Axes->{True,True},PlotStyle->{{Thickness[0.003],Black},{Thickness[0.003],Blue}},Filling->{1->{{2},{Yellow,Orange}}},ImageSize->{500,400},ImagePadding->30],{{k,{Sign,0,1/(Pi*n)*(1-2 Cos[n*Pi]+1),0},"function"},{{Sign,0,1/(Pi*n)*(2-2 Cos[n*Pi]),0}->"step",{#&,0,2 (-1)^(n+1)/n,0}->"sawtooth",{#^2&,π^2/3,0,(4 (-1)^n)/n^2}->"parabola",{(#-Pi) (#+Pi) (#-1)&,(2 π^2)/3,(12 (-1)^n)/n^3,-((4 (-1)^n)/n^2)}->"cubic",{(Sin[#] UnitStep[#])&,1/Pi,KroneckerDelta[n,1]/2,If[n==1,0,(-((1+(-1)^n)/((-1+n^2) π)))]}->"half-wave rectifier"}},{{m,3,"number of terms"},1,20,1,Appearance->"Labeled"},{{r,Pi,"x range"},Pi,5*Pi,Pi,Appearance->"Labeled"},Initialization:>{(PeriodicExtension[g_,x_]:=If[Abs[x]<Pi,g[x],PeriodicExtension[g,x-2 Sign[x] Pi]])}]
(*Credit: Alain Goriely  URL: http://demonstrations.wolfram.com/FourierSeriesOfSimpleFunctions/*)

Fourier Transforms

Fourier Transform of a periodic function

We are given several sine functions with different amplitudes and periods.  Like we saw before, we can represent periodic functions using a linear combination of other periodic functions (namely sines and cosines).  In this class, we’ll use fourier transforms to get a “global view” on the coefficents used in fourier series. 

Let’s start by building a periodic function from a set of four sine waves.

f1[x_]:=10*Sin[1 x];
f2[x_]:=4*Sin[2x];
f3[x_]:=3Sin[3x-2];
f4[x_]:=1Sin[6 x+2];

PeriodicFunction[x_]:=f1[x]+f2[x]+f3[x]+f4[x];

Lets see what the resulting function looks like:

Grid[{{Plot[PeriodicFunction[x],{x,-10,10},PlotLabel->"Periodic function",ImageSize->Medium,BaseStyle->{FontSize->15}],
Plot[{f1[x],f2[x],f3[x],f4[x]},{x,-10,10},PlotLegends->LineLegend["Expressions"],PlotLabel->"Components",ImageSize->Medium,BaseStyle->{FontSize->15}, PlotRange-> Full]}
}]

Now we consider the Fourier transform of this sum:

fakeDelta[k_]:=Exp[k^2*-500]*5/7*(Sqrt[2]) (*Note, fakeDelta is simply a replacement for the delta function which allows mathematica to easily plot the fourier transform*)
ff=FourierTransform[PeriodicFunction[x],x,k]/.DiracDelta->fakeDelta;
Plot[Abs[ff],{k,0,10},PlotRange->All,PlotLabel->"Fourier Transform",AxesLabel->{"k","Amplitude"},ImageSize->Medium,BaseStyle->{FontSize->15}]

The inversion machine

So, the fourier transform is a continuous analogue of a fourier series.  We can take it a step further, and look at how function representations in real and frequency space (inverse space) differ.
What patterns do you notice?

Manipulate[
gauss[x_]:=Exp[-x^2/λ];
ff2=FourierTransform[Exp[-x^2/λ],x,ω];
Grid[{{
Plot[Exp[-x^2/λ],{x,-5,5},PlotRange->{0,1},PlotLabel->"Real space",AxesLabel->{"x","Amplitude"},ImageSize->Medium,BaseStyle->{FontSize->15}],
Plot[ff2,{ω,-5,5},PlotRange->{0,2.5},PlotLabel->"Frequency space",AxesLabel->{"ω","Amplitude"},ImageSize->Medium,BaseStyle->{FontSize->15}]
}}],
{λ,1,10,Appearance->"Labeled"}]