The function I am referring to is as shown below, the height of the boxes being h, the length of each of them a, and the length of each gap b.
How can I write an expression for it in Mathematica (preferably most efficiently)?
Thanks a lot!
This also works:
pulseTrain[x_, h_, a_, b_] := If[Mod[x, a + b] < a, h, 0] Plot[pulseTrain[x, 1, 3, 2], {x, 0, 20}]
That's concise indeed, and so it is conceptually. It is a pleasure reading it. Thanks a lot!
Very clever and useful hack. Thank you for the code.
To illustrate Sean's idea:
Manipulate[Plot[UnitStep[SawtoothWave[x] - p], {x, -1, 2}, Filling -> 0], {{p, .2}, .1, .9}]
In reply to Vitaliy Kaurov:
Thank you very much for the code and demonstration! I am new to Mathematica, so the code is really of great help to me!
Replying to Sean Clarke:
Thank you very much! Your idea is a hundred times better than what I originally thought, which was to sum an infinite number of HeavisidePi (square pulse) functions with different offsets.
You might find the Math World reference http://mathworld.wolfram.com/SquareWave.html of use. Mathematica code is included there
The SquareWave function has equal up- and down-periods, which is not precisely what I had in mind, but thank you for the reply, since I've learned a new function!