Group Abstract Group Abstract

Message Boards Message Boards

Incorrect plot range when range is specified with unit

Posted 4 years ago

I was trying to make a square wave function that represents the pixel clock of our instrument.

PixelClock[pixelTime_, gapTime_] := 
 Piecewise[{{1, Mod[#, pixelTime] < (pixelTime - gapTime)}}, 0] &

I would prefer it can produce a function that takes time quantity as input, for example:

pc1 = PixelClock[Quantity[20, "Microseconds"], 
  Quantity[2, "Microseconds"]]

Running it with 1-100 microseconds as a list gives the expected answer.

pc1[Quantity[#, "Microseconds"]] & /@ Range[100]

Out[3]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1}

However, when I try to plot it, things get strange. enter image description here

I would expect the first and the second plots to be equivalent. But they are not... I then realized if I reduce the value from 100 to 0.0001, the plot would look "correct" but is in fact using the wrong range. Is this a bug?

POSTED BY: Chen Huang
3 Replies
Posted 4 years ago
POSTED BY: Chen Huang
Posted 4 years ago
POSTED BY: Brad Klee
Posted 4 years ago

In case you're interested...

Square wave is kind of boring function to me, honest opinion, but they love it in the tech sector and the lab. I asked my dad about your question and he said it could be a 555 timer. However, in next gen on a rasbperry pi somewhere, there would need to be more complicated functions. Thank you too.

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