ema Helper¶
-
template<size_t MaxDeps = 8, typename Source>
auto RxESP32::Helpers::Smoothing::ema(Source &source, decltype(source.get()) alpha, const typename Computed<decltype(source.get()), 1, MaxDeps>::Options &options = {})¶ Compute an exponential moving average (EMA) with configurable smoothing factor.
Creates a Computed signal that applies exponential smoothing to source values. Unlike simple moving average, EMA gives more weight to recent values while still considering all historical data with exponentially decaying influence.
- Since
v0.1.0
Formula: \(EMA_{new} = \alpha * current + (1 - \alpha) * EMA_{prev}\)
Signal<float> sensor; auto smoothed = ema(sensor, 0.2f); // 20% current, 80% history sensor.set(100.0); // smoothed.get() == 100.0 (first value) sensor.set(200.0); // smoothed.get() == 120.0 (0.2*200 + 0.8*100) sensor.set(300.0); // smoothed.get() == 156.0 (0.2*300 + 0.8*120)Note
Stateful helper. On first call, EMA is initialized to the first value.
alpha = 1.0disables smoothing (passes through current value).alpha = 2/(N+1)approximates N-period simple moving average.
Warning
Only accepts floating-point types (float, double).
See Also¶
Smoothing Helpers - Overview