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.
 
 
 
 
 

66 lines
1.8 KiB

  1. /*
  2. * This file is part of Aptdec.
  3. * Copyright (c) 2004-2009 Thierry Leconte (F4DWV), Xerbo (xerbo@protonmail.com) 2019-2020
  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. // Finite impulse response
  21. float fir(float *buff, const float *coeff, const int len) {
  22. double r;
  23. r = 0.0;
  24. for (int i = 0; i < len; i++) {
  25. r += buff[i] * coeff[i];
  26. }
  27. return (float)r;
  28. }
  29. /* IQ finite impulse response
  30. * Turn samples into a single IQ sample
  31. */
  32. void iqfir(float *buff, const float *coeff, const int len, double *I, double *Q) {
  33. double i = 0.0, q = 0.0;
  34. for (int k = 0; k < len; k++) {
  35. q += buff[2*k] * coeff[k];
  36. i += buff[2*k];
  37. }
  38. i = buff[len-1] - (i / len);
  39. *I = i, *Q = q;
  40. }
  41. /* Gaussian finite impulse responce compensation
  42. * https://www.recordingblogs.com/wiki/gaussian-window
  43. */
  44. float rsfir(double *buff, const float *coeff, const int len, const double offset, const double delta) {
  45. double out;
  46. out = 0.0;
  47. double n = offset;
  48. for (int i = 0; i < (len-1)/delta-1; n += delta, i++) {
  49. int k;
  50. double alpha;
  51. k = (int)floor(n);
  52. alpha = n - k;
  53. out += buff[i] * (coeff[k] * (1.0 - alpha) + coeff[k + 1] * alpha);
  54. }
  55. return (float)out;
  56. }