11 #include <unsupported/Eigen/FFT>
14 std::complex<T>
RandomCpx() {
return std::complex<T>( (
T)(rand()/(
T)RAND_MAX - .5), (
T)(rand()/(
T)RAND_MAX - .5) ); }
17 using namespace Eigen;
20 template <
typename T>
28 template <
typename VT1,
typename VT2>
29 long double fft_rmse(
const VT1 & fftbuf,
const VT2 & timebuf)
31 long double totalpower=0;
32 long double difpower=0;
33 long double pi =
acos((
long double)-1 );
36 long double phinc = (
long double)(-2.)*
k0* pi / timebuf.size();
46 cerr <<
"rmse:" <<
sqrt(difpower/totalpower) << endl;
47 return sqrt(difpower/totalpower);
50 template <
typename VT1,
typename VT2>
51 long double dif_rmse(
const VT1 buf1,
const VT2 buf2)
53 long double totalpower=0;
54 long double difpower=0;
55 size_t n = (
min)( buf1.size(),buf2.size() );
56 for (
size_t k=0;k<
n;++k) {
58 difpower += (
long double)(
numext::abs2(buf1[k] - buf2[k]));
60 return sqrt(difpower/totalpower);
65 template<
int Container,
typename Scalar>
struct VectorType;
69 typedef vector<Scalar>
type;
77 template <
int Container,
typename T>
86 ScalarVector tbuf(nfft);
87 ComplexVector freqBuf;
88 for (
int k=0;k<nfft;++k)
89 tbuf[k]= (
T)( rand()/(double)RAND_MAX - .5);
93 fft.SetFlag(fft.HalfSpectrum );
94 fft.fwd( freqBuf,tbuf);
95 VERIFY((
size_t)freqBuf.size() == (
size_t)( (nfft>>1)+1) );
98 fft.ClearFlag(fft.HalfSpectrum );
99 fft.fwd( freqBuf,tbuf);
100 VERIFY( (
size_t)freqBuf.size() == (
size_t)nfft);
107 fft.inv( tbuf2 , freqBuf);
113 fft.SetFlag(fft.Unscaled);
115 fft.inv( tbuf3 , freqBuf);
117 for (
int k=0;k<nfft;++k)
118 tbuf3[k] *=
T(1./nfft);
127 fft.ClearFlag(fft.Unscaled);
128 fft.inv( tbuf2 , freqBuf);
132 template <
typename T>
135 test_scalar_generic<StdVectorContainer,T>(nfft);
140 template <
int Container,
typename T>
148 ComplexVector inbuf(nfft);
149 ComplexVector outbuf;
151 for (
int k=0;k<nfft;++k)
152 inbuf[k]=
Complex( (
T)(rand()/(
double)RAND_MAX - .5), (
T)(rand()/(
double)RAND_MAX - .5) );
153 fft.fwd( outbuf , inbuf);
156 fft.inv( buf3 , outbuf);
162 fft.SetFlag(fft.Unscaled);
163 fft.inv( buf4 , outbuf);
164 for (
int k=0;k<nfft;++k)
165 buf4[k] *=
T(1./nfft);
169 fft.ClearFlag(fft.Unscaled);
170 fft.inv( buf3 , outbuf);
174 template <
typename T>
177 test_complex_generic<StdVectorContainer,T>(nfft);
178 test_complex_generic<EigenVectorContainer,T>(nfft);
219 fft.SetFlag(fft.HalfSpectrum );
247 #ifdef EIGEN_HAS_FFTWL