@@ -22,6 +22,8 @@ import {LowPassFilter} from './low_pass_filter';
2222 */
2323// ref:
2424// https://github.com/google/mediapipe/blob/master/mediapipe/util/filtering/one_euro_filter.cc
25+ // Also ref original paper:
26+ // https://cristal.univ-lille.fr/~casiez/1euro/
2527export class OneEuroFilter {
2628 private frequency : number ;
2729 private minCutOff : number ;
@@ -30,6 +32,8 @@ export class OneEuroFilter {
3032 private x : LowPassFilter ;
3133 private dx : LowPassFilter ;
3234 private lastTimestamp : number ;
35+ private thresholdCutOff : number ;
36+ private thresholdBeta : number ;
3337 /**
3438 * Constructor of `OneEuroFilter` class.
3539 * @param config See documentation of `OneEuroFilterConfig`.
@@ -38,6 +42,8 @@ export class OneEuroFilter {
3842 this . frequency = config . frequency ;
3943 this . minCutOff = config . minCutOff ;
4044 this . beta = config . beta ;
45+ this . thresholdCutOff = config . thresholdCutOff ;
46+ this . thresholdBeta = config . thresholdBeta ;
4147 this . derivateCutOff = config . derivateCutOff ;
4248 this . x = new LowPassFilter ( this . getAlpha ( this . minCutOff ) ) ;
4349 this . dx = new LowPassFilter ( this . getAlpha ( this . derivateCutOff ) ) ;
@@ -77,8 +83,12 @@ export class OneEuroFilter {
7783 this . dx . applyWithAlpha ( dValue , this . getAlpha ( this . derivateCutOff ) ) ;
7884 const cutOff = this . minCutOff + this . beta * Math . abs ( edValue ) ;
7985
86+ const threshold = this . thresholdCutOff != null ?
87+ this . thresholdCutOff + this . thresholdBeta * Math . abs ( edValue ) :
88+ null ;
89+
8090 // filter the given value.
81- return this . x . applyWithAlpha ( value , this . getAlpha ( cutOff ) ) ;
91+ return this . x . applyWithAlpha ( value , this . getAlpha ( cutOff ) , threshold ) ;
8292 }
8393
8494 private getAlpha ( cutoff : number ) : number {
0 commit comments