Fourier Series—Square Wave

Author

Eric W. Weisstein
August 17, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Calculus/FourierSeriesSquareWave.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/FourierSeriesSquareWave.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Square Wave

V6

f[x_]:=2(UnitStep[x/L]-UnitStep[x/L-1])-1

FourierA[0,f[x],{x,L}]

FourierA[n,f[x],{x,L}]

FullSimplify[FourierB[n,f[x],{x,L}]]

Table[-(-1+(((-1))^n))/2,{n,10}]

Sum[-((2 (-1+(((-1))^n)))/(n π))Sin[n x π],{n,∞}]

FullSimplify[%,x∈Reals]

(4/π)Sum[(1/n)Sin[((n π x)/L)],{n,1,∞,2}]

FullSimplify[%]

Plot[((2 I (ArcTanh[(E^(-I π x))]-ArcTanh[(E^(I π x))]))/π),{x,-2,2},Exclusions->None]

Plot[SquareWave[x/2],{x,-2,2}]

FunctionExpand[SquareWave[x/2]]

FullSimplify[SquareWave[x/2]-((2 I (ArcTanh[(E^(-I π x))]-ArcTanh[(E^(I π x))]))/π),x∈Reals]

Table[((2 I (-ArcTanh[(E^(-I π x))]+ArcTanh[(E^(I π x))]))/π)+SquareWave[(x/2)]/.x->RandomReal[{0,10}],{20}]//Chop//Union

Function[x,{SquareWave[x/2],((2 I (-ArcTanh[(E^(-I π x))]+ArcTanh[(E^(I π x))]))/π)}]/@{-2,-1,0,1,2}

V7

FourierCosCoefficient[SquareWave[x],x,n]

Table[FourierCosCoefficient[SquareWave[x],x,n],{n,0,4}]

FourierSinCoefficient[SquareWave[x],x,n]

Table[FourierSinCoefficient[SquareWave[x],x,n],{n,4}]

Plot

(series=Rest[FoldList[Plus,0,Table[Sin[n Pi x]/n,{n,1,9,2}]]]4/Pi)//ColumnForm//TraditionalForm

Plot[Evaluate[{
2UnitStep[x]-2UnitStep[x-1]+2UnitStep[x-2]-1,
Sequence@@series
}],{x,-.02,2.02},
PlotStyle->{Thickness[.01],Red,Yellow,Green,Blue,Violet},
PlotRange->All,AxesLabel->TraditionalForm/@{x,f[x]},Ticks->{Transpose[{Range[4]/2,TraditionalForm/@(Range[4]L/2),Table[Automatic,{4}]}],Automatic}]