dc_blocker.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_DC_BLOCKER_H
  6. #define KLEINLIBC_DC_BLOCKER_H
  7. typedef struct
  8. {
  9. float blocking_factor;
  10. float gain;
  11. float prev_input;
  12. float prev_output;
  13. } dc_blocker_t;
  14. /**
  15. * @brief Initialize the DC blocker.
  16. *
  17. * @param handle Pointer to an instance of `dc_blocker_t`.
  18. * @param blocking_factor A floating point number between 0 and 1 that
  19. * determines how close to DC the cutoff frequency should be. A value close to (but less than)
  20. * 1 will result in a cutoff frequency very close to DC but with a slow response.
  21. * Setting the blocking factor lower will result in a faster response but will attenuate more
  22. * low frequency content. A value between 0.9 and 1 is reasonably in most cases.
  23. */
  24. void dc_blocker_init(dc_blocker_t *handle, float blocking_factor);
  25. /**
  26. * @brief Process the next input value.
  27. *
  28. * @param handle Pointer to an instance of `dc_blocker_t`.
  29. * @param current_input The input value to process.
  30. * @return float The filtered output value.
  31. */
  32. float dc_blocker_process(dc_blocker_t *handle, float current_input);
  33. #endif