1eurofilter
Version:
Algorithm to filter noisy signals for high precision and responsiveness.
96 lines (94 loc) • 3.98 kB
TypeScript
/**
* Author: Alix Giguey and Gery Casiez
* Details: https://gery.casiez.net/1euro/
*
* Copyright 2019 Inria
*
* BSD License https://opensource.org/licenses/BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
export declare class OneEuroFilter {
private freq;
private mincutoff;
private beta;
private dcutoff;
private x;
private dx;
private lasttime;
private alpha;
/**
* Sets the frequency of the signal
*
* @param freq An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
*/
setFrequency(freq: number): void;
/**
* Sets the filter min cutoff frequency
*
* @param mincutoff Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
*/
setMinCutoff(mincutoff: number): void;
/**
* Sets the Beta parameter
*
* @param beta Parameter to reduce latency (> 0).
*/
setBeta(beta: number): void;
/**
* Sets the dcutoff parameter
*
* @param dcutoff Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*/
setDerivateCutoff(dcutoff: number): void;
/**
* Sets the parameters of the 1 euro filter.
*
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0).
*
*/
setParameters(freq: number, mincutoff: number, beta: number): void;
/**
* Constructs a 1 euro filter.
*
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param mincutoff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0).
* @param dcutoff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*
*/
constructor(freq: number, mincutoff?: number, beta?: number, dcutoff?: number);
/**
* Resets the internal state of the filter.
*/
reset(): void;
/**
* Returns the filtered value.
*
* @param value - Noisy value to filter
* @param timestamp - (optional) timestamp in seconds
* @returns The filtered value
*
*/
filter(value: number, timestamp: number | undefined): number;
}