1. /* sfft.h by K.Tsuru */
  2. /***************************************************
  3. Provides fast Fourie transform(FFT).
  4. Aug 24, 2000
  5. After version 2.10 Ooura's FFT program is used and
  6. "fftMaxArraySize" is enlarged.
  7. System fftType table USES_SIN_TABLE_FFT | USES_LONG_DBL_FFT | fftSqrt | sin, cos
  8. 32 bits double O 1 | 0 | sqrt | X
  9. X 0 | 0 | sqrt | sin, cos
  10. 64 bits double O 1 | 0 | sqrt | X
  11. X 0 | 0 | sqrt | sin, cos
  12. long double O 1 | 1 | sqrtl | X
  13. X 0 | 1 | sqrtl | sinl, cosl
  14. ---------------------------------------
  15. long double ldpi = 3.1415926535 89793 23846; // give 21 digits
  16. cout << ldpi << endl; // 3.1415926535 89793 11600 //16 digits agree only. The same as double.
  17. Then "long double" cannot be used FFT multiplication GCC at the present time.
  18. ****************************************************/
  19. #ifndef S_FFT_H
  20. #define S_FFT_H
  21. #ifndef DEF_CONST_H
  22. #include "defconst.h" // for M_PI_4
  23. #endif
  24. #ifndef SN_CONST_H
  25. #include "snconst.h"
  26. #endif // SN_CONST_H
  27. //type of real number using in FFT
  28. //If you use long double or quadruple precision, change here.
  29. //specify the function of sqrt(), modf(), etc.
  30. //Speed depends on the performance of FPU.
  31. #include <math.h>
  32. #define fftM_PI_4 M_PI_4 // =pi/4 Has 20 digits enough for long double
  33. #define USES_SIN_TABLE_FFT 0
  34. #define USES_LONG_DBL_FFT 0
  35. #if USES_LONG_DBL_FFT // =uses long double============================
  36. const bool Uses_long_double_FFT = true;
  37. const bool Uses_double_FFT = false;
  38. typedef long double fftType;
  39. #define fftSqrt sqrtl
  40. fftType fftModfl(const fftType x, fftType *ip); // modfl() my version // for FFTVerify()
  41. #define fftFmod fmodl //
  42. #define fftFabs fabsl //
  43. #define fftLdexp ldexpl //
  44. #define fftSin sinl
  45. #define fftCos cosl
  46. #define fftType_MANT_DIG LDBL_MANT_DIG // = 64
  47. const int FFT_MAX_SIZE_BITS = 27; // bits of maximum size of FFT work area, fftMaxSize=2^27 = 134217728.
  48. #else // end of USES_LONG_DBL_FFT
  49. // below === uses double =====================
  50. const bool Uses_long_double_FFT = false;
  51. const bool Uses_double_FFT = true;
  52. typedef double fftType;
  53. #define fftSqrt sqrt
  54. #define fftModf modf
  55. #define fftFmod fmod //
  56. #define fftFabs fabs
  57. #define fftLdexp ldexp //
  58. #define fftSin sin
  59. #define fftCos cos
  60. #define fftType_MANT_DIG DBL_MANT_DIG // = 53
  61. const int FFT_MAX_SIZE_BITS = 23; // 20 --> 22 --> 23 --> 24(NG); // bits of maximum size of FFT work area fftMaxSize=2^23 = 8388608.
  62. #endif // end of === uses double =====================
  63. const uint fftMaxArraySize = 1u << FFT_MAX_SIZE_BITS;
  64. #if USES_SIN_TABLE_FFT
  65. const bool UsesFFTSineTable = true;
  66. long FFTSineTableSize();
  67. long FFTSineTableUsedMemory();
  68. int MakeSinTable(int maxsizebit); // give FFT_MAX_SIZE_BITS
  69. fftType fftSinR(long j, long w); // = sin (pi/4)*(j/w)
  70. fftType fftCosR(long j, long w); // = cos (pi/4)*(j/w)
  71. #else
  72. const bool UsesFFTSineTable = false;
  73. fftType fftSinR(long n, long d);
  74. fftType fftCosR(long n, long d);
  75. #endif // USES_SIN_TABLE_FFT
  76. // return the information of work area on static memory.
  77. uint FFTSize(); // figure of N
  78. uint FFTsinSize(); // table size of sine.
  79. uint FFTWorkSize(); // size of work area for sine/cosine table and data
  80. // To get memory size please multiply "sizeof(fftType)"
  81. // which will be order of 10 MB.
  82. /*************************** To use Ooura's rdft(). ***************************/
  83. struct FFTWorkArea{
  84. int size, ipsz;
  85. int* ip; // for bit reverse table
  86. fftType* w; // for sine/cosine table
  87. //constructor
  88. FFTWorkArea():size(0),ipsz(0),ip(NULL),w(NULL){ }
  89. void Allocate(int N); // 217
  90. void MemFree(); // 217
  91. ~FFTWorkArea(){}
  92. };
  93. void rdft(int n, int isgn, fftType *a, int *ip, fftType *w);
  94. /*******************************************************************************/
  95. #endif // S_FFT_H

sfft.h : last modifiled at 2017/10/18 15:06:20(4,285 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/23 10:27:41 (Mon Oct 23 10:27:41 2017).