FFT.cpp File Reference

Go to the source code of this file.

Functions

void demo_all_types (int nfft)
 
template<typename T_time , typename T_freq >
void fwd_inv (size_t nfft)
 
template<typename T >
T mag2 (const std::vector< std::complex< T > > &vec)
 
template<typename T >
T mag2 (const std::vector< T > &vec)
 
template<typename T >
T mag2 (std::complex< T > a)
 
template<typename T >
T mag2 (T a)
 
int main ()
 
template<typename T >
vector< Toperator- (const vector< T > &a, const vector< T > &b)
 
template<typename T >
void RandomFill (std::vector< std::complex< T > > &vec)
 
template<typename T >
void RandomFill (std::vector< T > &vec)
 
template<typename T_scalar >
void two_demos (int nfft)
 

Function Documentation

◆ demo_all_types()

void demo_all_types ( int  nfft)

Definition at line 101 of file FFT.cpp.

102 {
103  cout << "nfft=" << nfft << endl;
104  cout << " float" << endl;
105  two_demos<float>(nfft);
106  cout << " double" << endl;
107  two_demos<double>(nfft);
108  cout << " long double" << endl;
109  two_demos<long double>(nfft);
110 }

◆ fwd_inv()

template<typename T_time , typename T_freq >
void fwd_inv ( size_t  nfft)

Definition at line 75 of file FFT.cpp.

76 {
77  typedef typename NumTraits<T_freq>::Real Scalar;
78  vector<T_time> timebuf(nfft);
79  RandomFill(timebuf);
80 
81  vector<T_freq> freqbuf;
82  static FFT<Scalar> fft;
83  fft.fwd(freqbuf,timebuf);
84 
85  vector<T_time> timebuf2;
86  fft.inv(timebuf2,freqbuf);
87 
88  T_time rmse = mag2(timebuf - timebuf2) / mag2(timebuf);
89  cout << "roundtrip rmse: " << rmse << endl;
90 }
void RandomFill(std::vector< T > &vec)
Definition: FFT.cpp:61
T mag2(T a)
Definition: FFT.cpp:23
Definition: FFT:177
void fwd(Complex *dst, const Scalar *src, Index nfft)
Definition: FFT:205
fft_inv_proxy< MatrixBase< InputDerived >, FFT< T_Scalar, T_Impl > > inv(const MatrixBase< InputDerived > &src, Index nfft=-1)
Definition: FFT:284

◆ mag2() [1/4]

template<typename T >
T mag2 ( const std::vector< std::complex< T > > &  vec)

Definition at line 43 of file FFT.cpp.

44 {
45  T out=0;
46  for (size_t k=0;k<vec.size();++k)
47  out += mag2(vec[k]);
48  return out;
49 }

◆ mag2() [2/4]

template<typename T >
T mag2 ( const std::vector< T > &  vec)

Definition at line 34 of file FFT.cpp.

35 {
36  T out=0;
37  for (size_t k=0;k<vec.size();++k)
38  out += mag2(vec[k]);
39  return out;
40 }

◆ mag2() [3/4]

template<typename T >
T mag2 ( std::complex< T a)

Definition at line 28 of file FFT.cpp.

29 {
30  return norm(a);
31 }

◆ mag2() [4/4]

template<typename T >
T mag2 ( T  a)

Definition at line 23 of file FFT.cpp.

24 {
25  return a*a;
26 }
ArrayXXi a

◆ main()

int main ( )

Definition at line 112 of file FFT.cpp.

113 {
114  demo_all_types( 2*3*4*5*7 );
115  demo_all_types( 2*9*16*25 );
116  demo_all_types( 1024 );
117  return 0;
118 }
void demo_all_types(int nfft)
Definition: FFT.cpp:101

◆ operator-()

template<typename T >
vector<T> operator- ( const vector< T > &  a,
const vector< T > &  b 
)

Definition at line 52 of file FFT.cpp.

53 {
54  vector<T> c(a);
55  for (size_t k=0;k<b.size();++k)
56  c[k] -= b[k];
57  return c;
58 }
Array33i c

◆ RandomFill() [1/2]

template<typename T >
void RandomFill ( std::vector< std::complex< T > > &  vec)

Definition at line 68 of file FFT.cpp.

69 {
70  for (size_t k=0;k<vec.size();++k)
71  vec[k] = std::complex<T> ( T( rand() )/T(RAND_MAX) - T(.5), T( rand() )/T(RAND_MAX) - T(.5));
72 }

◆ RandomFill() [2/2]

template<typename T >
void RandomFill ( std::vector< T > &  vec)

Definition at line 61 of file FFT.cpp.

62 {
63  for (size_t k=0;k<vec.size();++k)
64  vec[k] = T( rand() )/T(RAND_MAX) - T(.5);
65 }

◆ two_demos()

template<typename T_scalar >
void two_demos ( int  nfft)

Definition at line 93 of file FFT.cpp.

94 {
95  cout << " scalar ";
96  fwd_inv<T_scalar,std::complex<T_scalar> >(nfft);
97  cout << " complex ";
98  fwd_inv<std::complex<T_scalar>,std::complex<T_scalar> >(nfft);
99 }