MATH529L Lab01: Fourier Series

Construction of Fourier Series

Consider a periodic function with period 2p

Consider a sequence of periodic functions, starting from a step function with discontinuities inside the domain of periodicity and at the end points, to a smooth function.

Example 1

f(x)=0 for -π<x<0,f(x)=1,0≤x<π

p1[x_]:=x - Floor[(x+π)/(2π)](2π);
f1[x_]:= If[p1[x]<0,0,1];

Plot[f1[x],{x,-5π,5π}]

Plot[f1[x],{x,-π,π}]

Example 2

f(x)=0 for -π<x<0,f(x)=(x^2),0≤x<π

p2[x_]:=x - Floor[(x+π)/(2π)](2π);
f2[x_]:= If[p2[x]<0,0,((p2[x])^2)];

Plot[f2[x],{x,-5π,5π}]

Plot[f2[x],{x,-π,π}]

Example 3

f(x)=(π^2)-(x^2) for -π<x<π

p3[x_]:=x - Floor[(x+π)/(2π)](2π);
f3[x_]:=(π^2)- ((p3[x])^2);

Plot[f3[x],{x,-5π,5π}]

Plot[f3[x],{x,-π,π}]

Example 4

f(x)=sin(cos(x))+cos(sin(x))

f4[x_]:=Sin[Cos[x]]+Cos[Sin[x]];

Plot[f4[x],{x,-5π,5π}]

Plot[f4[x],{x,-π,π}]

Example 5

f(x)=1+sin(x)+10 cos(x)+(10^2) sin(2x)+(10^3) cos(3x)

f5[x_]:=1+Sin[x]+10 Cos[x]+(10^2)Sin[2x]+(10^3)Cos[3x];

Plot[f5[x],{x,-5π,5π}]

Plot[f5[x],{x,-π,π}]

Fourier Series Coefficients

Define scalar product for Fourier series with [-π,π] interval of periodicity

ScProd[f_,g_] :=(1/(2π)) Integrate[ f Conjugate[g],{x,-π,π}];

NScProd[f_,g_] :=(1/(2π)) NIntegrate[ f Conjugate[g],{x,-π,π}];

Fcoef[f_, n_] :=Table[ ScProd[f,Exp[I k x]],{k,-n,n}];

NFcoef[f_, n_] :=Table[ NScProd[f,Exp[I k x]],{k,-n,n}];

cf1 = Fcoef[f1[x],3]

Off[NIntegrate::slwcon,NIntegrate::ncvb];
cf1N = Chop[NFcoef[f1[x],3]]

F[x_]={f1[x],f2[x],f3[x],f4[x],f5[x]};

nTerms=10;
cf = Chop[Map[ NFcoef[#, nTerms]& , F[x]]];

RowH = Table[(Subscript[c, k]),{k,-nTerms,nTerms}];
ColH = Table[ "f" <> ToString[k],{k,1,5}];

TableForm[Transpose[cf],TableHeadings->{RowH,ColH}]

Table[(k-1-(Length[cf1]-1)/2), {k,1,Length[cf1]}]

fct[c_,k_]:=(k-1-(Length[c]-1)/2)

Fseries[c_] := Sum[ c[[k]] Exp[I fct[c,k]  x] , {k,1,Length[c]}]

f5[x]

Chop[ComplexExpand[Simplify[Fseries[cf[[5]]]]]]

fseries = Map[Chop[ComplexExpand[Simplify[Fseries[#]]]]&,cf]

Convergence of Fourier Series

cmpplt[k_]:=Plot[{fseries[[k]],F[x][[k]]},{x,-π,π},Frame->True,GridLines->Automatic,PlotStyle->{Red,Blue},PlotLabel->"Convergence of Fourier Series"];

Table[cmpplt[k],{k,1,5}]

convplt=GraphicsGrid[{{cmpplt[1],cmpplt[2]}}]

SetDirectory[NotebookDirectory[]]

Export["FSeriesConvPlot.pdf",convplt]

Questions to Investigate

Gather all the intermediate steps above into a single function producing a plot of the approximation of f given n the number of terms in the Fourier series

FConvPlot[ f_,n_ ] := Module[ {c,F,plt},
c = NFcoef[f,n];
F=Chop[ComplexExpand[Simplify[Fseries[c]]]];
plt=Plot[{F,f},{x,-π,π},Frame->True,GridLines->Automatic,PlotStyle->{Red,Blue},PlotLabel->"Convergence of Fourier Series"];
Return[plt]
]

Study convergence of Fourier series of a step function

Manipulate[FConvPlot[f1[x],k],{k,1,11,2}]

Question 1

Construct an animation of the convergence of a Fourier series for f1, f2, f3

Question 2

Construct a plot of |(Subscript[c, n])|, the absolute value of the Fourier series coefficients, as a function of the index n using linear axes. Repeat using a logarithmic axis, i.e., log|(Subscript[c, n])|.

Question 3

Construct f6(x)=f4(x)+f1(f5(x)). Present a convergence study (n=5,10,15,20).