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.

fir.hpp 811B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "dsp/functions.hpp"
  3. namespace rack {
  4. /** Perform a direct convolution
  5. x[-len + 1] to x[0] must be defined
  6. */
  7. inline float convolve(const float *x, const float *kernel, int len) {
  8. float y = 0.0;
  9. for (int i = 0; i < len; i++) {
  10. y += x[-i] * kernel[i];
  11. }
  12. return y;
  13. }
  14. inline void blackmanHarrisWindow(float *x, int n) {
  15. const float a0 = 0.35875;
  16. const float a1 = 0.48829;
  17. const float a2 = 0.14128;
  18. const float a3 = 0.01168;
  19. for (int i = 0; i < n; i++) {
  20. x[i] *= a0
  21. - a1 * cosf(2 * M_PI * i / (n - 1))
  22. + a2 * cosf(4 * M_PI * i / (n - 1))
  23. - a3 * cosf(6 * M_PI * i / (n - 1));
  24. }
  25. }
  26. inline void boxcarFIR(float *x, int n, float cutoff) {
  27. for (int i = 0; i < n; i++) {
  28. float t = (float)i / (n - 1) * 2.0 - 1.0;
  29. x[i] = sinc(t * n * cutoff);
  30. }
  31. }
  32. } // namespace rack