Skip to content

Commit

Permalink
add oneEuro filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DBraun committed Dec 14, 2024
1 parent a222717 commit c72994d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions filters.lib
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,49 @@ dynamicSmoothing(sensitivity, baseCF, x) = f ~ _ : ! , _
};
};


//-----------------`(fi.)oneEuro`----------------------------------
// The One Euro Filter (1€ Filter) is an adaptive lowpass filter.
// The input signal is smoothed according to an exponential
// moving average (EMA) whose alpha value is determined
// according to an EMA of the input's first-order derivative.
// This kind of filter is commonly used in object-tracking,
// not necessarily audio processing.
//
// #### Usage
//
// ```
// _ : oneEuro(derivativeCutoff, beta, minCutoff) : _
// ```
//
// Where:
//
// * `derivativeCutoff`: Used to filter the first derivative of the input. 1 Hz is a good default.
// * `beta`: "Speed" parameter where higher values reduce latency. Range is [0-1].
// * `minCutoff`: Minimum cutoff frequency in Hz. Lower values remove more jitter.
//
// #### References
// * <https://gery.casiez.net/1euro/>
//------------------------------------------------------------------------
declare oneEuro author "David Braun";
declare oneEuro copyright "Copyright (C) 2024 by David Braun <[email protected]>";
declare oneEuro license "MIT";
oneEuro(derivativeCutoff, beta, minCutoff, x) = x : ema(adaptiveCutoff)
with {
// exponential moving average that calculates its own alpha from a cutoff in Hz
// _ : ema(cutoff) : _
ema(cutoff) = tick ~ _
with {
alpha = 1.0 / (1.0 + ma.SR / (2 * ma.PI * cutoff));
tick(prev, y) = prev*(1-alpha) + y*alpha;
};

derivative = x - x';
derivativeFiltered = derivative : ema(derivativeCutoff);
adaptiveCutoff = minCutoff + beta * abs(derivativeFiltered);
};


//===========Linkwitz-Riley 4th-order 2-way, 3-way, and 4-way crossovers=====
//
// The Linkwitz-Riley (LR) crossovers are designed to produce a fully-flat
Expand Down

0 comments on commit c72994d

Please sign in to comment.