Extension to Mathematica/WL
SquareWave[ ] and TriangleWave[ ]

Explanation

The Mathematica built in “Wave” functions only support 50% duty cycle for
SquareWave[ ] as well as for TriangleWave[ ].
Here we present compatible versions with adjustable duty cycle.
The new function PulseWave[ ] generates a pulse sequence with adjustable duty cycle,
which defaults to and thus includes the SquareWave[ ] functionality.
GeneralTriangleWave[ ] on the other hand includes the TriangleWave[ ] functionality with the possibility to generate non symmetric triangle pulse sequences. Again the TriangleWave[ ] functionality is included.
Moreover also the SawtoothWave[ ] functionality is included, although the latter is not exactly compatible with respect to the default arguments.

Implementation


Examples

In[]:=
PlotPulseWave
1
2
,x,SquareWave[x],{x,-2,2},PlotStyle{Red,{Black,Dashed}}//Framed//(pLabeled[p,"PulseWave vs. SquareWave"])
Out[]=
PulseWave vs. SquareWave
In[]:=
PlotPulseWave
1
4
,x,{x,-2,2}//​​Framed//(pLabeled[p,"25% duty cycle"])
Out[]=
25% duty cycle
In[]:=
PlotGeneralTriangleWave
1
2
,x,TriangleWave[x],{x,-2,2},PlotStyle{Red,{Black,Dashed}}//​​Framed//(pLabeled[p,"GeneralTriangleWave vs. TriangleWave"])
Out[]=
GeneralTriangleWave vs. TriangleWave
In[]:=
PlotGeneralTriangleWave{10,12},
1
4
,x,{x,-2,2}//​​Framed//(pLabeled[p,"25% asymmetric"])
Out[]=
25% asymmetric
In[]:=
Plot[GeneralTriangleWave[0,x],{x,-2,2}]//​​Framed//(pLabeled[p,"Sawtooth mode by 0% duty cycle"])
Out[]=
Sawtooth mode by 0% duty cycle