### Install 1EuroFilter Package Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Use npm to install the 1eurofilter package. ```bash npm install 1eurofilter ``` -------------------------------- ### Parameter Tuning Guide Source: https://context7.com/casiez/oneeurofilter/llms.txt Guidance on choosing the `mincutoff` and `beta` parameters for the One Euro Filter based on different usage scenarios. ```APIDOC ## Parameter Tuning Guide ### Choosing `mincutoff` and `beta` These are the two primary parameters users need to tune for optimal filter performance. ### Scenarios - **Scenario 1: Stable cursor / low-speed precision (e.g., drawing tablet)** - **Goal**: Maximum jitter removal, some lag acceptable. - **Parameters**: `freq=60`, `mincutoff=0.1`, `beta=0.0`. - **Explanation**: Low `mincutoff` provides aggressive smoothing at rest; `beta=0` means no lag compensation. - **Scenario 2: Fast-moving tracking (e.g., head tracking, game input)** - **Goal**: Minimize lag during fast movement, tolerate some jitter. - **Parameters**: `freq=120`, `mincutoff=1.0`, `beta=1.0`. - **Explanation**: Higher `beta` allows the cutoff frequency to increase faster with signal speed, reducing lag. - **Scenario 3: Balanced (interactive pointing with moderate precision)** - **Parameters**: `freq=60`, `mincutoff=1.0`, `beta=0.007`. ### Rule of Thumb - **Increase `mincutoff`**: Less jitter at rest, more lag. - **Decrease `mincutoff`**: More jitter at rest, less lag. - **Increase `beta`**: Less lag during fast movement, may add jitter. - **Decrease `beta`**: More lag during fast movement, less jitter. ``` -------------------------------- ### Python Parameter Tuning Guide for One Euro Filter Source: https://context7.com/casiez/oneeurofilter/llms.txt Demonstrates how to tune `mincutoff` and `beta` parameters in Python for different scenarios, from stable cursor tracking to fast-moving input. Provides rules of thumb for parameter adjustments. ```python from OneEuroFilter import OneEuroFilter # Scenario 1: Stable cursor / low-speed precision (e.g., drawing tablet) # Goal: maximum jitter removal, some lag acceptable f_precision = OneEuroFilter(freq=60, mincutoff=0.1, beta=0.0) # Low mincutoff = aggressive smoothing at rest; beta=0 = no lag compensation # Scenario 2: Fast-moving tracking (e.g., head tracking, game input) # Goal: minimize lag during fast movement, tolerate some jitter f_responsive = OneEuroFilter(freq=120, mincutoff=1.0, beta=1.0) # Higher beta = faster cutoff increase as signal speed increases # Scenario 3: Balanced (interactive pointing with moderate precision) f_balanced = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.007) # Rule of thumb: # - Increase mincutoff → less jitter at rest (more lag) # - Decrease mincutoff → more jitter at rest (less lag) # - Increase beta → less lag during fast movement (may add jitter) ``` -------------------------------- ### Install OneEuroFilter Package Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Install the OneEuroFilter package using pip. It is recommended to upgrade to the latest version. ```bash pip install OneEuroFilter --upgrade ``` -------------------------------- ### Minimal Example of 1EuroFilter Usage Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Demonstrates the basic instantiation and usage of the OneEuroFilter for smoothing noisy values with timestamps. Ensure the frequency is set appropriately for your signal. ```typescript import {OneEuroFilter} from '1eurofilter' let frequency = 120; // Hz let mincutoff = 1.0; // Hz let beta = 0.1; let dcutoff = 1.0; let f = new OneEuroFilter(frequency, mincutoff, beta, dcutoff); let noisyvalue = 2.1; let timestamp = 0.0; // in seconds let filtered = f.filter(noisyvalue, timestamp); ``` -------------------------------- ### Filter Values with Fixed and Variable Rates (JavaScript) Source: https://context7.com/casiez/oneeurofilter/llms.txt Demonstrates filtering values using the OneEuroFilter. The first example filters without timestamps, assuming a fixed rate. The second example uses timestamps for variable rate filtering, suitable for animation frame callbacks. ```javascript // JavaScript ES module — import directly from source import { OneEuroFilter } from './OneEuroFilter.js'; const f = new OneEuroFilter(120, 0.5, 0.1, 1.0); // Without timestamps (fixed rate) [0.1, 0.15, 0.08, 0.13].forEach(v => { console.log(f.filter(v).toFixed(5)); }); // With timestamps (variable rate, e.g., requestAnimationFrame) const f2 = new OneEuroFilter(60, 1.0, 0.01, 1.0); let prevTime = null; function onFrame(timestamp) { // timestamp in ms from rAF const t = timestamp / 1000; // convert to seconds const rawValue = getSensorValue(); // your noisy data source const filtered = f2.filter(rawValue, t); renderValue(filtered); requestAnimationFrame(onFrame); } requestAnimationFrame(onFrame); ``` -------------------------------- ### Connect to Docker Container and Build Source: https://github.com/casiez/oneeurofilter/blob/main/docker/Readme.md Executes a bash shell inside the running container, navigates to the mounted directory, and builds the project using 'make'. ```bash docker exec -it oneeurofilter_con /bin/bash cd /mnt/1euro make ``` -------------------------------- ### Build Docker Image Source: https://github.com/casiez/oneeurofilter/blob/main/docker/Readme.md Builds the Docker image for the 1€ filter. Use this command in the directory containing the Dockerfile. ```bash docker build -t oneeurofilter . ``` -------------------------------- ### Initialize and Use OneEuroFilter in Python Source: https://context7.com/casiez/oneeurofilter/llms.txt Demonstrates initializing the OneEuroFilter with specific parameters for mouse cursor smoothing and processing a simulated noisy input stream using real timestamps. The filter can be called directly or via its `filter` method. ```python from OneEuroFilter import OneEuroFilter import time # Install: pip install OneEuroFilter # Mouse cursor smoothing at 60 Hz f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.01, dcutoff=1.0) # Simulated noisy input stream with real timestamps noisy_samples = [120.3, 121.8, 119.5, 122.1, 120.9, 123.4, 121.2] start = time.time() for i, raw in enumerate(noisy_samples): timestamp = start + i * (1.0 / 60.0) # seconds smoothed = f(raw, timestamp) # callable syntax # Equivalent: smoothed = f.filter(raw, timestamp) print(f"raw={raw:.1f} filtered={smoothed:.4f}") ``` -------------------------------- ### Constructor Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Constructs a 1 euro filter with specified parameters. Frequency is estimated if timestamps are not available. Min cutoff frequency controls jitter reduction. Beta parameter reduces latency. Dcutoff filters derivatives. ```APIDOC ## new OneEuroFilter(freq, mincutoff, beta, dcutoff) ### Description Constructs a 1 euro filter. ### Parameters - **freq** (number) - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. - **mincutoff** (number) - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. Default value: 1.0 - **beta** (number) - Parameter to reduce latency (> 0). Default value: 0.0 - **dcutoff** (number) - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. Default value: 1.0 ``` -------------------------------- ### Minimal OneEuroFilter Usage Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Demonstrates the basic instantiation and usage of the OneEuroFilter. Configure parameters like frequency, mincutoff, beta, and dcutoff during initialization. The filter takes the noisy value and timestamp as input. ```python from OneEuroFilter import OneEuroFilter config = { 'freq': 120, # Hz 'mincutoff': 1.0, # Hz 'beta': 0.1, 'dcutoff': 1.0 } f = OneEuroFilter(**config) # First parameter is the value to filter # the second parameter is the current timestamp in seconds filtered = f(2.1, 0) ``` -------------------------------- ### OneEuroFilter Class Initialization Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Initialize the OneEuroFilter class with essential parameters. 'freq' is the signal frequency, 'mincutoff' controls jitter reduction, 'beta' affects latency, and 'dcutoff' filters derivatives. ```python OneEuroFilter(freq: float, mincutoff: float = 1.0, beta: float = 0.0, dcutoff: float = 1.0) ``` -------------------------------- ### Java Class and Methods Source: https://context7.com/casiez/oneeurofilter/llms.txt Java implementation of the One Euro Filter with constructor overloads and a `filter` method for applying the smoothing. ```APIDOC ## Java API ### `new OneEuroFilter(freq, mincutoff, beta_, dcutoff)` / `filter(value, timestamp)` — Java class ### Constructor - **`OneEuroFilter(double freq)`**: Initializes with default `mincutoff`, `beta`, and `dcutoff`. - **`OneEuroFilter(double freq, double mincutoff)`**: Initializes with specified `freq` and `mincutoff`. - **`OneEuroFilter(double freq, double mincutoff, double beta_, double dcutoff)`**: Initializes with all four parameters. ### Method - **`filter(double value)`**: Filters a value without a timestamp. Uses an internal sentinel for undefined time. - **`filter(double value, double timestamp)`**: Filters a value with a timestamp. ### Usage Example ```java public class Example { public static void main(String[] args) throws Exception { OneEuroFilter f = new OneEuroFilter(120.0, 1.0, 0.1, 1.0); double[] noisy = {0.5, 0.52, 0.48, 0.55, 0.47, 0.51}; double[] timestamps = {0.0, 0.00833, 0.01667, 0.025, 0.03333, 0.04167}; System.out.println("timestamp,noisy,filtered"); for (int i = 0; i < noisy.length; i++) { double filtered = f.filter(noisy[i], timestamps[i]); System.out.printf("%.5f,%.4f,%.6f%n", timestamps[i], noisy[i], filtered); } OneEuroFilter f2 = new OneEuroFilter(60.0); for (double v : new double[]{1.0, 1.05, 0.98, 1.02}) { System.out.printf("%.6f%n", f2.filter(v)); } } } ``` ``` -------------------------------- ### OneEuroFilter Constructor - JavaScript/TypeScript Source: https://context7.com/casiez/oneeurofilter/llms.txt Initializes a new OneEuroFilter instance. Accepts frequency, minimum cutoff, beta, and derivative cutoff as parameters. ```APIDOC ## new OneEuroFilter(freq, mincutoff, beta, dcutoff) ### Description Initializes a new OneEuroFilter instance. Accepts frequency, minimum cutoff, beta, and derivative cutoff as parameters. Same parameters as the Python version. ### Parameters - **freq** (number) - The sampling frequency in Hz. - **mincutoff** (number) - The minimum cutoff frequency in Hz, used to reduce jitter at rest. - **beta** (number) - A small value for slight lag reduction on movement. - **dcutoff** (number) - The derivative cutoff frequency (typically 1.0). ### Example (TypeScript) ```typescript import { OneEuroFilter } from '1eurofilter'; const filter = new OneEuroFilter( 60, // freq: 60 Hz input 1.0, // mincutoff: 1 Hz (reduce jitter at rest) 0.007, // beta: small value for slight lag reduction on movement 1.0 // dcutoff: derivative cutoff (leave at 1.0) ); ``` ``` -------------------------------- ### OneEuroFilter Constructor Source: https://context7.com/casiez/oneeurofilter/llms.txt Initializes the 1€ filter with specified parameters. `freq` is the expected sampling rate in Hz. `mincutoff` controls jitter reduction, `beta` controls lag reduction, and `dcutoff` filters the derivative. Raises `ValueError` if any required parameter is less than or equal to 0. ```APIDOC ## OneEuroFilter(freq, mincutoff, beta, dcutoff) ### Description Initializes the filter. `freq` is the expected sampling rate in Hz. `mincutoff` (default `1.0` Hz) controls jitter reduction at rest—lower values remove more jitter. `beta` (default `0.0`) controls lag reduction during fast motion—increase it to reduce delay. `dcutoff` (default `1.0`) filters the derivative and should rarely need changing. Raises `ValueError` if any required parameter is ≤ 0. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from OneEuroFilter import OneEuroFilter import time # Mouse cursor smoothing at 60 Hz f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.01, dcutoff=1.0) # Simulated noisy input stream with real timestamps noisy_samples = [120.3, 121.8, 119.5, 122.1, 120.9, 123.4, 121.2] start = time.time() for i, raw in enumerate(noisy_samples): timestamp = start + i * (1.0 / 60.0) # seconds smoothed = f(raw, timestamp) # callable syntax # Equivalent: smoothed = f.filter(raw, timestamp) print(f"raw={raw:.1f} filtered={smoothed:.4f}") ``` ### Response #### Success Response (200) None (Constructor does not return a value, it initializes an object) #### Response Example None ``` -------------------------------- ### Initialize and Filter with Timestamps (C++) Source: https://context7.com/casiez/oneeurofilter/llms.txt Initializes the C++ OneEuroFilter class with specified parameters and filters a series of noisy values using provided timestamps. The `UndefinedTime` sentinel can be used when timestamps are unavailable. ```cpp #include "OneEuroFilter.h" #include int main() { // 120 Hz, mincutoff=1.0, beta=0.1, dcutoff=1.0 OneEuroFilter f(120.0, 1.0, 0.1, 1.0); double noisy[] = {0.05, 0.12, -0.03, 0.08, 0.15, 0.01}; double timestamps[] = {0.0, 0.00833, 0.01667, 0.025, 0.03333, 0.04167}; std::cout << "timestamp,noisy,filtered" << std::endl; for (int i = 0; i < 6; i++) { double filtered = f.filter(noisy[i], timestamps[i]); std::cout << timestamps[i] << "," << noisy[i] << "," << filtered << std::endl; } // Without timestamps (fixed rate assumed): OneEuroFilter f2(60.0, 1.0, 0.0); for (double v : {1.0, 1.05, 0.98, 1.02}) { std::cout << f2.filter(v, UndefinedTime) << std::endl; } return 0; } // Compile: g++ -o test Test.cpp OneEuroFilter.cpp -lm ``` -------------------------------- ### setParameters Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Sets multiple parameters of the 1 euro filter at once: frequency, minimum cutoff, and beta. ```APIDOC ## setParameters(freq, mincutoff, beta) ### Description Sets the parameters of the 1 euro filter. ### Parameters - **freq** (number) - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. - **mincutoff** (number) - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. - **beta** (number) - Parameter to reduce latency (> 0). ### Returns - `void` ``` -------------------------------- ### C API Functions Source: https://context7.com/casiez/oneeurofilter/llms.txt C API for the One Euro Filter, providing functions for creation, initialization, filtering, and destruction of the filter instance. ```APIDOC ## C API ### `SF1eFilterCreate` / `SF1eFilterDo` / `SF1eFilterDoAtTime` / `SF1eFilterDestroy` — C struct API Provides a struct-based API with heap allocation, config-struct allocation, and stack allocation patterns. ### Functions - **`SF1eFilterCreate(float freq, float mincutoff, float beta, float dcutoff)`**: Creates a new filter instance with specified parameters. - **`SF1eFilterInit(SF1eFilter *f)`**: Initializes the filter instance. - **`SF1eFilterDo(SF1eFilter *f, float value)`**: Filters a value without a timestamp. - **`SF1eFilterDoAtTime(SF1eFilter *f, float value, double timestamp)`**: Filters a value with a timestamp. - **`SF1eFilterDestroy(SF1eFilter *f)`**: Destroys the filter instance and frees memory. ### Usage Example (Heap Allocation) ```c #include "SF1eFilter.h" #include int main() { SF1eFilter *f = SF1eFilterCreate(120.0f, 1.0f, 0.1f, 1.0f); SF1eFilterInit(f); float noisy[] = {0.5f, 0.52f, 0.48f, 0.55f, 0.47f}; for (int i = 0; i < 5; i++) { float filtered = SF1eFilterDo(f, noisy[i]); printf("filtered: %f\n", filtered); } f = SF1eFilterDestroy(f); return 0; } ``` ### Usage Example (Stack Allocation) ```c #include "SF1eFilter.h" #include int main() { SF1eFilter sf; sf.config.frequency = 60.0f; sf.config.minCutoffFrequency = 1.0f; sf.config.cutoffSlope = 0.05f; sf.config.derivativeCutoffFrequency = 1.0f; SF1eFilterInit(&sf); float noisy[] = {0.5f, 0.52f, 0.48f, 0.55f, 0.47f}; for (int i = 0; i < 5; i++) { printf("stack filtered: %f\n", SF1eFilterDo(&sf, noisy[i])); } return 0; } ``` ``` -------------------------------- ### Apply One Euro Filter to Sequence Source: https://context7.com/casiez/oneeurofilter/llms.txt Iterate through a sequence of raw values and apply the One Euro filter with different tuning parameters (precision, responsive, balanced). ```python raw_sequence = [10.1, 10.3, 9.9, 10.4, 10.0, 10.2, 9.8, 10.5] for v in raw_sequence: print(f"precision={f_precision.filter(v):.3f} " f"responsive={f_responsive.filter(v):.3f} " f"balanced={f_balanced.filter(v):.3f}") ``` -------------------------------- ### C API for One Euro Filter Source: https://context7.com/casiez/oneeurofilter/llms.txt C struct-based API with options for heap allocation (individual parameters or timestamp-based) and stack allocation. Requires explicit initialization and destruction. ```c #include "SF1eFilter.h" #include int main() { /* --- Pattern 1: Heap allocation with individual parameters --- */ SF1eFilter *f = SF1eFilterCreate(120.0f, 1.0f, 0.1f, 1.0f); // freq mincutoff beta dcutoff SF1eFilterInit(f); float noisy[] = {0.5f, 0.52f, 0.48f, 0.55f, 0.47f}; for (int i = 0; i < 5; i++) { float filtered = SF1eFilterDo(f, noisy[i]); printf("filtered: %f\n", filtered); } f = SF1eFilterDestroy(f); // returns NULL /* --- Pattern 2: Timestamp-based (auto frequency) --- */ SF1eFilter *f2 = SF1eFilterCreate(120.0f, 1.0f, 0.1f, 1.0f); SF1eFilterInit(f2); double timestamps[] = {0.0, 0.00833, 0.01667, 0.025, 0.03333}; for (int i = 0; i < 5; i++) { float filtered = SF1eFilterDoAtTime(f2, noisy[i], timestamps[i]); printf("t=%.5f filtered=%f\n", timestamps[i], filtered); } f2 = SF1eFilterDestroy(f2); /* --- Pattern 3: Stack allocation (no malloc) --- */ SF1eFilter sf; sf.config.frequency = 60.0f; sf.config.minCutoffFrequency = 1.0f; sf.config.cutoffSlope = 0.05f; sf.config.derivativeCutoffFrequency = 1.0f; SF1eFilterInit(&sf); for (int i = 0; i < 5; i++) { printf("stack filtered: %f\n", SF1eFilterDo(&sf, noisy[i])); } return 0; } // Compile: gcc -o test test.c SF1eFilter.c -lm ``` -------------------------------- ### Set Individual OneEuroFilter Parameters in Python Source: https://context7.com/casiez/oneeurofilter/llms.txt Demonstrates using individual setter methods (`setBeta`, `setMinCutoff`, `setFrequency`, `setDerivateCutoff`) to modify specific filter parameters dynamically. Note that frequency-related setters raise a `ValueError` if the provided value is not positive. ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.0) # Increase responsiveness dynamically (e.g., when user starts moving fast) f.setBeta(0.5) # Reduce jitter further (e.g., for precision drawing) f.setMinCutoff(0.5) # Adapt to a new data source running at a different rate f.setFrequency(120) try: f.setFrequency(-5) # raises ValueError except ValueError as e: print(f"Error: {e}") # Error: freq should be >0 ``` -------------------------------- ### OneEuroFilter.setParameters Method Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md A convenience method to set the frequency, minimum cutoff, and beta parameters simultaneously. Ensure frequency and mincutoff are positive. ```typescript f.setParameters(freq, mincutoff, beta) ``` -------------------------------- ### OneEuroFilter Constructor Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Constructs a 1 euro filter with specified parameters. The frequency parameter is used if timestamps are unavailable. Adjust mincutoff to control jitter reduction and beta to manage latency. ```typescript new OneEuroFilter(freq, mincutoff, beta, dcutoff) ``` -------------------------------- ### Update All OneEuroFilter Parameters Dynamically in Python Source: https://context7.com/casiez/oneeurofilter/llms.txt Illustrates using the `setParameters` method to update all filter configuration values (`freq`, `mincutoff`, `beta`, `dcutoff`) simultaneously without resetting the filter's internal state. This is useful for runtime adjustments. ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=30, mincutoff=2.0, beta=0.0) # Process some data at 30 Hz with high jitter reduction for v in [1.0, 1.1, 0.9, 1.05]: print(f.filter(v)) # Switch to 60 Hz input with less jitter reduction, more responsiveness f.setParameters(freq=60, mincutoff=0.5, beta=0.2) for v in [2.0, 2.1, 1.95, 2.05]: print(f.filter(v)) ``` -------------------------------- ### Filter with Fixed-Rate and Variable-Rate Timestamps in Python Source: https://context7.com/casiez/oneeurofilter/llms.txt Shows two ways to use the `filter` method: fixed-rate usage without timestamps, relying on the constructor's `freq` parameter, and variable-rate usage with explicit timestamps for adaptive frequency estimation. Ensure timestamps are in seconds. ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=120, mincutoff=1.0, beta=0.1, dcutoff=1.0) # Fixed-rate usage (no timestamps) for raw_value in [0.5, 0.52, 0.49, 0.53, 0.48, 0.51]: filtered = f.filter(raw_value) print(f"{filtered:.5f}") # Variable-rate usage (with timestamps in seconds) f2 = OneEuroFilter(freq=30, mincutoff=0.5, beta=0.05) timestamps = [0.0, 0.033, 0.067, 0.105, 0.138] # irregular intervals values = [10.1, 10.3, 9.8, 10.5, 10.0] for t, v in zip(timestamps, values): result = f2(v, t) print(f"t={t:.3f} filtered={result:.4f}") ``` -------------------------------- ### OneEuroFilter Constructor and filter() - C++ Source: https://context7.com/casiez/oneeurofilter/llms.txt C++ class-based implementation of the OneEuroFilter. Uses `UndefinedTime` sentinel for when timestamps are unavailable. ```APIDOC ## C++ API (Class-Based) ### `OneEuroFilter(freq, mincutoff, beta_, dcutoff)` / `filter(value, timestamp)` ### Description The C++ class-based implementation. Uses `UndefinedTime` sentinel for when timestamps are unavailable. ### Parameters - **freq** (double) - The sampling frequency in Hz. - **mincutoff** (double) - The minimum cutoff frequency in Hz. - **beta_** (double) - The beta parameter for the filter. - **dcutoff** (double) - The derivative cutoff frequency. - **value** (double) - The noisy input value to filter. - **timestamp** (double) - The timestamp of the input value in seconds, or `UndefinedTime` if unavailable. ### Example ```cpp #include "OneEuroFilter.h" #include int main() { // 120 Hz, mincutoff=1.0, beta=0.1, dcutoff=1.0 OneEuroFilter f(120.0, 1.0, 0.1, 1.0); double noisy[] = {0.05, 0.12, -0.03, 0.08, 0.15, 0.01}; double timestamps[] = {0.0, 0.00833, 0.01667, 0.025, 0.03333, 0.04167}; std::cout << "timestamp,noisy,filtered" << std::endl; for (int i = 0; i < 6; i++) { double filtered = f.filter(noisy[i], timestamps[i]); std::cout << timestamps[i] << "," << noisy[i] << "," << filtered << std::endl; } // Without timestamps (fixed rate assumed): OneEuroFilter f2(60.0, 1.0, 0.0); for (double v : {1.0, 1.05, 0.98, 1.02}) { std::cout << f2.filter(v, UndefinedTime) << std::endl; } return 0; } // Compile: g++ -o test Test.cpp OneEuroFilter.cpp -lm ``` ``` -------------------------------- ### Initialize and Filter with Timestamps (TypeScript) Source: https://context7.com/casiez/oneeurofilter/llms.txt Initializes the OneEuroFilter with specified parameters and filters a stream of X coordinates using provided timestamps. The timestamp parameter allows for automatic recalculation of the sampling frequency. ```typescript // TypeScript — npm install 1eurofilter import { OneEuroFilter } from '1eurofilter'; const filter = new OneEuroFilter( 60, // freq: 60 Hz input 1.0, // mincutoff: 1 Hz (reduce jitter at rest) 0.007, // beta: small value for slight lag reduction on movement 1.0 // dcutoff: derivative cutoff (leave at 1.0) ); // Filtering a stream of touch/pointer X coordinates const rawX = [312, 315, 310, 318, 313, 320, 314]; rawX.forEach((x, i) => { const timestamp = i / 60; // seconds const smoothed = filter.filter(x, timestamp); console.log(`raw=${x} filtered=${smoothed.toFixed(3)}`); }); // Output: // raw=312 filtered=312.000 // raw=315 filtered=312.215 // raw=310 filtered=312.038 // raw=318 filtered=312.371 // raw=313 filtered=312.411 // raw=320 filtered=312.829 // raw=314 filtered=312.795 ``` -------------------------------- ### OneEuroFilter setBeta Method Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Adjusts the Beta parameter of the filter. Increasing Beta reduces latency but may affect smoothing. ```python setBeta(beta: float) ``` -------------------------------- ### OneEuroFilter setParameters Method Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Resets all filter parameters at once. Accepts frequency, min cutoff, beta, and derivative cutoff. ```python setParameters(freq: float, mincutoff: float = 1.0, beta: float = 0.0, dcutoff=1.0) ``` -------------------------------- ### setMinCutoff Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Sets the minimum cutoff frequency in Hz. Lower values result in more jitter reduction. ```APIDOC ## setMinCutoff(mincutoff) ### Description Sets the filter min cutoff frequency ### Parameters - **mincutoff** (number) - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. ### Returns - `void` ``` -------------------------------- ### Java Implementation of One Euro Filter Source: https://context7.com/casiez/oneeurofilter/llms.txt Java class for the One Euro Filter. Supports constructor overloads for different parameter sets and a `filter` method that can optionally take a timestamp. ```java public class Example { public static void main(String[] args) throws Exception { // Constructor overloads: freq only, freq+mincutoff, freq+mincutoff+beta, or all four OneEuroFilter f = new OneEuroFilter(120.0, 1.0, 0.1, 1.0); double[] noisy = {0.5, 0.52, 0.48, 0.55, 0.47, 0.51}; double[] timestamps = {0.0, 0.00833, 0.01667, 0.025, 0.03333, 0.04167}; System.out.println("timestamp,noisy,filtered"); for (int i = 0; i < noisy.length; i++) { double filtered = f.filter(noisy[i], timestamps[i]); System.out.printf("%.5f,%.4f,%.6f%n", timestamps[i], noisy[i], filtered); } // Without timestamp: uses UndefinedTime sentinel (-1) OneEuroFilter f2 = new OneEuroFilter(60.0); // mincutoff=1.0, beta=0.0, dcutoff=1.0 for (double v : new double[]{1.0, 1.05, 0.98, 1.02}) { System.out.printf("%.6f%n", f2.filter(v)); } } } // Compile: javac OneEuroFilter.java Example.java // Run: java Example ``` -------------------------------- ### C++ Template Implementation Source: https://context7.com/casiez/oneeurofilter/llms.txt Header-only, type-generic implementation of the One Euro Filter using C++ templates. Can be instantiated with any numeric type. ```APIDOC ## `one_euro_filter` — Header-only template struct Instantiate with any numeric type. ### Usage Example ```cpp #include "1efilter.cc" // header-only, include directly #include int main() { // Double precision (default) one_euro_filter f(120.0, 1.0, 0.1, 1.0); // Float precision (more efficient on embedded) one_euro_filter ff(60.0f, 0.5f, 0.05f, 1.0f); double ts[] = {0.0, 0.00833, 0.01667, 0.025}; double vals[] = {0.5, 0.52, 0.48, 0.51}; for (int i = 0; i < 4; i++) { double out = f(vals[i], ts[i]); // callable operator() std::cout << out << std::endl; } // Without timestamp (-1 means undefined) one_euro_filter<> f2(30.0, 1.0, 0.0, 1.0); std::cout << f2(3.14) << std::endl; // no timestamp return 0; } ``` ``` -------------------------------- ### Run Docker Container Source: https://github.com/casiez/oneeurofilter/blob/main/docker/Readme.md Runs the Docker container in detached mode, mounting the current directory into the container. This allows for persistent storage and access to project files. ```bash docker run -i -t -d --name=oneeurofilter_con --mount type=bind,source=.,target=/mnt/1euro oneeurofilter ``` -------------------------------- ### setBeta Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Sets the beta parameter of the filter, which influences latency reduction. ```APIDOC ## setBeta(beta) ### Description Sets the Beta parameter ### Parameters - **beta** (number) - Parameter to reduce latency (> 0). ### Returns - `void` ``` -------------------------------- ### setFrequency / setMinCutoff / setBeta / setDerivateCutoff / setParameters - JavaScript/TypeScript Source: https://context7.com/casiez/oneeurofilter/llms.txt Allows dynamic adjustment of the filter's parameters after initialization. ```APIDOC ## Parameter Setters (JS/TS) ### Description Allows dynamic adjustment of the filter's parameters after initialization. ### Methods - `setFrequency(freq)` - `setMinCutoff(mincutoff)` - `setBeta(beta)` - `setDerivateCutoff(dcutoff)` - `setParameters(freq, mincutoff, beta)` (TypeScript version) ### Example (TypeScript) ```typescript import { OneEuroFilter } from '1eurofilter'; const f = new OneEuroFilter(30, 1.0, 0.0, 1.0); // Adjust parameters dynamically f.setFrequency(60); f.setMinCutoff(0.5); f.setBeta(0.1); f.setDerivateCutoff(1.0); // Or set all at once (TypeScript version) f.setParameters(60, 0.5, 0.1); ``` ``` -------------------------------- ### OneEuroFilter setMinCutoff Method Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Modifies the minimum cutoff frequency in Hz. Lower values provide more jitter reduction but may introduce more lag. ```python setMinCutoff(mincutoff: float) ``` -------------------------------- ### OneEuroFilter.setMinCutoff Method Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Adjusts the minimum cutoff frequency in Hz. Lower values result in more jitter removal but may increase latency. ```typescript f.setMinCutoff(mincutoff) ``` -------------------------------- ### Individual Parameter Setters Source: https://context7.com/casiez/oneeurofilter/llms.txt Allows updating individual filter parameters (`setFrequency`, `setMinCutoff`, `setBeta`, `setDerivateCutoff`) one at a time. Setters related to frequency will raise a `ValueError` if a non-positive value is provided. ```APIDOC ## setFrequency(freq) / setMinCutoff(mincutoff) / setBeta(beta) / setDerivateCutoff(dcutoff) ### Description Individual setters to update one parameter at a time. All setters that accept a frequency raise `ValueError` if the value is ≤ 0. ### Method PATCH (Conceptual, as it modifies specific object state) ### Endpoint N/A (Method call on an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **freq** (float) - The new sampling rate in Hz (for `setFrequency`). Must be > 0. - **mincutoff** (float) - The new minimum cutoff frequency (for `setMinCutoff`). - **beta** (float) - The new beta value (for `setBeta`). - **dcutoff** (float) - The new derivative cutoff frequency (for `setDerivateCutoff`). ### Request Example ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.0) # Increase responsiveness dynamically (e.g., when user starts moving fast) f.setBeta(0.5) # Reduce jitter further (e.g., for precision drawing) f.setMinCutoff(0.5) # Adapt to a new data source running at a different rate f.setFrequency(120) try: f.setFrequency(-5) # raises ValueError except ValueError as e: print(f"Error: {e}") # Error: freq should be >0 ``` ### Response #### Success Response (200) None (Method modifies object state) #### Response Example None ``` -------------------------------- ### OneEuroFilter.setBeta Method Source: https://github.com/casiez/oneeurofilter/blob/main/typescript/Readme.md Updates the beta parameter of the filter, which influences latency reduction. Ensure the new beta value is greater than 0. ```typescript f.setBeta(beta) ``` -------------------------------- ### OneEuroFilter setFrequency Method Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md Updates the estimated frequency of the input signal in Hz. This is used when timestamps are not provided. ```python setFrequency(freq: float) ``` -------------------------------- ### Dynamically Adjust OneEuroFilter Parameters (TypeScript) Source: https://context7.com/casiez/oneeurofilter/llms.txt Shows how to modify the OneEuroFilter's parameters after initialization using setter methods or the `setParameters` method. This allows for runtime adjustments to the filter's behavior. ```typescript import { OneEuroFilter } from '1eurofilter'; const f = new OneEuroFilter(30, 1.0, 0.0, 1.0); // Adjust parameters dynamically f.setFrequency(60); f.setMinCutoff(0.5); f.setBeta(0.1); f.setDerivateCutoff(1.0); // Or set all at once (TypeScript version) f.setParameters(60, 0.5, 0.1); ``` -------------------------------- ### OneEuroFilter Class Source: https://github.com/casiez/oneeurofilter/blob/main/python/README.md The main class for the 1 Euro filter. It can be initialized with various parameters and used to filter noisy values. ```APIDOC ## class OneEuroFilter.OneEuroFilter.OneEuroFilter(freq: float, mincutoff: float = 1.0, beta: float = 0.0, dcutoff: float = 1.0) Bases: `object` ### filter(x: float, timestamp: float = None) Filters a noisy value. * **Parameters:** * **x** (*float*) – Noisy value to filter. * **timestamp** (*float**,* *optional*) – timestamp in seconds. * **Returns:** the filtered value * **Return type:** float ### reset() Resets the internal state of the filter. ### setBeta(beta: float) Sets the Beta parameter. * **Parameters:** **beta** (*float*) – Parameter to reduce latency (> 0). ### setDerivateCutoff(dcutoff: float) Sets the dcutoff parameter. * **Parameters:** **dcutoff** (*float*) – Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. ### setFrequency(freq: float) Sets the frequency of the input signal. * **Parameters:** **freq** (*float*) – An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. * **Raises:** **ValueError** – If one of the frequency is not >0 ### setMinCutoff(mincutoff: float) Sets the filter min cutoff frequency. * **Parameters:** **mincutoff** (*float*) – Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. * **Raises:** **ValueError** – If one of the frequency is not >0 ### setParameters(freq: float, mincutoff: float = 1.0, beta: float = 0.0, dcutoff=1.0) Sets all the parameters of the filter. * **Parameters:** * **freq** (*float*) – An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available. * **mincutoff** (*float**,* *optional*) – Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter. * **beta** (*float**,* *optional*) – Parameter to reduce latency (> 0). * **dcutoff** (*float**,* *optional*) – Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing. * **Raises:** **ValueError** – If one of the parameters is not >0 ``` -------------------------------- ### Reset OneEuroFilter State (Python) Source: https://context7.com/casiez/oneeurofilter/llms.txt Clears the internal low-pass filter state and timestamp memory. The next sample fed will be treated as the first, re-initializing the filter. ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.1) # Filter a stream for v in [5.0, 5.1, 4.9, 5.05]: print(f.filter(v)) # Reset before processing a new, unrelated stream f.reset() for v in [100.0, 100.2, 99.8, 100.1]: print(f.filter(v)) # starts fresh, no memory from previous stream ``` -------------------------------- ### reset() - Python Source: https://context7.com/casiez/oneeurofilter/llms.txt Clears the internal low-pass filter state and timestamp memory. The next sample fed will be treated as the first, re-initializing the filter. ```APIDOC ## reset() ### Description Clears the internal low-pass filter state and timestamp memory. The next sample fed will be treated as the first, re-initializing the filter. ### Method Signature `reset()` ### Example ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=60, mincutoff=1.0, beta=0.1) # Filter a stream for v in [5.0, 5.1, 4.9, 5.05]: print(f.filter(v)) # Reset before processing a new, unrelated stream f.reset() for v in [100.0, 100.2, 99.8, 100.1]: print(f.filter(v)) # starts fresh, no memory from previous stream ``` ``` -------------------------------- ### setParameters Source: https://context7.com/casiez/oneeurofilter/llms.txt Updates all filter parameters (`freq`, `mincutoff`, `beta`, `dcutoff`) simultaneously without resetting the filter's internal state. This allows for dynamic adjustments during runtime. ```APIDOC ## setParameters(freq, mincutoff, beta, dcutoff) ### Description Updates all filter parameters at once without resetting internal state. Useful for dynamically changing filter behavior at runtime. ### Method PUT (Conceptual, as it modifies object state) ### Endpoint N/A (Method call on an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **freq** (float) - The new expected sampling rate in Hz. - **mincutoff** (float) - The new minimum cutoff frequency for jitter reduction. - **beta** (float) - The new beta value for lag reduction. - **dcutoff** (float) - The new cutoff frequency for the derivative filter. ### Request Example ```python from OneEuroFilter import OneEuroFilter f = OneEuroFilter(freq=30, mincutoff=2.0, beta=0.0) # Process some data at 30 Hz with high jitter reduction for v in [1.0, 1.1, 0.9, 1.05]: print(f.filter(v)) # Switch to 60 Hz input with less jitter reduction, more responsiveness f.setParameters(freq=60, mincutoff=0.5, beta=0.2) for v in [2.0, 2.1, 1.95, 2.05]: print(f.filter(v)) ``` ### Response #### Success Response (200) None (Method modifies object state) #### Response Example None ```