lowpass.c 534 B

12345678910111213141516171819202122232425
  1. /*
  2. * lowpass.c
  3. *
  4. * Created on: 2023Äê4ÔÂ3ÈÕ
  5. * Author: wangd
  6. */
  7. #include "lowpass.h"
  8. // cutoff khz ,Ts ms
  9. long a1,a2,a3,a4;
  10. long lowpassfilter(long sample_1,long sample,long cutoff,long Ts)
  11. {
  12. //1.0f/(M_2PI*cutoff) rc = 1.0f/(M_2PI*cutoff)
  13. //alpha = Ts/(Ts + rc) = 1/(1 + Ts*2*pi*f)
  14. long t = Ts*cutoff>>12;
  15. long rcf = (25736*t)>>12;// M_2PI 25736
  16. long Hg = _IQ12div(4096,rcf);
  17. long alpha = _IQ12div(4096,4096+Hg);
  18. long result = (4096-alpha)*sample_1+alpha*sample;
  19. return result>>12;
  20. }