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 2.1 KiB

21 years ago
21 years ago
21 years ago
21 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Atpdec
  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. float fir(float *buff, const float *coeff, const int len)
  24. {
  25. int i;
  26. double r;
  27. r = 0.0;
  28. for (i = 0; i < len; i++) {
  29. r += buff[i] * coeff[i];
  30. }
  31. return r;
  32. }
  33. void
  34. iqfir(float *buff, const float *Icoeff, const float *Qcoeff, const int len,
  35. float *Iptr, float *Qptr)
  36. {
  37. int i;
  38. float I, Q;
  39. I = Q = 0.0;
  40. for (i = 0; i < len; i++) {
  41. double v;
  42. v = buff[i];
  43. I += v * Icoeff[i];
  44. Q += v * Qcoeff[i];
  45. } *Iptr = I;
  46. *Qptr = Q;
  47. }
  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 iir(double x, iirbuff_t * buff, const iircoeff_t * coeff)
  65. {
  66. buff->x[4] = buff->x[3];
  67. buff->x[3] = buff->x[2];
  68. buff->x[2] = buff->x[1];
  69. buff->x[1] = buff->x[0];
  70. buff->x[0] = x / coeff->G;
  71. buff->y[2] = buff->y[1];
  72. buff->y[1] = buff->y[0];
  73. buff->y[0] = buff->x[4]
  74. + coeff->x[2] * buff->x[3]
  75. + coeff->x[1] * buff->x[2]
  76. + coeff->x[0] * buff->x[1]
  77. + buff->x[0] + coeff->y[1] * buff->y[2] + coeff->y[0] * buff->y[1];
  78. return (buff->y[0]);
  79. }