# Noise Filtering Using 1€ Filter

## Introduction

This article explores the 1€ Filter, a simple, but powerful algorithm for filtering noisy real-time signals. The article focuses on the practical implementation of the algorithm, and it covers the mathematical basis, a pseudocode implementation, and simple, pure Python implementation of the algorithm. To understand why and how the filter works, we recommend reading the original article 1.

## 1€ Filter

The 1€ Filter is a low pass filter for filtering noisy signals in real-time. It is also a simple filter with only two configurable parameters. The signal at time $T_i$ is denoted as value $X_i$ and the filtered signal as value $\hat{X}_i$. The filter uses exponential smoothing

$$\hat{X}_1 = X_1$$

$$\hat{X}_i = α X_i + (1-α) \hat{X} _{i-1},\quad i≥2 \tag{1} \label{1}$$

where the smoothing factor $α∈[0, 1]$, instead of being a constant, is adaptive, that is, dynamically computed using information about the rate of change (speed) of the signal. The adaptive smoothing factor aims to balance the jitter versus lag trade-off since people are sensitive to jitter at low speeds and more sensitive to lag at high speeds. The smoothing factor is defined as

$$α = \frac{1}{1 + \dfrac{τ}{T_e}},$$

where $T_e$ is the sampling period computed from the time difference between the samples

$$T_e=T_i-T _{i-1}$$

and $τ$ is time constant computed using the cutoff frequency

$$τ = \frac{1}{2πf_C}.$$

The cutoff frequency $f_C$ increases linearly as the rate of change, aka speed, increases

$$f_C=f_{C_{min}} + β|\hat{\dot{X}} _i|$$

where $f _{C _{min}}>0$ is the minimum cutoff frequency, $β>0$ is the speed coefficient and $\hat{\dot{X}}_i$ is the filtered rate of change. We define the rate of change $\hat{X}_i$ as the discrete derivative of the signal

$$\dot{X}_1 = 0$$

$$\dot{X}_i = \frac{X_i-\hat{X} _{i-1}}{T_e}, i≥2$$

which is then filtered using exponential smoothing $\eqref{1}$ with a constant cutoff frequency $f_{C_d},$ by default $f_{C_d}=1$.

## Algorithm

In this section, we implement the 1€ filter algorithm as pseudocode. The precise implementation of the algorithm depends on the programming language and paradigm in question. We have written this algorithm using a functional style.

$\operatorname{Smoothing-Factor}(f_C, T_e)$

1. $r=2π⋅f_c⋅T_e$
2. return $\dfrac{r}{r+1}$

$\operatorname{Exponential-Smoothing}(α, X_i, \hat{X}_{i-1})$

1. return $α X_i + (1-α) \hat{X}_{i-1}$

$\operatorname{One-Euro-Filter}(T_i,X_i,T_{i-1},\hat{X}_{i-1},\hat{\dot{X}}_{i-1},f_C,β,f_{C_d})$ for $i≥2$

1. $T_e=T_i-T_{i-1}$
2. $α_d=\operatorname{Smoothing-Factor}(T_e, f_{C_d})$
3. $\dot{X}_i = \dfrac{X_i-\hat{X} _{i-1}}{T_e}$
4. $\hat{\dot{X}}_i=\operatorname{Exponential-Smoothing}(α_d, \dot{X}_i, \hat{\dot{X}} _{i-1})$
5. $f_C=f_{C_{min}} + β|\hat{\dot{X}}_i|$
6. $α=\operatorname{Smoothing-Factor}(f_C, T_e)$
7. $\hat{X}_i=\operatorname{Exponential-Smoothing}(α, X_i, \hat{X} _{i-1})$
8. return $T_i,\hat{X}_i,\hat{\dot{X}}_i$

## Tuning the Filter

There are two configurable parameters in the model, the minimum cutoff frequency $f _{C _{min}}$ and the speed coefficient $β$. Decreasing the minimum cutoff frequency decreases slow speed jitter. Increasing the speed coefficient decreases speed lag.

## Python Implementation

The following object-oriented Python implementation is also available in OneEuroFilter GitHub repository or as GitHub Gist one_euro_filter.py. The object-oriented approach stores the previous values inside the object instead of explicitly giving them a return value as functional implementation would. It should be relatively simple to implement this algorithm in other languages.

## Conclusions

I first learned about the 1€ filter at Computational User Interface Design course at Aalto University. I found the algorithm to be elegant, but the original paper’s explanation was cumbersome for implementing it. It motivated me to create a simplified explanation and code to help other people implement this algorithm.

If you enjoyed or found benefit from this article, it would be helpful for me if you shared it. If you have any feedback, improvement suggestions, or constructive criticism, don’t forget to mention them in the comments.

## References

1. Casiez, G., Roussel, N., & Vogel, D. (2012). 1€ filter: a simple speed-based low-pass filter for noisy input in interactive systems. In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (pp. 2527–2530). ↩︎

##### Jaan Tollander de Balsch
###### Student & Researcher

Jaan Tollander de Balsch is a computer scientist with a background in applied mathematics.