smoothing_filter.c 465 B

12345678910111213141516
  1. #include "smoothing_filter.h"
  2. void smoothing_filter_init(smoothing_filter_t *handle, float smoothing_factor)
  3. {
  4. handle->smoothing_factor = smoothing_factor;
  5. handle->prev_output = 0;
  6. }
  7. float smoothing_filter_process(smoothing_filter_t *handle, float current_input)
  8. {
  9. float output = current_input * handle->smoothing_factor +
  10. handle->prev_output * (1 - handle->smoothing_factor);
  11. handle->prev_output = output;
  12. return output;
  13. }