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.

filter.c 1.9 KiB

20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
20 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This file is part of Aptdec.
  3. * Copyright (c) 2004-2009 Thierry Leconte (F4DWV), Xerbo (xerbo@protonmail.com) 2019
  4. *
  5. * Aptdec is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include <math.h>
  20. #include "filter.h"
  21. // Finite impulse response
  22. float fir(float *buff, const float *coeff, const int len) {
  23. double r;
  24. r = 0.0;
  25. for (int i = 0; i < len; i++) {
  26. r += buff[i] * coeff[i];
  27. }
  28. return(r);
  29. }
  30. /* IQ finite impulse response
  31. * Turn samples into a single IQ sample
  32. */
  33. void iqfir(float *buff, const float *coeff, const int len, double *I, double *Q) {
  34. double i, q;
  35. i = q = 0.0;
  36. for (int k = 0; k < len; k++) {
  37. q += buff[2*k] * coeff[k];
  38. i += buff[2*k];
  39. }
  40. i = buff[len-1] - (i / len);
  41. *I = i, *Q = q;
  42. }
  43. /* Gaussian finite impulse responce compensation
  44. * https://www.recordingblogs.com/wiki/gaussian-window
  45. */
  46. float rsfir(double *buff, const float *coeff, const int len, const double offset, const double delta) {
  47. double out;
  48. out = 0.0;
  49. double n = offset;
  50. for (int i = 0; i < (len-1)/delta-1; n += delta, i++) {
  51. int k;
  52. double alpha;
  53. k = (int)floor(n);
  54. alpha = n - k;
  55. out += buff[i] * (coeff[k] * (1.0 - alpha) + coeff[k + 1] * alpha);
  56. }
  57. return(out);
  58. }