28 template <
typename T =
double>
31 T operator()(T x, T alpha) {
34 hatx = alpha * x + (1-alpha) * hatxprev;
48 template <
typename T =
double,
typename timestamp_t =
double>
50 one_euro_filter(
double _freq, T _mincutoff, T _beta, T _dcutoff) : freq(_freq), mincutoff(_mincutoff), beta(_beta), dcutoff(_dcutoff), last_time_(-1) {}
51 T operator()(T x, timestamp_t t = -1) {
54 if(last_time_ != -1 && t != -1 && t != last_time_) {
55 freq = 1.0 / (t - last_time_);
60 dx = (x - xfilt_.xprev) * freq;
62 T edx = dxfilt_(dx, alpha(dcutoff));
63 T cutoff = mincutoff + beta * abs(static_cast<double>(edx));
64 return xfilt_(x, alpha(cutoff));
68 T mincutoff, beta, dcutoff;
71 T tau = 1.0 / (2 * M_PI * cutoff);
73 return 1.0 / (1.0 + tau / te);
76 timestamp_t last_time_;