gsl_fft__hc_unpack.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* fft/hc_unpack.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. int
  20. FUNCTION(gsl_fft_halfcomplex,unpack) (const BASE halfcomplex_coefficient[],
  21. BASE complex_coefficient[],
  22. const size_t stride, const size_t n)
  23. {
  24. size_t i;
  25. if (n == 0)
  26. {
  27. GSL_ERROR ("length n must be positive integer", GSL_EDOM);
  28. }
  29. REAL(complex_coefficient,stride,0) = halfcomplex_coefficient[0];
  30. IMAG(complex_coefficient,stride,0) = 0.0;
  31. for (i = 1; i < n - i; i++)
  32. {
  33. const ATOMIC hc_real = halfcomplex_coefficient[(2 * i - 1) * stride];
  34. const ATOMIC hc_imag = halfcomplex_coefficient[2 * i * stride];
  35. REAL(complex_coefficient,stride,i) = hc_real;
  36. IMAG(complex_coefficient,stride,i) = hc_imag;
  37. REAL(complex_coefficient,stride,n - i) = hc_real;
  38. IMAG(complex_coefficient,stride,n - i) = -hc_imag;
  39. }
  40. if (i == n - i)
  41. {
  42. REAL(complex_coefficient,stride,i) = halfcomplex_coefficient[(n - 1) * stride];
  43. IMAG(complex_coefficient,stride,i) = 0.0;
  44. }
  45. return 0;
  46. }
  47. int
  48. FUNCTION(gsl_fft_halfcomplex,radix2_unpack) (const BASE halfcomplex_coefficient[],
  49. BASE complex_coefficient[],
  50. const size_t stride, const size_t n)
  51. {
  52. size_t i;
  53. if (n == 0)
  54. {
  55. GSL_ERROR ("length n must be positive integer", GSL_EDOM);
  56. }
  57. REAL(complex_coefficient,stride,0) = halfcomplex_coefficient[0];
  58. IMAG(complex_coefficient,stride,0) = 0.0;
  59. for (i = 1; i < n - i; i++)
  60. {
  61. const ATOMIC hc_real = halfcomplex_coefficient[i * stride];
  62. const ATOMIC hc_imag = halfcomplex_coefficient[(n - i) * stride];
  63. REAL(complex_coefficient,stride,i) = hc_real;
  64. IMAG(complex_coefficient,stride,i) = hc_imag;
  65. REAL(complex_coefficient,stride,n - i) = hc_real;
  66. IMAG(complex_coefficient,stride,n - i) = -hc_imag;
  67. }
  68. if (i == n - i)
  69. {
  70. REAL(complex_coefficient,stride,i) = halfcomplex_coefficient[i * stride];
  71. IMAG(complex_coefficient,stride,i) = 0.0;
  72. }
  73. return 0;
  74. }