Message Boards Message Boards

0
|
18664 Views
|
9 Replies
|
7 Total Likes
View groups...
Share
Share this post:

What is the expression for the periodic rectangular function?

Posted 10 years ago

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!

enter image description here

POSTED BY: Felix K
9 Replies
Posted 10 years ago

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}]

enter image description here

POSTED BY: David Keith
Posted 10 years ago

That's concise indeed, and so it is conceptually. It is a pleasure reading it. Thanks a lot!

POSTED BY: Felix K

Very clever and useful hack. Thank you for the code.

POSTED BY: Jesse Sheinwald

There are a lot of different representations possible for a lot of different purposes. So the answer might really depend. A clean way of doing it is to use SawtoothWave

This spends 3/4ths of it's time under 0: SawtoothWave[x] - 3/4

This spends half of it's time under 0: SawtoothWave[x] - 1/2

This spends a quarter of it's time under 0: SawtoothWave[x] - 1/4

So you can use UnitStep[SawtoothWave[x] - p] where p is the proportion of the function that should be 0. If you want it expanded you can always divide x by how much you want the function stretched out by.

POSTED BY: Sean Clarke

To illustrate Sean's idea:

Manipulate[Plot[UnitStep[SawtoothWave[x] - p], {x, -1, 2}, Filling -> 0], {{p, .2}, .1, .9}]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 10 years ago

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!

POSTED BY: Felix K
Posted 10 years ago

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.

POSTED BY: Felix K
Posted 10 years ago

You might find the Math World reference http://mathworld.wolfram.com/SquareWave.html of use. Mathematica code is included there

POSTED BY: Brett A Collins
Posted 10 years ago

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!

POSTED BY: Felix K
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract