NUMfft_d.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* NUMfft_d.c
  2. *
  3. * Copyright (C) 1997-2011 David Weenink, Paul Boersma 2017
  4. *
  5. * This code 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 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code 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 work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* djmw 20020813 GPL header
  19. djmw 20040511 Added n>1 test for compatibility with old behaviour.
  20. djmw 20110308 struct renaming
  21. */
  22. #include "NUM2.h"
  23. #include "melder.h"
  24. #define FFT_DATA_TYPE double
  25. #include "NUMfft_core.h"
  26. void NUMforwardRealFastFourierTransform (VEC data) {
  27. autoNUMfft_Table table;
  28. NUMfft_Table_init (& table, data.size);
  29. NUMfft_forward (& table, data);
  30. if (data.size > 1) {
  31. // To be compatible with old behaviour
  32. double tmp = data [data.size];
  33. for (integer i = data.size; i > 2; i--) {
  34. data [i] = data [i - 1];
  35. }
  36. data [2] = tmp;
  37. }
  38. }
  39. void NUMreverseRealFastFourierTransform (VEC data) {
  40. autoNUMfft_Table table;
  41. if (data.size > 1) {
  42. // To be compatible with old behaviour
  43. double tmp = data [2];
  44. for (integer i = 2; i < data.size; i++) {
  45. data [i] = data [i + 1];
  46. }
  47. data [data.size] = tmp;
  48. }
  49. NUMfft_Table_init (& table, data.size);
  50. NUMfft_backward (& table, data);
  51. }
  52. void NUMfft_forward (NUMfft_Table me, VEC data) {
  53. if (my n == 1) {
  54. return;
  55. }
  56. Melder_assert (my n == data.size);
  57. drftf1 (my n, data.begin(), my trigcache.begin(), my trigcache.begin() + my n, my splitcache.begin());
  58. }
  59. void NUMfft_backward (NUMfft_Table me, VEC data) {
  60. if (my n == 1) {
  61. return;
  62. }
  63. Melder_assert (my n == data.size);
  64. drftb1 (my n, data.begin(), my trigcache.begin(), my trigcache.begin() + my n, my splitcache.begin());
  65. }
  66. void NUMfft_Table_init (NUMfft_Table me, integer n) {
  67. my n = n;
  68. my trigcache = VECzero (3 * n);
  69. my splitcache = INTVECzero (32);
  70. NUMrffti (n, my trigcache.begin(), my splitcache.begin());
  71. }
  72. void NUMrealft (VEC data, int isign) {
  73. isign == 1 ? NUMforwardRealFastFourierTransform (data) :
  74. NUMreverseRealFastFourierTransform (data);
  75. }
  76. /* End of file NUMfft.c */