gsl_fft__c_pass_2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* fft/c_pass_2.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_2) (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) twiddle[])
  28. {
  29. size_t i = 0, j = 0;
  30. size_t k, k1;
  31. const size_t factor = 2;
  32. const size_t m = n / factor;
  33. const size_t q = n / product;
  34. const size_t product_1 = product / factor;
  35. const size_t jump = (factor - 1) * product_1;
  36. for (k = 0; k < q; k++)
  37. {
  38. ATOMIC w_real, w_imag;
  39. if (k == 0)
  40. {
  41. w_real = 1.0;
  42. w_imag = 0.0;
  43. }
  44. else
  45. {
  46. if (sign == gsl_fft_forward)
  47. {
  48. /* forward tranform */
  49. w_real = GSL_REAL(twiddle[k - 1]);
  50. w_imag = GSL_IMAG(twiddle[k - 1]);
  51. }
  52. else
  53. {
  54. /* backward tranform: w -> conjugate(w) */
  55. w_real = GSL_REAL(twiddle[k - 1]);
  56. w_imag = -GSL_IMAG(twiddle[k - 1]);
  57. }
  58. }
  59. for (k1 = 0; k1 < product_1; k1++)
  60. {
  61. const ATOMIC z0_real = REAL(in,istride,i);
  62. const ATOMIC z0_imag = IMAG(in,istride,i);
  63. const ATOMIC z1_real = REAL(in,istride,i+m);
  64. const ATOMIC z1_imag = IMAG(in,istride,i+m);
  65. /* compute x = W(2) z */
  66. /* x0 = z0 + z1 */
  67. const ATOMIC x0_real = z0_real + z1_real;
  68. const ATOMIC x0_imag = z0_imag + z1_imag;
  69. /* x1 = z0 - z1 */
  70. const ATOMIC x1_real = z0_real - z1_real;
  71. const ATOMIC x1_imag = z0_imag - z1_imag;
  72. /* apply twiddle factors */
  73. /* out0 = 1 * x0 */
  74. REAL(out,ostride,j) = x0_real;
  75. IMAG(out,ostride,j) = x0_imag;
  76. /* out1 = w * x1 */
  77. REAL(out,ostride,j+product_1) = w_real * x1_real - w_imag * x1_imag;
  78. IMAG(out,ostride,j+product_1) = w_real * x1_imag + w_imag * x1_real;
  79. i++;
  80. j++;
  81. }
  82. j += jump;
  83. }
  84. return 0;
  85. }