You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
975 B

  1. #include "FIR.h"
  2. /*360hz 0.51Hz~8.9Hz 20190925*/
  3. #define taps 32
  4. static const float coefficients[taps] = {0.012177,0.01599,0.019905,0.02387,0.027827,0.031719,0.035487,0.039075,0.042426,0.045488,0.048212,0.050553,0.052475,0.053944,0.054937,0.055438,0.055438,0.054937,0.053944,0.052475,0.050553,0.048212,0.045488,0.042426,0.039075,0.035487,0.031719,0.027827,0.02387,0.019905,0.01599,0.012177};
  5. static float buffer[taps];
  6. unsigned offset;
  7. float FIR_filter(float input) {
  8. const float *coeff = coefficients;
  9. const float *coeff_end = coefficients + taps;
  10. float *buf_val = buffer + offset;
  11. *buf_val = input;
  12. float output_ = 0;
  13. while (buf_val >= buffer) {
  14. output_ += *buf_val-- * *coeff++;
  15. }
  16. buf_val = buffer + taps - 1;
  17. while (coeff < coeff_end) {
  18. output_ += *buf_val-- * *coeff++;
  19. }
  20. if (++offset >= taps) {
  21. offset = 0;
  22. }
  23. return output_;
  24. }
  25. void FIR_reset_buffer() {
  26. memset(buffer, 0, sizeof(float) * taps);
  27. offset = 0;
  28. }