gsl_fft__bitreverse.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* fft/bitreverse.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. #include "gsl__config.h"
  20. #include "gsl_fft.h"
  21. #include "gsl_fft__complex_internal.h"
  22. #include "gsl_fft__bitreverse.h"
  23. static int
  24. FUNCTION(fft_complex,bitreverse_order) (BASE data[],
  25. const size_t stride,
  26. const size_t n,
  27. size_t logn)
  28. {
  29. /* This is the Goldrader bit-reversal algorithm */
  30. size_t i;
  31. size_t j = 0;
  32. logn = 0 ; /* not needed for this algorithm */
  33. for (i = 0; i < n - 1; i++)
  34. {
  35. size_t k = n / 2 ;
  36. if (i < j)
  37. {
  38. const BASE tmp_real = REAL(data,stride,i);
  39. const BASE tmp_imag = IMAG(data,stride,i);
  40. REAL(data,stride,i) = REAL(data,stride,j);
  41. IMAG(data,stride,i) = IMAG(data,stride,j);
  42. REAL(data,stride,j) = tmp_real;
  43. IMAG(data,stride,j) = tmp_imag;
  44. }
  45. while (k <= j)
  46. {
  47. j = j - k ;
  48. k = k / 2 ;
  49. }
  50. j += k ;
  51. }
  52. return 0;
  53. }
  54. static int
  55. FUNCTION(fft_real,bitreverse_order) (BASE data[],
  56. const size_t stride,
  57. const size_t n,
  58. size_t logn)
  59. {
  60. /* This is the Goldrader bit-reversal algorithm */
  61. size_t i;
  62. size_t j = 0;
  63. logn = 0 ; /* not needed for this algorithm */
  64. for (i = 0; i < n - 1; i++)
  65. {
  66. size_t k = n / 2 ;
  67. if (i < j)
  68. {
  69. const BASE tmp = VECTOR(data,stride,i);
  70. VECTOR(data,stride,i) = VECTOR(data,stride,j);
  71. VECTOR(data,stride,j) = tmp;
  72. }
  73. while (k <= j)
  74. {
  75. j = j - k ;
  76. k = k / 2 ;
  77. }
  78. j += k ;
  79. }
  80. return 0;
  81. }