smoothing_filter.h 980 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Quick and simple digital filters for smoothing and DC removal
  3. * https://kleinembedded.com/quick-and-simple-digital-filters-for-smoothing-and-dc-removal/
  4. */
  5. #ifndef KLEINLIBC_SMOOTHING_FILTER_H
  6. #define KLEINLIBC_SMOOTHING_FILTER_H
  7. typedef struct
  8. {
  9. float smoothing_factor;
  10. float prev_output;
  11. } smoothing_filter_t;
  12. /**
  13. * @brief Initialize smoothing filter.
  14. *
  15. * @param handle Pointer to an instance of `smoothing_filter_t`.
  16. * @param smoothing_factor A floating point number between 0 and 1 that determines how much smoothing to apply.
  17. * Smaller values apply more smoothing.
  18. */
  19. void smoothing_filter_init(smoothing_filter_t *handle, float smoothing_factor);
  20. /**
  21. * @brief Process the next input value.
  22. *
  23. * @param handle Pointer to an instance of `smoothing_filter_t`.
  24. * @param current_input The input value to process.
  25. * @return float The filtered output value.
  26. */
  27. float smoothing_filter_process(smoothing_filter_t *handle, float current_input);
  28. #endif