Class: ExpSmoother
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
Creates a new instance of ExpSmoother.
Parameters
Name | 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
Defined in
src/sdk/math/ExpSmoother.ts:21
Properties
dtThreshold
• Readonly
dtThreshold: number
= Infinity
The elapsed time threshold, in seconds, above which this smoother will not smooth a new raw value. Defaults to infinity.
Defined in
src/sdk/math/ExpSmoother.ts:24
tau
• Readonly
tau: number
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.
Defined in
src/sdk/math/ExpSmoother.ts:22
Methods
last
▸ last(): null
| number
Gets the last smoothed value.
Returns
null
| number
The last smoothed value, or null if none exists.
Defined in
src/sdk/math/ExpSmoother.ts:33
next
▸ next(raw
, dt
): number
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
Name | 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.
Defined in
src/sdk/math/ExpSmoother.ts:45
reset
▸ reset(): null
Resets the "history" of this smoother and sets the initial smoothed value to null.
Returns
null
Defined in
src/sdk/math/ExpSmoother.ts:73
▸ reset<T
>(value
): T
Resets the "history" of this smoother and sets the initial smoothed value.
Type parameters
Name | Type |
---|---|
T | extends null | number |
Parameters
Name | Type | Description |
---|---|---|
value | T | The new initial smoothed value. |
Returns
T
The reset smoothed value.
Defined in
src/sdk/math/ExpSmoother.ts:79
▸ reset(value?
): null
| number
Resets the "history" of this smoother and optionally sets the initial smoothed value.
Parameters
Name | Type | Description |
---|---|---|
value? | null | number | The new initial smoothed value. Defaults to null. |
Returns
null
| number
The reset smoothed value.
Defined in
src/sdk/math/ExpSmoother.ts:85