Class: MultiExpSmoother
Defined in: src/sdk/math/MultiExpSmoother.ts:13
Applies time-weighted exponential smoothing (i.e. an exponential moving average) to a sequence of raw values and optionally uses smoothed estimates of velocity and acceleration to adjust the smooth value to compensate for trends in the raw input values.
When a new raw value is added to the sequence, it and the last smoothed value, with optional adjustments derived from estimated velocity and acceleration, are weighted according to the time elapsed since the last smoothed value was calculated (i.e. since the last raw value was added) and averaged. The calculation of the weighting is such that the weight of each raw value in the sequence decays exponentially with the "age" (i.e. time elapsed between when that value was added to the sequence and when the latest value was added to the sequence) of the value. Estimates of velocity and acceleration are also smoothed in the same manner.
Constructors
Constructor
new MultiExpSmoother(
tau
,tauVelocity?
,tauAccel?
,initial?
,initialVelocity?
,initialAccel?
,dtThreshold?
):MultiExpSmoother
Defined in: src/sdk/math/MultiExpSmoother.ts:40
Creates a new instance of MultiExpSmoother.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
tau | number | undefined | This smoother's time constant. The larger the constant, the greater the smoothing effect. A value less than or equal to 0 is equivalent to no smoothing. |
tauVelocity? | number | undefined | This smoother's time constant for estimated velocity. The larger the constant, the greater the smoothing effect applied to the estimated velocity. A value less than or equal to 0 is equivalent to no smoothing. If not defined, then this smoother will not estimate velocity. |
tauAccel? | number | undefined | This smoother's time constant for estimated acceleration. The larger the constant, the greater the smoothing effect applied to the estimated acceleration. A value less than or equal to 0 is equivalent to no smoothing. If this value or tauVelocity is not defined, then this smoother will not estimate acceleration. |
initial? | null | number | null | The initial smoothed value of the smoother. Defaults to null . |
initialVelocity? | null | number | null | The initial smoothed velocity estimate of the smoother. Ignored if tauVelocity is not defined. Defaults to null . |
initialAccel? | null | number | null | The initial smoothed acceleration estimate of the smoother. Ignored if tauVelocity or tauAccel is not defined. Defaults to null . |
dtThreshold? | number | Infinity | The elapsed time threshold, in seconds, above which this smoother will not smooth a new raw value. Defaults to infinity. |
Returns
MultiExpSmoother
Properties
dtThreshold
readonly
dtThreshold:number
=Infinity
Defined in: src/sdk/math/MultiExpSmoother.ts:47
The elapsed time threshold, in seconds, above which this smoother will not smooth a new raw value. Defaults to infinity.
tau
readonly
tau:number
Defined in: src/sdk/math/MultiExpSmoother.ts:41
This smoother's time constant. The larger the constant, the greater the smoothing effect. A value less than or equal to 0 is equivalent to no smoothing.
tauAccel?
readonly
optional
tauAccel:number
Defined in: src/sdk/math/MultiExpSmoother.ts:43
This smoother's time constant for estimated acceleration. The larger the constant, the greater the
smoothing effect applied to the estimated acceleration. A value less than or equal to 0 is equivalent to no
smoothing. If this value or tauVelocity
is not defined, then this smoother will not estimate
acceleration.
tauVelocity?
readonly
optional
tauVelocity:number
Defined in: src/sdk/math/MultiExpSmoother.ts:42
This smoother's time constant for estimated velocity. The larger the constant, the greater the smoothing effect applied to the estimated velocity. A value less than or equal to 0 is equivalent to no smoothing. If not defined, then this smoother will not estimate velocity.
Methods
forecast()
forecast(
t
):null
|number
Defined in: src/sdk/math/MultiExpSmoother.ts:179
Forecasts the smoothed value into the future based on the most recently calculated smoothed parameters (value, velocity, and acceleration). If velocity or acceleration has not been calculated (or is not part of this smoother's internal model), each will be treated as zero.
Parameters
Parameter | Type | Description |
---|---|---|
t | number | The time in the future (relative to the last calculated smoothed value) at which to get the forecasted value. |
Returns
null
| number
The forecast smoothed value at the specified time, or null
if a smoothed value has not yet been
calculated.
last()
last():
null
|number
Defined in: src/sdk/math/MultiExpSmoother.ts:58
Gets the last smoothed value.
Returns
null
| number
The last smoothed value, or null
if none exists.
lastAcceleration()
lastAcceleration():
null
|number
Defined in: src/sdk/math/MultiExpSmoother.ts:74
Gets the last smoothed acceleration.
Returns
null
| number
The last smoothed acceleration, or null
if none exists.
lastVelocity()
lastVelocity():
null
|number
Defined in: src/sdk/math/MultiExpSmoother.ts:66
Gets the last smoothed velocity.
Returns
null
| number
The last smoothed velocity, or null
if none exists.
next()
next(
raw
,dt
):number
Defined in: src/sdk/math/MultiExpSmoother.ts:86
Adds a new raw value and gets the next smoothed value. If the new raw value is the first to be added since this smoother was created or reset with no initial smoothed value, the returned smoothed value will be equal to the raw value.
Parameters
Parameter | Type | Description |
---|---|---|
raw | number | The new raw value. |
dt | number | The elapsed time since the last raw value was added. |
Returns
number
The next smoothed value.
reset()
Call Signature
reset():
null
Defined in: src/sdk/math/MultiExpSmoother.ts:145
Resets the "history" of this smoother and sets the initial smoothed value, velocity, and acceleration to null.
Returns
null
The reset smoothed value.
Call Signature
reset<
T
>(value
,velocity?
,accel?
):T
Defined in: src/sdk/math/MultiExpSmoother.ts:154
Resets the "history" of this smoother, sets the initial smoothed value, and optionally sets the initial smoothed velocity and acceleration.
Type Parameters
Type Parameter |
---|
T extends null | number |
Parameters
Parameter | Type | Description |
---|---|---|
value | T | The new initial smoothed value. |
velocity? | null | number | The new initial smoothed velocity estimate. Defaults to null . |
accel? | null | number | The new initial smoothed acceleration estimate. Defaults to null . |
Returns
T
The reset smoothed value.
Call Signature
reset(
value?
,velocity?
,accel?
):null
|number
Defined in: src/sdk/math/MultiExpSmoother.ts:162
Resets the "history" of this smoother and optionally sets the initial smoothed value, velocity, and acceleration.
Parameters
Parameter | Type | Description |
---|---|---|
value? | null | number | The new initial smoothed value. Defaults to null . |
velocity? | null | number | The new initial smoothed velocity estimate. Defaults to null . |
accel? | null | number | The new initial smoothed acceleration estimate. Defaults to null . |
Returns
null
| number
The reset smoothed value.