gsl_fft__hc_pass_3.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* fft/hc_pass_3.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_3) (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) twiddle1[],
  27. const TYPE(gsl_complex) twiddle2[])
  28. {
  29. size_t i, j, k, k1, jump;
  30. size_t factor, q, m, product_1;
  31. ATOMIC tau = sqrt (3.0) / 2.0;
  32. i = 0;
  33. j = 0;
  34. factor = 3;
  35. m = n / factor;
  36. q = n / product;
  37. product_1 = product / factor;
  38. jump = (factor - 1) * q;
  39. for (k1 = 0; k1 < product_1; k1++)
  40. {
  41. const size_t from0 = 3 * k1 * q;
  42. const size_t from1 = from0 + 2 * q - 1;
  43. const ATOMIC z0_real = VECTOR(in,istride,from0);
  44. const ATOMIC z1_real = VECTOR(in,istride,from1);
  45. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  46. const ATOMIC t1_real = 2 * z1_real;
  47. const ATOMIC t2_real = z0_real - z1_real;
  48. const ATOMIC t3_imag = 2 * tau * z1_imag;
  49. const size_t to0 = q * k1;
  50. const size_t to1 = to0 + m;
  51. const size_t to2 = to1 + m;
  52. VECTOR(out,ostride,to0) = z0_real + t1_real;
  53. VECTOR(out,ostride,to1) = t2_real - t3_imag;
  54. VECTOR(out,ostride,to2) = t2_real + t3_imag;
  55. }
  56. if (q == 1)
  57. return;
  58. for (k = 1; k < (q + 1) / 2; k++)
  59. {
  60. const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
  61. const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
  62. const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
  63. const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
  64. for (k1 = 0; k1 < product_1; k1++)
  65. {
  66. const size_t from0 = 3 * k1 * q + 2 * k - 1;
  67. const size_t from1 = from0 + 2 * q;
  68. const size_t from2 = 3 * k1 * q - 2 * k + 2 * q - 1;
  69. const ATOMIC z0_real = VECTOR(in,istride,from0);
  70. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  71. const ATOMIC z1_real = VECTOR(in,istride,from1);
  72. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  73. const ATOMIC z2_real = VECTOR(in,istride,from2);
  74. const ATOMIC z2_imag = -VECTOR(in,istride,from2 + 1);
  75. /* compute x = W(3) z */
  76. /* t1 = z1 + z2 */
  77. const ATOMIC t1_real = z1_real + z2_real;
  78. const ATOMIC t1_imag = z1_imag + z2_imag;
  79. /* t2 = z0 - t1/2 */
  80. const ATOMIC t2_real = z0_real - t1_real / 2.0;
  81. const ATOMIC t2_imag = z0_imag - t1_imag / 2.0;
  82. /* t3 = sin(pi/3)*(z1 - z2) */
  83. const ATOMIC t3_real = tau * (z1_real - z2_real);
  84. const ATOMIC t3_imag = tau * (z1_imag - z2_imag);
  85. /* x0 = z0 + t1 */
  86. const ATOMIC x0_real = z0_real + t1_real;
  87. const ATOMIC x0_imag = z0_imag + t1_imag;
  88. /* x1 = t2 + i t3 */
  89. const ATOMIC x1_real = t2_real - t3_imag;
  90. const ATOMIC x1_imag = t2_imag + t3_real;
  91. /* x2 = t2 - i t3 */
  92. const ATOMIC x2_real = t2_real + t3_imag;
  93. const ATOMIC x2_imag = t2_imag - t3_real;
  94. const size_t to0 = k1 * q + 2 * k - 1;
  95. const size_t to1 = to0 + m;
  96. const size_t to2 = to1 + m;
  97. VECTOR(out,ostride,to0) = x0_real;
  98. VECTOR(out,ostride,to0 + 1) = x0_imag;
  99. VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
  100. VECTOR(out,ostride,to1 + 1) = w1_imag * x1_real + w1_real * x1_imag;
  101. VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
  102. VECTOR(out,ostride,to2 + 1) = w2_imag * x2_real + w2_real * x2_imag;
  103. }
  104. }
  105. if (q % 2 == 1)
  106. return;
  107. for (k1 = 0; k1 < product_1; k1++)
  108. {
  109. const size_t from0 = 3 * k1 * q + q - 1;
  110. const size_t from1 = from0 + 2 * q;
  111. const ATOMIC z0_real = VECTOR(in,istride,from0);
  112. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  113. const ATOMIC z1_real = VECTOR(in,istride,from1);
  114. const ATOMIC t1_real = z0_real - z1_real;
  115. const ATOMIC t2_real = 2 * tau * z0_imag;
  116. const ATOMIC x0_real = 2 * z0_real + z1_real;
  117. const ATOMIC x1_real = t1_real - t2_real;
  118. const ATOMIC x2_real = -t1_real - t2_real;
  119. const size_t to0 = k1 * q + q - 1;
  120. const size_t to1 = to0 + m;
  121. const size_t to2 = to1 + m;
  122. VECTOR(out,ostride,to0) = x0_real;
  123. VECTOR(out,ostride,to1) = x1_real;
  124. VECTOR(out,ostride,to2) = x2_real;
  125. }
  126. return;
  127. }