gsl_fft__real_pass_4.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* fft/real_pass_4.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_4) (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. const TYPE(gsl_complex) twiddle3[])
  29. {
  30. size_t k, k1;
  31. const size_t factor = 4;
  32. const size_t m = n / factor;
  33. const size_t q = n / product;
  34. const size_t product_1 = product / factor;
  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 size_t from3 = from2 + m;
  41. const ATOMIC z0_real = VECTOR(in,istride,from0);
  42. const ATOMIC z1_real = VECTOR(in,istride,from1);
  43. const ATOMIC z2_real = VECTOR(in,istride,from2);
  44. const ATOMIC z3_real = VECTOR(in,istride,from3);
  45. /* compute x = W(4) z */
  46. /* t1 = z0 + z2 */
  47. const ATOMIC t1_real = z0_real + z2_real;
  48. /* t2 = z1 + z3 */
  49. const ATOMIC t2_real = z1_real + z3_real;
  50. /* t3 = z0 - z2 */
  51. const ATOMIC t3_real = z0_real - z2_real;
  52. /* t4 = - (z1 - z3) */
  53. const ATOMIC t4_real = -(z1_real - z3_real);
  54. /* x0 = t1 + t2 */
  55. const ATOMIC x0_real = t1_real + t2_real;
  56. /* x1 = t3 + i t4 */
  57. const ATOMIC x1_real = t3_real;
  58. const ATOMIC x1_imag = t4_real;
  59. /* x2 = t1 - t2 */
  60. const ATOMIC x2_real = t1_real - t2_real;
  61. const size_t to0 = product * k1;
  62. const size_t to1 = to0 + 2 * product_1 - 1;
  63. const size_t to2 = to1 + 2 * product_1;
  64. VECTOR(out,ostride,to0) = x0_real;
  65. VECTOR(out,ostride,to1) = x1_real;
  66. VECTOR(out,ostride,to1 + 1) = x1_imag;
  67. VECTOR(out,ostride,to2) = x2_real;
  68. }
  69. if (product_1 == 1)
  70. return;
  71. for (k = 1; k < (product_1 + 1) / 2; k++)
  72. {
  73. ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag;
  74. w1_real = GSL_REAL(twiddle1[k - 1]);
  75. w1_imag = -GSL_IMAG(twiddle1[k - 1]);
  76. w2_real = GSL_REAL(twiddle2[k - 1]);
  77. w2_imag = -GSL_IMAG(twiddle2[k - 1]);
  78. w3_real = GSL_REAL(twiddle3[k - 1]);
  79. w3_imag = -GSL_IMAG(twiddle3[k - 1]);
  80. for (k1 = 0; k1 < q; k1++)
  81. {
  82. const size_t from0 = k1 * product_1 + 2 * k - 1;
  83. const size_t from1 = from0 + m;
  84. const size_t from2 = from1 + m;
  85. const size_t from3 = from2 + m;
  86. const ATOMIC f0_real = VECTOR(in,istride,from0);
  87. const ATOMIC f0_imag = VECTOR(in,istride,from0 + 1);
  88. const ATOMIC f1_real = VECTOR(in,istride,from1);
  89. const ATOMIC f1_imag = VECTOR(in,istride,from1 + 1);
  90. const ATOMIC f2_real = VECTOR(in,istride,from2);
  91. const ATOMIC f2_imag = VECTOR(in,istride,from2 + 1);
  92. const ATOMIC f3_real = VECTOR(in,istride,from3);
  93. const ATOMIC f3_imag = VECTOR(in,istride,from3 + 1);
  94. const ATOMIC z0_real = f0_real;
  95. const ATOMIC z0_imag = f0_imag;
  96. const ATOMIC z1_real = w1_real * f1_real - w1_imag * f1_imag;
  97. const ATOMIC z1_imag = w1_real * f1_imag + w1_imag * f1_real;
  98. const ATOMIC z2_real = w2_real * f2_real - w2_imag * f2_imag;
  99. const ATOMIC z2_imag = w2_real * f2_imag + w2_imag * f2_real;
  100. const ATOMIC z3_real = w3_real * f3_real - w3_imag * f3_imag;
  101. const ATOMIC z3_imag = w3_real * f3_imag + w3_imag * f3_real;
  102. /* compute x = W(4) z */
  103. /* t1 = z0 + z2 */
  104. const ATOMIC t1_real = z0_real + z2_real;
  105. const ATOMIC t1_imag = z0_imag + z2_imag;
  106. /* t2 = z1 + z3 */
  107. const ATOMIC t2_real = z1_real + z3_real;
  108. const ATOMIC t2_imag = z1_imag + z3_imag;
  109. /* t3 = z0 - z2 */
  110. const ATOMIC t3_real = z0_real - z2_real;
  111. const ATOMIC t3_imag = z0_imag - z2_imag;
  112. /* t4 = - (z1 - z3) */
  113. const ATOMIC t4_real = -(z1_real - z3_real);
  114. const ATOMIC t4_imag = -(z1_imag - z3_imag);
  115. /* x0 = t1 + t2 */
  116. const ATOMIC x0_real = t1_real + t2_real;
  117. const ATOMIC x0_imag = t1_imag + t2_imag;
  118. /* x1 = t3 + i t4 */
  119. const ATOMIC x1_real = t3_real - t4_imag;
  120. const ATOMIC x1_imag = t3_imag + t4_real;
  121. /* x2 = t1 - t2 */
  122. const ATOMIC x2_real = t1_real - t2_real;
  123. const ATOMIC x2_imag = t1_imag - t2_imag;
  124. /* x3 = t3 - i t4 */
  125. const ATOMIC x3_real = t3_real + t4_imag;
  126. const ATOMIC x3_imag = t3_imag - t4_real;
  127. const size_t to0 = k1 * product + 2 * k - 1;
  128. const size_t to1 = to0 + 2 * product_1;
  129. const size_t to2 = 2 * product_1 - 2 * k + k1 * product - 1;
  130. const size_t to3 = to2 + 2 * product_1;
  131. VECTOR(out,ostride,to0) = x0_real;
  132. VECTOR(out,ostride,to0 + 1) = x0_imag;
  133. VECTOR(out,ostride,to1) = x1_real;
  134. VECTOR(out,ostride,to1 + 1) = x1_imag;
  135. VECTOR(out,ostride,to3) = x2_real;
  136. VECTOR(out,ostride,to3 + 1) = -x2_imag;
  137. VECTOR(out,ostride,to2) = x3_real;
  138. VECTOR(out,ostride,to2 + 1) = -x3_imag;
  139. }
  140. }
  141. if (product_1 % 2 == 1)
  142. return;
  143. for (k1 = 0; k1 < q; k1++)
  144. {
  145. const size_t from0 = k1 * product_1 + product_1 - 1;
  146. const size_t from1 = from0 + m;
  147. const size_t from2 = from1 + m;
  148. const size_t from3 = from2 + m;
  149. const ATOMIC x0 = VECTOR(in,istride,from0);
  150. const ATOMIC x1 = VECTOR(in,istride,from1);
  151. const ATOMIC x2 = VECTOR(in,istride,from2);
  152. const ATOMIC x3 = VECTOR(in,istride,from3);
  153. const ATOMIC t1 = (1.0 / sqrt (2.0)) * (x1 - x3);
  154. const ATOMIC t2 = (1.0 / sqrt (2.0)) * (x1 + x3);
  155. const size_t to0 = k1 * product + 2 * k - 1;
  156. const size_t to1 = to0 + 2 * product_1;
  157. VECTOR(out,ostride,to0) = x0 + t1;
  158. VECTOR(out,ostride,to0 + 1) = -x2 - t2;
  159. VECTOR(out,ostride,to1) = x0 - t1;
  160. VECTOR(out,ostride,to1 + 1) = x2 - t2;
  161. }
  162. return;
  163. }