fft.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef fftH
15 #define fftH
16 //---------------------------------------------------------------------------
17 #include "support.h"
18 
19 #include <vector>
20 #include <complex>
21 
22 #include <fftw3.h>
23 
24 //! Wrapper class for fast Fourier transformation by FFTW.
25 class DECLSPEC_KAME FFTBase {
26 public:
27  FFTBase(int length);
28  virtual ~FFTBase();
29  //! Expand to appropriate length for better O(n log n) computation.
30  static int fitLength(int length);
31  int length() const {return m_fftlen;}
32 
33  //for Window Func.
34  typedef double (*twindowfunc)(double x);
35  static double windowFuncRect(double x);
36  static double windowFuncTri(double x);
37  static double windowFuncHanning(double x);
38  static double windowFuncHamming(double x);
39  static double windowFuncFlatTop(double x);
40  static double windowFuncBlackman(double x);
41  static double windowFuncBlackmanHarris(double x);
42  static double windowFuncKaiser(double x, double alpha);
43  static double windowFuncKaiser1(double x);
44  static double windowFuncKaiser2(double x);
45  static double windowFuncKaiser3(double x);
46  static double windowFuncFlatTopLong(double x);
47  static double windowFuncFlatTopLongLong(double x);
48  static double windowFuncHalfSin(double x);
49 protected:
50  int m_fftlen;
51  shared_ptr<fftw_plan> m_fftplan;
52 };
53 
54 //! Wrapper class for FFTW.
55 class DECLSPEC_KAME FFT : public FFTBase {
56 public:
57  //! Create FFT plan.
58  //! \param sign -1:FFT, 1:IFFT.
59  //! \param length FFT length.
60  FFT(int sign, int length);
61  virtual ~FFT();
62 
63  void exec(const std::vector<std::complex<double> >& wavein,
64  std::vector<std::complex<double> >& waveout);
65 private:
66  fftw_complex *m_pBufin, *m_pBufout;
67 };
68 
69 //! Read Data FFT(DFT).
70 class DECLSPEC_KAME RFFT : public FFTBase {
71 public:
72  //! Create real data FFT plan.
73  //! \param length FFT length.
74  RFFT(int length);
75  virtual ~RFFT();
76 
77  void exec(const std::vector<double>& wavein,
78  std::vector<std::complex<double> >& waveout);
79 private:
80  double *m_pBufin;
81  fftw_complex *m_pBufout;
82 };
83 
84 //! Read Data IFFT(IDFT).
85 class DECLSPEC_KAME RIFFT : public FFTBase {
86 public:
87  //! Create real data IFFT plan.
88  //! \param length FFT length.
89  RIFFT(int length);
90  virtual ~RIFFT();
91 
92  void exec(const std::vector<std::complex<double> >& wavein,
93  std::vector<double>& waveout);
94 private:
95  double *m_pBufout;
96  fftw_complex *m_pBufin;
97 };
98 #endif

Generated for KAME4 by  doxygen 1.8.3