gsl_fft__c_pass_5.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* fft/c_pass_5.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_5) (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. {
  32. size_t i = 0, j = 0;
  33. size_t k, k1;
  34. const size_t factor = 5;
  35. const size_t m = n / factor;
  36. const size_t q = n / product;
  37. const size_t p_1 = product / factor;
  38. const size_t jump = (factor - 1) * p_1;
  39. const ATOMIC sin_2pi_by_5 = sin (2.0 * M_PI / 5.0);
  40. const ATOMIC sin_2pi_by_10 = sin (2.0 * M_PI / 10.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;
  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. }
  56. else
  57. {
  58. if (sign == gsl_fft_forward)
  59. {
  60. /* forward tranform */
  61. w1_real = GSL_REAL(twiddle1[k - 1]);
  62. w1_imag = GSL_IMAG(twiddle1[k - 1]);
  63. w2_real = GSL_REAL(twiddle2[k - 1]);
  64. w2_imag = GSL_IMAG(twiddle2[k - 1]);
  65. w3_real = GSL_REAL(twiddle3[k - 1]);
  66. w3_imag = GSL_IMAG(twiddle3[k - 1]);
  67. w4_real = GSL_REAL(twiddle4[k - 1]);
  68. w4_imag = GSL_IMAG(twiddle4[k - 1]);
  69. }
  70. else
  71. {
  72. /* backward tranform: w -> conjugate(w) */
  73. w1_real = GSL_REAL(twiddle1[k - 1]);
  74. w1_imag = -GSL_IMAG(twiddle1[k - 1]);
  75. w2_real = GSL_REAL(twiddle2[k - 1]);
  76. w2_imag = -GSL_IMAG(twiddle2[k - 1]);
  77. w3_real = GSL_REAL(twiddle3[k - 1]);
  78. w3_imag = -GSL_IMAG(twiddle3[k - 1]);
  79. w4_real = GSL_REAL(twiddle4[k - 1]);
  80. w4_imag = -GSL_IMAG(twiddle4[k - 1]);
  81. }
  82. }
  83. for (k1 = 0; k1 < p_1; k1++)
  84. {
  85. ATOMIC x0_real, x0_imag, x1_real, x1_imag, x2_real, x2_imag,
  86. x3_real, x3_imag, x4_real, x4_imag;
  87. const ATOMIC z0_real = REAL(in,istride,i);
  88. const ATOMIC z0_imag = IMAG(in,istride,i);
  89. const ATOMIC z1_real = REAL(in,istride,i + m);
  90. const ATOMIC z1_imag = IMAG(in,istride,i + m);
  91. const ATOMIC z2_real = REAL(in,istride,i + 2*m);
  92. const ATOMIC z2_imag = IMAG(in,istride,i + 2*m);
  93. const ATOMIC z3_real = REAL(in,istride,i + 3*m);
  94. const ATOMIC z3_imag = IMAG(in,istride,i + 3*m);
  95. const ATOMIC z4_real = REAL(in,istride,i + 4*m);
  96. const ATOMIC z4_imag = IMAG(in,istride,i + 4*m);
  97. /* compute x = W(5) z */
  98. /* t1 = z1 + z4 */
  99. const ATOMIC t1_real = z1_real + z4_real;
  100. const ATOMIC t1_imag = z1_imag + z4_imag;
  101. /* t2 = z2 + z3 */
  102. const ATOMIC t2_real = z2_real + z3_real;
  103. const ATOMIC t2_imag = z2_imag + z3_imag;
  104. /* t3 = z1 - z4 */
  105. const ATOMIC t3_real = z1_real - z4_real;
  106. const ATOMIC t3_imag = z1_imag - z4_imag;
  107. /* t4 = z2 - z3 */
  108. const ATOMIC t4_real = z2_real - z3_real;
  109. const ATOMIC t4_imag = z2_imag - z3_imag;
  110. /* t5 = t1 + t2 */
  111. const ATOMIC t5_real = t1_real + t2_real;
  112. const ATOMIC t5_imag = t1_imag + t2_imag;
  113. /* t6 = (sqrt(5)/4)(t1 - t2) */
  114. const ATOMIC t6_real = (sqrt (5.0) / 4.0) * (t1_real - t2_real);
  115. const ATOMIC t6_imag = (sqrt (5.0) / 4.0) * (t1_imag - t2_imag);
  116. /* t7 = z0 - ((t5)/4) */
  117. const ATOMIC t7_real = z0_real - t5_real / 4.0;
  118. const ATOMIC t7_imag = z0_imag - t5_imag / 4.0;
  119. /* t8 = t7 + t6 */
  120. const ATOMIC t8_real = t7_real + t6_real;
  121. const ATOMIC t8_imag = t7_imag + t6_imag;
  122. /* t9 = t7 - t6 */
  123. const ATOMIC t9_real = t7_real - t6_real;
  124. const ATOMIC t9_imag = t7_imag - t6_imag;
  125. /* t10 = sin(2 pi/5) t3 + sin(2 pi/10) t4 */
  126. const ATOMIC t10_real = ((int) sign) * (sin_2pi_by_5 * t3_real +
  127. sin_2pi_by_10 * t4_real);
  128. const ATOMIC t10_imag = ((int) sign) * (sin_2pi_by_5 * t3_imag +
  129. sin_2pi_by_10 * t4_imag);
  130. /* t11 = sin(2 pi/10) t3 - sin(2 pi/5) t4 */
  131. const ATOMIC t11_real = ((int) sign) * (sin_2pi_by_10 * t3_real -
  132. sin_2pi_by_5 * t4_real);
  133. const ATOMIC t11_imag = ((int) sign) * (sin_2pi_by_10 * t3_imag -
  134. sin_2pi_by_5 * t4_imag);
  135. /* x0 = z0 + t5 */
  136. x0_real = z0_real + t5_real;
  137. x0_imag = z0_imag + t5_imag;
  138. /* x1 = t8 + i t10 */
  139. x1_real = t8_real - t10_imag;
  140. x1_imag = t8_imag + t10_real;
  141. /* x2 = t9 + i t11 */
  142. x2_real = t9_real - t11_imag;
  143. x2_imag = t9_imag + t11_real;
  144. /* x3 = t9 - i t11 */
  145. x3_real = t9_real + t11_imag;
  146. x3_imag = t9_imag - t11_real;
  147. /* x4 = t8 - i t10 */
  148. x4_real = t8_real + t10_imag;
  149. x4_imag = t8_imag - t10_real;
  150. /* apply twiddle factors */
  151. /* to0 = 1 * x0 */
  152. REAL(out,ostride,j) = x0_real;
  153. IMAG(out,ostride,j) = x0_imag;
  154. /* to1 = w1 * x1 */
  155. REAL(out,ostride,j + p_1) = w1_real * x1_real - w1_imag * x1_imag;
  156. IMAG(out,ostride,j + p_1) = w1_real * x1_imag + w1_imag * x1_real;
  157. /* to2 = w2 * x2 */
  158. REAL(out,ostride,j + 2*p_1) = w2_real * x2_real - w2_imag * x2_imag;
  159. IMAG(out,ostride,j+2*p_1) = w2_real * x2_imag + w2_imag * x2_real;
  160. /* to3 = w3 * x3 */
  161. REAL(out,ostride,j+3*p_1) = w3_real * x3_real - w3_imag * x3_imag;
  162. IMAG(out,ostride,j+3*p_1) = w3_real * x3_imag + w3_imag * x3_real;
  163. /* to4 = w4 * x4 */
  164. REAL(out,ostride,j+4*p_1) = w4_real * x4_real - w4_imag * x4_imag;
  165. IMAG(out,ostride,j+4*p_1) = w4_real * x4_imag + w4_imag * x4_real;
  166. i++;
  167. j++;
  168. }
  169. j += jump;
  170. }
  171. return 0;
  172. }