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.
 
 
 
 
 

67 lines
2.0 KiB

  1. /*
  2. * Aptdec
  3. * Copyright (c) 2004 by Thierry Leconte (F4DWV)
  4. *
  5. * $Id$
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Library General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. */
  22. #include "filter.h"
  23. #include <math.h>
  24. // Sum of a matrix multiplication of 2 arrays
  25. float fir(float *buff, const float *coeff, const int len) {
  26. double r;
  27. r = 0.0;
  28. for (int i = 0; i < len; i++) {
  29. r += buff[i] * coeff[i];
  30. }
  31. return(r);
  32. }
  33. // Create an IQ sample from a sample buffer
  34. void iqfir(float *buff, const float *coeff, const int len, double *I, double *Q) {
  35. double i, q;
  36. i = q = 0.0;
  37. for (int k = 0; k < len; k++) {
  38. q += buff[2*k] * coeff[k];
  39. // Average out the I samples, which gives us the DC offset
  40. i += buff[2*k];
  41. }
  42. // Grab the peak value of the wave and subtract the DC offset
  43. i = buff[len-1] - (i / len);
  44. *I = i, *Q = q;
  45. }
  46. // Denoise, I don't know how it works, but it does
  47. float rsfir(double *buff, const float *coeff, const int len, const double offset, const double delta) {
  48. double out;
  49. out = 0.0;
  50. double n = offset;
  51. for (int i = 0; i < (len-1)/delta-1; n += delta, i++) {
  52. int k;
  53. double alpha;
  54. k = (int)floor(n);
  55. alpha = n - k;
  56. out += buff[i] * (coeff[k] * (1.0 - alpha) + coeff[k + 1] * alpha);
  57. }
  58. return(out);
  59. }