Specifications

6.2 Periodic functions 63
Wrapping ranges
wrap~
*~ 2
phasor~ 670
pd grapha
B
pd grapha
A
fig 6.12: Wrap-
ping
The
wrap~
object provides just such a behaviour. It is like
a signal version of
mod
If the input a to
wrap~
exceeds 1.0
then it returns a −1.0. And if the input exceeds 2.0 it gives
us a − 2.0. Wrap is the “fractional” pa rt of a number in
relation to a division, in this case the unit 1, a − ⌊a⌋. Let’s
say we have a normalised phasor which is cycling up once per
second. If we pass it through
wrap~
it will be unaffected. A
normalised phasor never exceeds 1.0 and s o passes through
unchanged. But if we double the amplitude of the phasor by
multiplying by 2.0 and then w rap it something else happens
as seen in Fig . 6.12.
wrap~
vline~
0, 1 10
r b
*~ 3
pd grapha
A
fig 6.13: Wrap-
ping a line
Imagine the graph of a in a range of 0.0 to 2.0 drawn on
tracing paper then the paper is cut into two strips of height
1.0 which are placed on top of one another. Each time the
phasor passes 1.0 it is wrapped back to the bottom. Conse-
quently the frequency doubles but it’s peak amplitude stays
at 1.0. This way we can create periodic functions from a
steadily gr owing input, so a line that rises at a constant rate
can be turned into a phasor with
wrap~
. Even more useful,
we can obtain an exact number of phasor cycles in a certain
time period by making the line rise at a particular rate. The
vline~
in Fig. 6.13 moves from 0.0 to 1.0 in 10ms. Multiplying
by 3 means it moves from 0.0 to 3.0 in 10ms, and wrapping it
produces three phasor cycles in a period of 1 0/3 = 3.333ms, giving a frequency
of 1/3.333 × 1000 = 300Hz.
Cosine function
cos~
phasor~ 100
pd grapha
B
pd grapha
A
fig 6.14: Cosine of a phasor
The reason for s aying that the phasor is the most
primitive waveform is that even a cosinusoidal oscil-
lator can be derived from it. Notice in Fig. 6.14 that
although the phas or is always positive in the range
0.0 to 1.0 (unipolar) the
cos~
operation produces a
bipolar waveform in the range −1.0 to 1.0. One com-
plete period of the cosine corresponds to 2π, 360
◦
, or
in rotation normalised form 1.0. When the phasor is
at 0.0 the cosine is 1.0. When the phasor is at 0.25
the cosine crosses zero moving downwards. It reaches
the bottom of its cy c le when the phasor is 0.5. So
there are two zero crossing points, one when the pha-
sor is 0.25 and another when it is 0.75. When the
phasor is 1.0 the cosine has completed a full cycle and returned to its original
position.