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.
 
 
 
 
 

83 lines
2.2 KiB

  1. /*
  2. * Atpdec
  3. * Copyright (c) 2003 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. float
  24. fir (float *buff, const float *coeff, const int len)
  25. {
  26. int i;
  27. double r;
  28. r = 0.0;
  29. for (i = 0; i < len; i++) {
  30. r += buff[i] * coeff[i];
  31. }
  32. return r;
  33. }
  34. void
  35. iqfir (float *buff, const float *Icoeff, const float *Qcoeff, const int len,
  36. float *Iptr, float *Qptr)
  37. {
  38. int i;
  39. float I, Q;
  40. I = Q = 0.0;
  41. for (i = 0; i < len; i++) {
  42. double v;
  43. v = buff[i];
  44. I += v * Icoeff[i];
  45. Q += v * Qcoeff[i];
  46. } *Iptr = I;
  47. *Qptr = Q;
  48. } float
  49. rsfir (float *buff, const float *coeff, const int len, const double offset,
  50. const double delta)
  51. {
  52. int i;
  53. double n;
  54. double out;
  55. out = 0.0;
  56. for (i = 0, n = offset; n < len - 1; n += delta, i++) {
  57. int k;
  58. double alpha;
  59. k = (int) n;
  60. alpha = n - k;
  61. out += buff[i] * (coeff[k] * (1.0 - alpha) + coeff[k + 1] * alpha);
  62. } return out;
  63. }
  64. double
  65. iir (double x, iirbuff_t * buff, const iircoeff_t * coeff)
  66. {
  67. buff->x[4] = buff->x[3];
  68. buff->x[3] = buff->x[2];
  69. buff->x[2] = buff->x[1];
  70. buff->x[1] = buff->x[0];
  71. buff->x[0] = x / coeff->G;
  72. buff->y[2] = buff->y[1];
  73. buff->y[1] = buff->y[0];
  74. buff->y[0] = buff->x[4]
  75. +coeff->x[2] * buff->x[3]
  76. +coeff->x[1] * buff->x[2]
  77. +coeff->x[0] * buff->x[1]
  78. +buff->x[0] +coeff->y[1] * buff->y[2] +coeff->y[0] * buff->y[1];
  79. return (buff->y[0]);
  80. }