gsl_fft__c_pass_4.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* fft/c_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 int
  20. FUNCTION(fft_complex,pass_4) (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. {
  31. size_t i = 0, j = 0;
  32. size_t k, k1;
  33. const size_t factor = 4;
  34. const size_t m = n / factor;
  35. const size_t q = n / product;
  36. const size_t p_1 = product / factor;
  37. const size_t jump = (factor - 1) * p_1;
  38. for (k = 0; k < q; k++)
  39. {
  40. ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag;
  41. if (k == 0)
  42. {
  43. w1_real = 1.0;
  44. w1_imag = 0.0;
  45. w2_real = 1.0;
  46. w2_imag = 0.0;
  47. w3_real = 1.0;
  48. w3_imag = 0.0;
  49. }
  50. else
  51. {
  52. if (sign == gsl_fft_forward)
  53. {
  54. /* forward tranform */
  55. w1_real = GSL_REAL(twiddle1[k - 1]);
  56. w1_imag = GSL_IMAG(twiddle1[k - 1]);
  57. w2_real = GSL_REAL(twiddle2[k - 1]);
  58. w2_imag = GSL_IMAG(twiddle2[k - 1]);
  59. w3_real = GSL_REAL(twiddle3[k - 1]);
  60. w3_imag = GSL_IMAG(twiddle3[k - 1]);
  61. }
  62. else
  63. {
  64. /* backward tranform: w -> conjugate(w) */
  65. w1_real = GSL_REAL(twiddle1[k - 1]);
  66. w1_imag = -GSL_IMAG(twiddle1[k - 1]);
  67. w2_real = GSL_REAL(twiddle2[k - 1]);
  68. w2_imag = -GSL_IMAG(twiddle2[k - 1]);
  69. w3_real = GSL_REAL(twiddle3[k - 1]);
  70. w3_imag = -GSL_IMAG(twiddle3[k - 1]);
  71. }
  72. }
  73. for (k1 = 0; k1 < p_1; k1++)
  74. {
  75. const ATOMIC z0_real = REAL(in,istride,i);
  76. const ATOMIC z0_imag = IMAG(in,istride,i);
  77. const ATOMIC z1_real = REAL(in,istride,i+m);
  78. const ATOMIC z1_imag = IMAG(in,istride,i+m);
  79. const ATOMIC z2_real = REAL(in,istride,i+2*m);
  80. const ATOMIC z2_imag = IMAG(in,istride,i+2*m);
  81. const ATOMIC z3_real = REAL(in,istride,i+3*m);
  82. const ATOMIC z3_imag = IMAG(in,istride,i+3*m);
  83. /* compute x = W(4) z */
  84. /* t1 = z0 + z2 */
  85. const ATOMIC t1_real = z0_real + z2_real;
  86. const ATOMIC t1_imag = z0_imag + z2_imag;
  87. /* t2 = z1 + z3 */
  88. const ATOMIC t2_real = z1_real + z3_real;
  89. const ATOMIC t2_imag = z1_imag + z3_imag;
  90. /* t3 = z0 - z2 */
  91. const ATOMIC t3_real = z0_real - z2_real;
  92. const ATOMIC t3_imag = z0_imag - z2_imag;
  93. /* t4 = (+/-) (z1 - z3) */
  94. const ATOMIC t4_real = ((int) sign) * (z1_real - z3_real);
  95. const ATOMIC t4_imag = ((int) sign) * (z1_imag - z3_imag);
  96. /* x0 = t1 + t2 */
  97. const ATOMIC x0_real = t1_real + t2_real;
  98. const ATOMIC x0_imag = t1_imag + t2_imag;
  99. /* x1 = t3 + i t4 */
  100. const ATOMIC x1_real = t3_real - t4_imag;
  101. const ATOMIC x1_imag = t3_imag + t4_real;
  102. /* x2 = t1 - t2 */
  103. const ATOMIC x2_real = t1_real - t2_real;
  104. const ATOMIC x2_imag = t1_imag - t2_imag;
  105. /* x3 = t3 - i t4 */
  106. const ATOMIC x3_real = t3_real + t4_imag;
  107. const ATOMIC x3_imag = t3_imag - t4_real;
  108. /* apply twiddle factors */
  109. /* to0 = 1 * x0 */
  110. REAL(out,ostride,j) = x0_real;
  111. IMAG(out,ostride,j) = x0_imag;
  112. /* to1 = w1 * x1 */
  113. REAL(out, ostride, j + p_1) = w1_real * x1_real - w1_imag * x1_imag;
  114. IMAG(out, ostride, j + p_1) = w1_real * x1_imag + w1_imag * x1_real;
  115. /* to2 = w2 * x2 */
  116. REAL(out, ostride, j + 2 * p_1) = w2_real * x2_real - w2_imag * x2_imag;
  117. IMAG(out, ostride, j + 2 * p_1) = w2_real * x2_imag + w2_imag * x2_real;
  118. /* to3 = w3 * x3 */
  119. REAL(out, ostride, j + 3 * p_1) = w3_real * x3_real - w3_imag * x3_imag;
  120. IMAG(out, ostride, j + 3 * p_1) = w3_real * x3_imag + w3_imag * x3_real;
  121. i++;
  122. j++;
  123. }
  124. j += jump;
  125. }
  126. return 0;
  127. }