Square Wave

Author

Eric W. Weisstein
March 26, 2010

This notebook downloaded from http://mathworld.wolfram.com/notebooks/GeneralizedFunctions/SquareWave.nb.

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

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

Built-In

V6

SquareWave2:=Sign[Sin[2 Pi #]]&

Plot[SquareWave2[x],{x,-2,2}]

SquareWave2[0]

V7

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

Plot[SquareWave[x],{x,-2,2},Exclusions->None]

SquareWave[0]

Identities

dif=SquareWave[x]+SquareWave[-x]

FunctionExpand[dif]

FullSimplify[dif]

FullSimplify[dif,#[x,0]]&/@{Less,Equal,Greater}

Function[x,SquareWave[x]+SquareWave[-x]]/@{-1,0,1/2,1}

FullSimplify[dif,x∈Reals]

Special Values

SquareWave/@{0.,0,1/2,.5}

FunctionExpand

FunctionExpand[SquareWave[x],x∈Reals]

FunctionExpand[SquareWave[x],x∈Reals]/. {x->{0,1/2,1,3/2}}

SquareWave[x]/. {x->{0,1/2,1,3/2}}

Plot

SquareWave[x_,A_:1,T_:1,x0_:0]:=((2 I (ArcTanh[(E^(-2I π (x-x0)/T))]-ArcTanh[(E^(2I π (x-x0)/T))]))/π)A

Plot[SquareWave[x,.5,2,.1],{x,-.2,5},PlotStyle->Red,AxesLabel->TraditionalForm/@{x,(Subscript[S, 1/2,2])[x]}]

SquareWave2[x_,A_:1,T_:1,x0_:0]:=A Sign[Sin[2π (x-x0)/T]]

Plot[SquareWave2[x,.5,2,.1],{x,-.2,5},PlotStyle->Red]

SquareWave3[x_,A_:1,T_:1,x0_:0]:=A(-1)^Floor[2(x-x0)/T]

Plot[SquareWave3[x,.5,2,.1],{x,-.2,5},PlotStyle->Red]

SquareWave4[x_,A_:1,T_:1,x0_:0]:=(2Sum[UnitStep[(x-2n)/(T/2)-x0]-UnitStep[(x-2n)/(T/2)-1-x0],{n,-2,2}]-1)A

Plot[SquareWave4[x,.5,2,.1],{x,-.2,5},PlotStyle->Red]

Combinations of square waves

Plot[SquareWave3[x,.5,2,0]+SquareWave3[x,.5,2,1],{x,-.2,5},PlotStyle->Red]

Plot[SquareWave3[x,.5,2,0]+SquareWave3[x,.5,2,.5],{x,-.2,5},PlotStyle->Red]

Analytic Fourier Series Sum

FourierA[n,2(UnitStep[x/L]-UnitStep[x/L-1])-1,{x,0,2L}]

FourierB[n,2(UnitStep[x/L]-UnitStep[x/L-1])-1,{x,0,2L}]

FullSimplify[%,n∈Integers&&n≥0]

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

Table[(4/(n π))If[EvenQ[n],0,1],{n,10}]

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

FullSimplify[%41,x∈Reals]

PowerExpand[%]

Simplification

TrigToExp[(ArcTanh[(E^(-I π x))]-ArcTanh[(E^(I π x))])]

FullSimplify[%]

FullSimplify[(((1-(E^(I π x)))(1+(E^(-I π x))))/((1-(E^(-I π x)))(1+(E^(I π x)))))]

2I Log[-1]/(2π)

SeriesCoefficient

SeriesCoefficient[SquareWave[x],{x,0,n}]

Series[SquareWave[x],{x,0,10}]

FullSimplify[Series[((2 I (ArcTanh[(E^(-I π x))]-ArcTanh[(E^(I π x))]))/π),{x,0,10}],0<x<3]

SeriesCoefficient[((2 I (ArcTanh[(E^(-I π x))]-ArcTanh[(E^(I π x))]))/π),{x,0,n}]

Derivatives

D[UnitStep[x],x]//InputForm

D[SquareWave[x],x]

Integrate

Integrate[UnitStep[x],x]

Integrate[SquareWave[x],x]

Integrate[SquareWave[x],{x,0,10}]

Integrate[FunctionExpand[SquareWave[x]],{x,0,1/2}]

NIntegrate[FunctionExpand[SquareWave[x]],{x,0,1/2}]

Integrate[SquareWave[x],{x,0,t},Assumptions->t>0]

Plot[Integrate[SquareWave[x],{x,0,t}],{t,-2,2}]

Limit

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

Limit[SquareWave[x],x->0,Direction->#]&/@{-1,1,Automatic}

Limit[UnitStep[x],x->0,Direction->#]&/@{-1,1,Automatic}

Maximize

Maximize[SquareWave[x],x]

bug(439979): Maximize[Sin[x], x] could return {1, {x -> Pi/2}} instead of -95 Pi/2 [used to prior to V11.2)

Maximize[Sin[x],x]

Maximize[UnitStep[x],x]