How to create a rectangle wave (duty cycle $\ne$ 50 %)?

See if this helps

squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)]

Plot[squareWave[t, 10, 0.8], {t, -2, 21}]

Mathematica graphics


What I'd do:

With[{d = 1/3}, (* duty cycle *)
 Plot[(1 + (-1)^Floor[x] (-1)^Floor[d - x])/2, {x, -5, 5}, 
  Axes -> {False, True}, Frame -> True, PlotPoints -> 105, 
  PlotRange -> {-5/4, 5/4}]]

square wave with duty cycle 1/3

If you absolutely must use the SquareWave[] function, there is the identity

$$\text{SquareWave}[\{a,b\},x]=\frac{a+b}{2}+\frac{b-a}{2}(-1)^{\lfloor 2 x\rfloor}$$

I'll leave the conversion up to you.


You can make any duty cycle you want by combining TriangleWave and Sign:

Sign[TriangleWave[t] - a]

As a goes from +/-1, you get all possible duty cycles. To see this:

Manipulate[Plot[Sign[TriangleWave[t] - a], {t, -3, 3}, 
      Exclusions -> None], {a, -1, 1}]

enter image description here