Fir.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool
  3. * Generated by MATLAB(R) 9.9 and Signal Processing Toolbox 8.5.
  4. * Generated on: 06-Oct-2022 12:50:19
  5. */
  6. /*
  7. * 离散时间 FIR 滤波器(实数)
  8. * ----------------
  9. * 滤波器结构 : 直接型 FIR
  10. * 滤波器长度 : 16
  11. * 稳定 : 是
  12. * 线性相位 : 是 (Type 2)
  13. */
  14. /* General type conversion for MATLAB generated C-code */
  15. //#include "tmwtypes.h"
  16. /*
  17. * Expected path to tmwtypes.h
  18. * D:\Program Files\R2020b\extern\include\tmwtypes.h
  19. */
  20. /*
  21. * Warning - Filter coefficients were truncated to fit specified data type.
  22. * The resulting response may not match generated theoretical response.
  23. * Use the Filter Design & Analysis Tool to design accurate
  24. * single-precision filter coefficients.
  25. */
  26. #include "math/fir.h"
  27. static const float Fir_Ceofs[16] = {
  28. 0.007895005867, 0.01734124683, 0.03257999197, 0.05209516734, 0.07380001992,
  29. 0.09460353851, 0.1110314056, 0.1201113388, 0.1201113388, 0.1110314056,
  30. 0.09460353851, 0.07380001992, 0.05209516734, 0.03257999197, 0.01734124683,
  31. 0.007895005867
  32. };
  33. void Fir_init(Fir_t *fir) {
  34. for (int i = 0; i < FIR_Ceof_Len; i++) {
  35. fir->X[0] = 0.0f;
  36. }
  37. fir->k = 0;
  38. }
  39. float Fir_Filter(Fir_t *fir, float in) {
  40. float out = 0;
  41. fir->X[fir->k] = in;
  42. for (int i = 1; i <= FIR_Ceof_Len; i++) {
  43. out += Fir_Ceofs[i-1] * fir->X[(i+fir->k) % FIR_Ceof_Len];
  44. }
  45. fir->k = (fir->k + 1) % FIR_Ceof_Len;
  46. return out;
  47. }