Specifications

38 Using Pure Data
since the distr ibution of input numbers is uniform they are sent to one of three
outlets with 10%, 40% a nd 50% probability.
Delay cascade
del 100 del 100 del 100 del 100
fig 3.37: Delay cascade.
Sometimes we want a quick succession of bangs in a
certain fixed timing pattern. An easy way to do this
is to ca scade
delay
objects. Each
delay 100
in Fig. 3.37
adds a delay of 100 milliseconds. Notice the ab-
brieved form of the object name is used.
Last float and averages
t f b
f
3
2
t f b
f
12.5
+
/ 2
trigger f f
10 15
fig 3. 38: Last value and av-
eraging
If you have a stream of float values and want to
keep the previous va lue to compare to the current
one then the idiom shown on the left o f Fig. 3.38
will do the job. Notice how a trigger is employed to
first bang the last va lue stored in the float box and
then update it with the current value via the right
inlet. This can be turned into a simple “lowpass”
or averaging filter for float messages as s hown on
the right of Fig . 3 .38. If you add the previous value
to the current one and divide by two you obtain the average. In the example
shown the values were 10 followed by 15, resulting in (10 + 15)/2 = 1 2.5.
Running maximum (or minimum)
t f f
9
max 1e-21
35
fig 3.39:
Biggest
so far
Giving
max
a very small argument and connecting whatever passes
through it back to its right inlet gives us a way to keep track of the
largest value. In Fig. 3.39 the greatest past value in the stream has
been 35. Giving a very large argument to
min
provides the opposite
behaviour for tracking a lowest value. If you need to reset the max-
imum or minimum tracker just send a very large or sma ll float value
to the cold inlet to start again.
Float lowpass
38
* 0.1
+ * 0.9
37.26
fig 3.40: Low
pass for floats
Using only
*
and
+
as shown in Fig. 3.40 we can low pass
filter a stream of float values. This is useful to smooth data from
an external controller where values are occasionally anomalous.
It follows the filter equation y
n
= Ax
n
+ Bx
n1
. The strength
of the filter is set by the ratio A : B. Both A and B should be
between 0.0 and 1.0 and add up to 1.0. Note that this method
will not converge on the exact input value, so you might like to
follow it with
int
if you need numbers rounded to integer values.