gsl_fft__real_pass_3.c 5.7 KB

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