fix blob fallback breaking stuff

This commit is contained in:
Prohurtz 2023-03-05 14:58:28 -08:00 committed by GitHub
parent b97cc8a352
commit d9ca447ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,21 +30,22 @@ class OneEuroFilter:
t = time() t = time()
t_e = t - self.t_prev t_e = t - self.t_prev
t_e = np.full(x.shape, t_e) if t_e != 0.0: #occasionally when switching to algos this becomes zero causing divide by zero errors crashing the filter.
t_e = np.full(x.shape, t_e)
# The filtered derivative of the signal. # The filtered derivative of the signal.
a_d = smoothing_factor(t_e, self.d_cutoff) a_d = smoothing_factor(t_e, self.d_cutoff)
dx = (x - self.x_prev) / t_e dx = (x - self.x_prev) / t_e
dx_hat = exponential_smoothing(a_d, dx, self.dx_prev) dx_hat = exponential_smoothing(a_d, dx, self.dx_prev)
# The filtered signal. # The filtered signal.
cutoff = self.min_cutoff + self.beta * np.abs(dx_hat) cutoff = self.min_cutoff + self.beta * np.abs(dx_hat)
a = smoothing_factor(t_e, cutoff) a = smoothing_factor(t_e, cutoff)
x_hat = exponential_smoothing(a, x, self.x_prev) x_hat = exponential_smoothing(a, x, self.x_prev)
# Memorize the previous values. # Memorize the previous values.
self.x_prev = x_hat self.x_prev = x_hat
self.dx_prev = dx_hat self.dx_prev = dx_hat
self.t_prev = t self.t_prev = t
return x_hat return x_hat