Advertisement
poosh

LPF

Mar 25th, 2025
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @brief Applies a Low-Pass Filter to the input samples, adding inertia to the system.
  3.  * @param y [in] previous/initial result of the function
  4.  *          [out] new result
  5.  * @param x new sample value
  6.  * @oaram dt time between the previous and the new sample
  7.  * @param rc time constant - the reference measurement time.
  8.  *  The higher rc, the more inertia (less impact of a single x on y)
  9.  */
  10. static function lpf(out float y, float x, float dt, float rc)
  11. {
  12.     local float a;
  13.  
  14.     a = dt / (rc + dt);
  15.     y = a * x + (1 - a) * y;
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement