Skip to main content

Class: MultiExpSmoother

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

Creates a new instance of MultiExpSmoother.

Parameters

NameTypeDefault valueDescription
taunumberundefinedThis 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?numberundefinedThis 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?numberundefinedThis 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.
initialnull | numbernullThe initial smoothed value of the smoother. Defaults to null.
initialVelocitynull | numbernullThe initial smoothed velocity estimate of the smoother. Ignored if tauVelocity is not defined. Defaults to null.
initialAccelnull | numbernullThe initial smoothed acceleration estimate of the smoother. Ignored if tauVelocity or tauAccel is not defined. Defaults to null.
dtThresholdnumberInfinityThe elapsed time threshold, in seconds, above which this smoother will not smooth a new raw value. Defaults to infinity.

Returns

MultiExpSmoother

Defined in

src/sdk/math/MultiExpSmoother.ts:40

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/MultiExpSmoother.ts:47


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/MultiExpSmoother.ts:41


tauAccel

Optional Readonly tauAccel: number

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.

Defined in

src/sdk/math/MultiExpSmoother.ts:43


tauVelocity

Optional Readonly tauVelocity: number

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.

Defined in

src/sdk/math/MultiExpSmoother.ts:42

Methods

forecast

forecast(t): null | number

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

NameTypeDescription
tnumberThe 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.

Defined in

src/sdk/math/MultiExpSmoother.ts:179


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/MultiExpSmoother.ts:58


lastAcceleration

lastAcceleration(): null | number

Gets the last smoothed acceleration.

Returns

null | number

The last smoothed acceleration, or null if none exists.

Defined in

src/sdk/math/MultiExpSmoother.ts:74


lastVelocity

lastVelocity(): null | number

Gets the last smoothed velocity.

Returns

null | number

The last smoothed velocity, or null if none exists.

Defined in

src/sdk/math/MultiExpSmoother.ts:66


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

NameTypeDescription
rawnumberThe new raw value.
dtnumberThe elapsed time since the last raw value was added.

Returns

number

The next smoothed value.

Defined in

src/sdk/math/MultiExpSmoother.ts:86


reset

reset(): null

Resets the "history" of this smoother and sets the initial smoothed value, velocity, and acceleration to null.

Returns

null

The reset smoothed value.

Defined in

src/sdk/math/MultiExpSmoother.ts:145

reset<T>(value, velocity?, accel?): T

Resets the "history" of this smoother, sets the initial smoothed value, and optionally sets the initial smoothed velocity and acceleration.

Type parameters

NameType
Textends null | number

Parameters

NameTypeDescription
valueTThe new initial smoothed value.
velocity?null | numberThe new initial smoothed velocity estimate. Defaults to null.
accel?null | numberThe new initial smoothed acceleration estimate. Defaults to null.

Returns

T

The reset smoothed value.

Defined in

src/sdk/math/MultiExpSmoother.ts:154

reset(value?, velocity?, accel?): null | number

Resets the "history" of this smoother and optionally sets the initial smoothed value, velocity, and acceleration.

Parameters

NameTypeDescription
value?null | numberThe new initial smoothed value. Defaults to null.
velocity?null | numberThe new initial smoothed velocity estimate. Defaults to null.
accel?null | numberThe new initial smoothed acceleration estimate. Defaults to null.

Returns

null | number

The reset smoothed value.

Defined in

src/sdk/math/MultiExpSmoother.ts:162