gsl_fft__hc_pass_2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* fft/hc_pass_2.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program 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 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * 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, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. static void
  20. FUNCTION(fft_halfcomplex,pass_2) (const BASE in[],
  21. const size_t istride,
  22. BASE out[],
  23. const size_t ostride,
  24. const size_t product,
  25. const size_t n,
  26. const TYPE(gsl_complex) twiddle[])
  27. {
  28. size_t i, j, k, k1, jump;
  29. size_t factor, q, m, product_1;
  30. i = 0;
  31. j = 0;
  32. factor = 2;
  33. m = n / factor;
  34. q = n / product;
  35. product_1 = product / factor;
  36. jump = (factor - 1) * q;
  37. for (k1 = 0; k1 < product_1; k1++)
  38. {
  39. const ATOMIC r0 = VECTOR(in,istride,2 * k1 * q);
  40. const ATOMIC r1 = VECTOR(in,istride,2 * k1 * q + 2 * q - 1);
  41. const ATOMIC s0 = r0 + r1;
  42. const ATOMIC s1 = r0 - r1;
  43. VECTOR(out,ostride,q * k1) = s0;
  44. VECTOR(out,ostride,q * k1 + m) = s1;
  45. }
  46. if (q == 1)
  47. return;
  48. for (k = 1; k < (q + 1) / 2; k++)
  49. {
  50. const ATOMIC w_real = GSL_REAL(twiddle[k - 1]);
  51. const ATOMIC w_imag = GSL_IMAG(twiddle[k - 1]);
  52. for (k1 = 0; k1 < product_1; k1++)
  53. {
  54. const size_t from0 = 2 * k1 * q + 2 * k - 1;
  55. const size_t from1 = 2 * k1 * q - 2 * k + 2 * q - 1;
  56. const ATOMIC z0_real = VECTOR(in,istride,from0);
  57. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  58. const ATOMIC z1_real = VECTOR(in,istride,from1);
  59. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  60. /* compute x = W(2) z */
  61. /* x0 = z0 + z1 */
  62. const ATOMIC x0_real = z0_real + z1_real;
  63. const ATOMIC x0_imag = z0_imag - z1_imag;
  64. /* x1 = z0 - z1 */
  65. const ATOMIC x1_real = z0_real - z1_real;
  66. const ATOMIC x1_imag = z0_imag + z1_imag;
  67. const size_t to0 = k1 * q + 2 * k - 1;
  68. const size_t to1 = to0 + m;
  69. VECTOR(out,ostride,to0) = x0_real;
  70. VECTOR(out,ostride,to0 + 1) = x0_imag;
  71. VECTOR(out,ostride,to1) = w_real * x1_real - w_imag * x1_imag;
  72. VECTOR(out,ostride,to1 + 1) = w_imag * x1_real + w_real * x1_imag;
  73. }
  74. }
  75. if (q % 2 == 1)
  76. return;
  77. for (k1 = 0; k1 < product_1; k1++)
  78. {
  79. const size_t from0 = 2 * k1 * q + q - 1;
  80. const size_t to0 = k1 * q + q - 1;
  81. const size_t to1 = to0 + m;
  82. VECTOR(out,ostride,to0) = 2 * VECTOR(in,istride,from0);
  83. VECTOR(out,ostride,to1) = -2 * VECTOR(in,istride,from0 + 1);
  84. }
  85. return;
  86. }