Skip to content

Commit

Permalink
Integrating the use case where the new timestamp is equal or even sma…
Browse files Browse the repository at this point in the history
…ller than the last timestamp and causing incorrect freq update
  • Loading branch information
Géry Casiez committed Aug 13, 2024
1 parent daaf33d commit 32a58a9
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion C/SF1eFilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ float SF1eFilterDo(SF1eFilter *filter, float x)

float SF1eFilterDoAtTime(SF1eFilter *filter, float x, double timestamp)
{
if(filter->lastTime != 0) {
if(filter->lastTime != 0 && timestamp > filter->lastTime) {
filter->frequency = 1.0f / (timestamp - filter->lastTime);
}
filter->lastTime = timestamp;
Expand Down
2 changes: 1 addition & 1 deletion CppUsingTemplates/1efilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct one_euro_filter {
T operator()(T x, timestamp_t t = -1) {
T dx = 0;

if(last_time_ != -1 && t != -1 && t != last_time_) {
if(last_time_ != -1 && t != -1 && t != last_time_ && t > last_time_) {
freq = 1.0 / (t - last_time_);
}
last_time_ = t;
Expand Down
2 changes: 1 addition & 1 deletion java/OneEuroFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void init(double freq,

double filter(double value, double timestamp) throws Exception {
// update the sampling frequency based on timestamps
if (lasttime != UndefinedTime && timestamp != UndefinedTime) {
if (lasttime != UndefinedTime && timestamp != UndefinedTime && timestamp > lasttime) {
freq = 1.0 / (timestamp - lasttime);
}

Expand Down
2 changes: 1 addition & 1 deletion javascript/OneEuroFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class OneEuroFilter {

filter(value, timestamp=undefined) {
// update the sampling frequency based on timestamps
if (this.lasttime!=undefined && timestamp!=undefined)
if (this.lasttime!=undefined && timestamp!=undefined && timestamp > this.lasttime)
this.freq = 1.0 / (timestamp-this.lasttime) ;
this.lasttime = timestamp ;
// estimate the current variation per second
Expand Down
2 changes: 1 addition & 1 deletion python/OneEuroFilter/OneEuroFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __call__(self, x:float, timestamp:float=None) -> float:
"""

# ---- update the sampling frequency based on timestamps
if self.__lasttime and timestamp:
if self.__lasttime and timestamp and timestamp>self.__lasttime:
self.__freq = 1.0 / (timestamp-self.__lasttime)
self.__lasttime = timestamp
# ---- estimate the current variation per second
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/OneEuroFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class OneEuroFilter {

public filter(value : number, timestamp : number | undefined) : number {
// update the sampling frequency based on timestamps
if (this.lasttime!=undefined && timestamp!=undefined)
if (this.lasttime!=undefined && timestamp!=undefined && timestamp>this.lasttime)
this.freq = 1.0 / (timestamp-this.lasttime) ;
this.lasttime = timestamp ;
// estimate the current variation per second
Expand Down

0 comments on commit 32a58a9

Please sign in to comment.