-
Notifications
You must be signed in to change notification settings - Fork 3
/
DynamicScaledData.sc
64 lines (54 loc) · 1.08 KB
/
DynamicScaledData.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// DynamicScaleSystem is dynamically scaling a system of SensorData
/// created for Schwelle, www.schwelle.org
/// (c) 2007, Marije Baalman
DynamicScaleSystem{
var <data;
*new{ |data|
^super.new.init( data );
}
init{ |dat|
data = dat ? Array.fill( 5, {DynamicScaleData.new} );
}
test{
var maxscale = 0;
var minscale = 100000;
data.do{ |it,i|
it.test;
if ( maxscale < it.scale, { maxscale = it.scale } );
if ( minscale > it.scale, { minscale = it.scale } );
};
data.do{ |it,i|
it.scale = minscale;
};
}
output{
^data.collect{ |it| it.output };
}
}
/// DynamicScaleData is dynamically scaling one set of SensorData.
DynamicScaleData{
var <>data;
var <>scale = 1;
var <>top = 1.1;
var <>bottom = 0.9;
var <>scalefact = 0.75;
*new{ |data|
^super.new.init( data );
}
init{ |dat|
data = dat ? SensorData.new;
}
test{
if ( data.fluctuation > top,
{
scale = scalefact / data.longStdDev;
});
if ( data.fluctuation < bottom,
{
scale = scalefact / data.longStdDev;
});
}
output{
^(data.shortStdDev * scale)
}
}