FastLED 3.9.15
Loading...
Searching...
No Matches
cascaded_ema_impl.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/math/math.h"
4
5namespace fl {
6namespace detail {
7
8template <typename T, int Stages = 2>
10 public:
11 explicit CascadedEMAImpl(T tau_seconds, T initial = T(0))
12 : mTau(tau_seconds) {
13 for (int i = 0; i < Stages; ++i) {
14 mY[i] = initial;
15 }
16 }
17
18 T update(T input, T dt_seconds) {
19 T decay = fl::exp(-(dt_seconds / mTau));
20 T val = input;
21 for (int i = 0; i < Stages; ++i) {
22 mY[i] = val + (mY[i] - val) * decay;
23 val = mY[i];
24 }
25 return val;
26 }
27
28 T value() const { return mY[Stages - 1]; }
29 void setTau(T tau_seconds) { mTau = tau_seconds; }
30
31 void reset(T initial = T(0)) {
32 for (int i = 0; i < Stages; ++i) mY[i] = initial;
33 }
34
35 private:
37 T mY[Stages];
38};
39
40} // namespace detail
41} // namespace fl
T update(T input, T dt_seconds)
CascadedEMAImpl(T tau_seconds, T initial=T(0))
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179