Class: ExpSmoother
Defined in: src/sdk/math/ExpSmoother.ts:10
Applies time-weighted exponential smoothing (i.e. an exponential moving average) to a sequence of raw values.
When a new raw value is added to the sequence, it and the last smoothed value 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.
Constructors
Constructor
new ExpSmoother(
tau
,initial
,dtThreshold
):ExpSmoother
Defined in: src/sdk/math/ExpSmoother.ts:21
Creates a new instance of ExpSmoother.
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. |
initial | null | number | null | The initial smoothed value of this smoother. 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
ExpSmoother
Properties
dtThreshold
readonly
dtThreshold:number
=Infinity
Defined in: src/sdk/math/ExpSmoother.ts:24
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/ExpSmoother.ts:22
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.
Methods
last()
last():
null
|number
Defined in: src/sdk/math/ExpSmoother.ts:33
Gets the last smoothed value.
Returns
null
| number
The last smoothed value, or null if none exists.
next()
next(
raw
,dt
):number
Defined in: src/sdk/math/ExpSmoother.ts:45
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/ExpSmoother.ts:73
Resets the "history" of this smoother and sets the initial smoothed value to null.
Returns
null
Call Signature
reset<
T
>(value
):T
Defined in: src/sdk/math/ExpSmoother.ts:79
Resets the "history" of this smoother and sets the initial smoothed value.
Type Parameters
Type Parameter |
---|
T extends null | number |
Parameters
Parameter | Type | Description |
---|---|---|
value | T | The new initial smoothed value. |
Returns
T
The reset smoothed value.
Call Signature
reset(
value?
):null
|number
Defined in: src/sdk/math/ExpSmoother.ts:85
Resets the "history" of this smoother and optionally sets the initial smoothed value.
Parameters
Parameter | Type | Description |
---|---|---|
value? | null | number | The new initial smoothed value. Defaults to null. |
Returns
null
| number
The reset smoothed value.