Hi, I would appreciate if someone could explain what exactly this scaling algorithm does?
Calibration of Sensor Data
- Edited
First a general explanation of some relevant pd quirks:
- In the various
[f $1]
,[f $2]
,[f $3]
,[f $4]
, the dollar sign variable refers to the value of the respective creation argument of the patch (note that they assume this meaning only within objects, while within messages they mean something different). So if this abstraction is calledmyabs.pd
and you create an object in a parent patch as:
then[myabs 10 20 30 40]
$1
will be 10,$2
will be 20,$3
will be 30 and$4
will be 40. If any are omitted, they will be 0. - The loadbang is used to provide default values for the various operators which can be overridden with inputs from the inlets after creation.
[t a a]
means to pass the argument received via the inlet out of the rightmost outlet first and then out of the leftmost outlet[t b a]
is used when a float goes into the right (inactive) inlet of a[pack f f]
: this way when this value comes in, a bang is sent to the[pack f f]
which forces it to send the list out of its output.- The idiom that sends a list of floats into one of the operators, e.g.:
is equivalent to sending the second element of the list to the right inlet followed by the first argument in the left inlet, i.e.: the operator is applied to the two numbers. In the example just above means that that the output of[10 3( | [- ]
[-]
is10 - 3
, that is 7. - in your code, the
[$1 $2(
messages are useless, because they don't transform in any way the output of[pack f f]
Below we consider the inlets as numbered 0 to 4 from left to right. If a value for inlet N
has not been provided yet, the patch will use the corresponding [f $N]
provided at creation time, or 0
if the argument has not been provided
Here's what's happening in your patch:
val = inlet0 - inlet1
val = val / (inlet1 - inlet2)
val = val * (inlet3 - inlet4)
val = val + inlet3
This is kind of hard to understand for me because the way they used the signs is not particularly intuitive so we can play with the signs in the second and third line and rewrite it, equivalently, as:
val = inlet0 - inlet1
val = val / (inlet2 - inlet1)
val = val * (inlet4 - inlet3)
val = val + inlet3
This means that inlet0 is mapped from the range "inlet1 to inlet2" to the range "inlet3 to inlet4". For instance, you can use it to map a value from the range 0 to 1 to the range 100 to 200:
[myabs 0 1 100 200]
. Then, sending in 0 will give you 100, sending in 0.5 will give you 150 and sending in 1 will give you 200. No clipping is applied.