gsl_fft__c_pass_6.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* fft/c_pass_6.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 int
  20. FUNCTION(fft_complex,pass_6) (const BASE in[],
  21. const size_t istride,
  22. BASE out[],
  23. const size_t ostride,
  24. const gsl_fft_direction sign,
  25. const size_t product,
  26. const size_t n,
  27. const TYPE(gsl_complex) twiddle1[],
  28. const TYPE(gsl_complex) twiddle2[],
  29. const TYPE(gsl_complex) twiddle3[],
  30. const TYPE(gsl_complex) twiddle4[],
  31. const TYPE(gsl_complex) twiddle5[])
  32. {
  33. size_t i = 0, j = 0;
  34. size_t k, k1;
  35. const size_t factor = 6;
  36. const size_t m = n / factor;
  37. const size_t q = n / product;
  38. const size_t p_1 = product / factor;
  39. const size_t jump = (factor - 1) * p_1;
  40. const ATOMIC tau = sqrt (3.0) / 2.0;
  41. for (k = 0; k < q; k++)
  42. {
  43. ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag, w4_real,
  44. w4_imag, w5_real, w5_imag;
  45. if (k == 0)
  46. {
  47. w1_real = 1.0;
  48. w1_imag = 0.0;
  49. w2_real = 1.0;
  50. w2_imag = 0.0;
  51. w3_real = 1.0;
  52. w3_imag = 0.0;
  53. w4_real = 1.0;
  54. w4_imag = 0.0;
  55. w5_real = 1.0;
  56. w5_imag = 0.0;
  57. }
  58. else
  59. {
  60. if (sign == gsl_fft_forward)
  61. {
  62. /* forward tranform */
  63. w1_real = GSL_REAL(twiddle1[k - 1]);
  64. w1_imag = GSL_IMAG(twiddle1[k - 1]);
  65. w2_real = GSL_REAL(twiddle2[k - 1]);
  66. w2_imag = GSL_IMAG(twiddle2[k - 1]);
  67. w3_real = GSL_REAL(twiddle3[k - 1]);
  68. w3_imag = GSL_IMAG(twiddle3[k - 1]);
  69. w4_real = GSL_REAL(twiddle4[k - 1]);
  70. w4_imag = GSL_IMAG(twiddle4[k - 1]);
  71. w5_real = GSL_REAL(twiddle5[k - 1]);
  72. w5_imag = GSL_IMAG(twiddle5[k - 1]);
  73. }
  74. else
  75. {
  76. /* backward tranform: w -> conjugate(w) */
  77. w1_real = GSL_REAL(twiddle1[k - 1]);
  78. w1_imag = -GSL_IMAG(twiddle1[k - 1]);
  79. w2_real = GSL_REAL(twiddle2[k - 1]);
  80. w2_imag = -GSL_IMAG(twiddle2[k - 1]);
  81. w3_real = GSL_REAL(twiddle3[k - 1]);
  82. w3_imag = -GSL_IMAG(twiddle3[k - 1]);
  83. w4_real = GSL_REAL(twiddle4[k - 1]);
  84. w4_imag = -GSL_IMAG(twiddle4[k - 1]);
  85. w5_real = GSL_REAL(twiddle5[k - 1]);
  86. w5_imag = -GSL_IMAG(twiddle5[k - 1]);
  87. }
  88. }
  89. for (k1 = 0; k1 < p_1; k1++)
  90. {
  91. const ATOMIC z0_real = REAL(in,istride,i);
  92. const ATOMIC z0_imag = IMAG(in,istride,i);
  93. const ATOMIC z1_real = REAL(in,istride,i+m);
  94. const ATOMIC z1_imag = IMAG(in,istride,i+m);
  95. const ATOMIC z2_real = REAL(in,istride,i+2*m);
  96. const ATOMIC z2_imag = IMAG(in,istride,i+2*m);
  97. const ATOMIC z3_real = REAL(in,istride,i+3*m);
  98. const ATOMIC z3_imag = IMAG(in,istride,i+3*m);
  99. const ATOMIC z4_real = REAL(in,istride,i+4*m);
  100. const ATOMIC z4_imag = IMAG(in,istride,i+4*m);
  101. const ATOMIC z5_real = REAL(in,istride,i+5*m);
  102. const ATOMIC z5_imag = IMAG(in,istride,i+5*m);
  103. /* compute x = W(6) z */
  104. /* W(6) is a combination of sums and differences of W(3) acting
  105. on the even and odd elements of z */
  106. /* ta1 = z2 + z4 */
  107. const ATOMIC ta1_real = z2_real + z4_real;
  108. const ATOMIC ta1_imag = z2_imag + z4_imag;
  109. /* ta2 = z0 - ta1/2 */
  110. const ATOMIC ta2_real = z0_real - ta1_real / 2;
  111. const ATOMIC ta2_imag = z0_imag - ta1_imag / 2;
  112. /* ta3 = (+/-) sin(pi/3)*(z2 - z4) */
  113. const ATOMIC ta3_real = ((int) sign) * tau * (z2_real - z4_real);
  114. const ATOMIC ta3_imag = ((int) sign) * tau * (z2_imag - z4_imag);
  115. /* a0 = z0 + ta1 */
  116. const ATOMIC a0_real = z0_real + ta1_real;
  117. const ATOMIC a0_imag = z0_imag + ta1_imag;
  118. /* a1 = ta2 + i ta3 */
  119. const ATOMIC a1_real = ta2_real - ta3_imag;
  120. const ATOMIC a1_imag = ta2_imag + ta3_real;
  121. /* a2 = ta2 - i ta3 */
  122. const ATOMIC a2_real = ta2_real + ta3_imag;
  123. const ATOMIC a2_imag = ta2_imag - ta3_real;
  124. /* tb1 = z5 + z1 */
  125. const ATOMIC tb1_real = z5_real + z1_real;
  126. const ATOMIC tb1_imag = z5_imag + z1_imag;
  127. /* tb2 = z3 - tb1/2 */
  128. const ATOMIC tb2_real = z3_real - tb1_real / 2;
  129. const ATOMIC tb2_imag = z3_imag - tb1_imag / 2;
  130. /* tb3 = (+/-) sin(pi/3)*(z5 - z1) */
  131. const ATOMIC tb3_real = ((int) sign) * tau * (z5_real - z1_real);
  132. const ATOMIC tb3_imag = ((int) sign) * tau * (z5_imag - z1_imag);
  133. /* b0 = z3 + tb1 */
  134. const ATOMIC b0_real = z3_real + tb1_real;
  135. const ATOMIC b0_imag = z3_imag + tb1_imag;
  136. /* b1 = tb2 + i tb3 */
  137. const ATOMIC b1_real = tb2_real - tb3_imag;
  138. const ATOMIC b1_imag = tb2_imag + tb3_real;
  139. /* b2 = tb2 - i tb3 */
  140. const ATOMIC b2_real = tb2_real + tb3_imag;
  141. const ATOMIC b2_imag = tb2_imag - tb3_real;
  142. /* x0 = a0 + b0 */
  143. const ATOMIC x0_real = a0_real + b0_real;
  144. const ATOMIC x0_imag = a0_imag + b0_imag;
  145. /* x4 = a1 + b1 */
  146. const ATOMIC x4_real = a1_real + b1_real;
  147. const ATOMIC x4_imag = a1_imag + b1_imag;
  148. /* x2 = a2 + b2 */
  149. const ATOMIC x2_real = a2_real + b2_real;
  150. const ATOMIC x2_imag = a2_imag + b2_imag;
  151. /* x3 = a0 - b0 */
  152. const ATOMIC x3_real = a0_real - b0_real;
  153. const ATOMIC x3_imag = a0_imag - b0_imag;
  154. /* x1 = a1 - b1 */
  155. const ATOMIC x1_real = a1_real - b1_real;
  156. const ATOMIC x1_imag = a1_imag - b1_imag;
  157. /* x5 = a2 - b2 */
  158. const ATOMIC x5_real = a2_real - b2_real;
  159. const ATOMIC x5_imag = a2_imag - b2_imag;
  160. /* apply twiddle factors */
  161. /* to0 = 1 * x0 */
  162. REAL(out,ostride,j) = x0_real;
  163. IMAG(out,ostride,j) = x0_imag;
  164. /* to1 = w1 * x1 */
  165. REAL(out,ostride,j+p_1) = w1_real * x1_real - w1_imag * x1_imag;
  166. IMAG(out,ostride,j+p_1) = w1_real * x1_imag + w1_imag * x1_real;
  167. /* to2 = w2 * x2 */
  168. REAL(out,ostride,j+2*p_1) = w2_real * x2_real - w2_imag * x2_imag;
  169. IMAG(out,ostride,j+2*p_1) = w2_real * x2_imag + w2_imag * x2_real;
  170. /* to3 = w3 * x3 */
  171. REAL(out,ostride,j+3*p_1) = w3_real * x3_real - w3_imag * x3_imag;
  172. IMAG(out,ostride,j+3*p_1) = w3_real * x3_imag + w3_imag * x3_real;
  173. /* to4 = w4 * x4 */
  174. REAL(out,ostride,j+4*p_1) = w4_real * x4_real - w4_imag * x4_imag;
  175. IMAG(out,ostride,j+4*p_1) = w4_real * x4_imag + w4_imag * x4_real;
  176. /* to5 = w5 * x5 */
  177. REAL(out,ostride,j+5*p_1) = w5_real * x5_real - w5_imag * x5_imag;
  178. IMAG(out,ostride,j+5*p_1) = w5_real * x5_imag + w5_imag * x5_real;
  179. i++;
  180. j++;
  181. }
  182. j += jump;
  183. }
  184. return 0;
  185. }