36 const string myname =
"test_FwFFT: ";
38 cout << myname <<
"NDEBUG must be off." <<
endl;
41 string line =
"-----------------------------";
45 cout << myname <<
" Global norm: " << ignorm <<
endl;
46 cout << myname <<
" Term norm: " << itnorm <<
endl;
48 cout << myname << line <<
endl;
49 cout << myname <<
"Create data." <<
endl;
50 vector<float> sams = { 3.0, 6.0, 16.1, 28.6, 30.2, 27.7, 16.3, 9.6, 4.2, -1.0,
51 -2.3, -4.2, -9.2, -18.6, -21.9, -29.0, -24.3, -14.2, -5.0, -3.0};
52 if ( len > 0 ) sams.resize(len, 0.0);
54 assert( sams.
size() == nsam );
55 cout << myname <<
"Sample length: " << nsam <<
endl;
57 for (
float sam : sams ) samsum +=
sam;
58 cout << myname <<
"Sample mean: " << samsum/nsam <<
endl;
59 Index namp = (nsam+2)/2;
60 Index npha = (nsam+1)/2;
61 cout << myname <<
" # samples: " << nsam <<
endl;
62 cout << myname <<
"Expected amp size: " << namp <<
endl;
63 cout << myname <<
"Expected pha size: " << npha <<
endl;
65 cout << myname << line <<
endl;
66 cout << myname <<
"Create empty DFT." <<
endl;
68 assert( dft.size() == 0 );
70 cout << myname << line <<
endl;
71 cout << myname <<
"Transform forward." <<
endl;
74 cout << myname << line <<
endl;
75 cout << myname <<
"Transform forward." <<
endl;
76 assert( xf.fftForward(sams, dft, loglev) == 0 );
77 assert( sams.size() == nsam );
78 cout << myname <<
"DFT size: " << dft.size() <<
endl;
79 assert( dft.size() == nsam );
80 assert( dft.nCompact() == namp );
81 assert( dft.nAmplitude() == namp );
82 assert( dft.nPhase() == npha );
83 cout <<
"Frequency components:" <<
endl;
84 for (
Index ifrq=0; ifrq<namp; ++ifrq ) {
85 cout << myname <<
setw(4) << ifrq <<
": " << dft.amplitude(ifrq);
86 if ( ifrq < npha ) cout <<
" @ " << dft.phase(ifrq);
90 cout << myname << line <<
endl;
91 cout << myname <<
"Check power." <<
endl;
94 float pwr2 = dft.power();
97 for (
Index ifrq=0; ifrq<nsam; ++ifrq ) {
98 float amp = dft.amplitude(ifrq);
99 float xre = dft.real(ifrq);
100 float xim = dft.imag(ifrq);
101 if ( !dft.normalization().isPower() || ifrq < dft.nCompact() ) {
103 pwr4 += xre*xre + xim*xim;
107 if ( dft.normalization().isStandard() ) pfac = 1.0/nsam;
108 if ( dft.normalization().isBin() ) pfac = nsam;
111 cout << myname <<
"Tick power: " << pwr1 <<
endl;
112 cout << myname <<
" DFT power: " << pwr2 <<
endl;
113 cout << myname <<
" Amp power: " << pwr3 <<
endl;
114 cout << myname <<
" ReI power: " << pwr4 <<
endl;
115 assert( fabs(pwr2 - pwr1) < 1.
e-5*pwr1 );
117 cout << myname << line <<
endl;
118 cout << myname <<
"Call inverse." <<
endl;
120 int rstat = xf.fftInverse(dft, sams2, loglev);
122 cout << myname <<
"FFT invert returned " << rstat <<
endl;
126 assert( sams2.size() == nsam );
127 for (
Index isam=0; isam<nsam; ++isam ) {
128 cout <<
setw(4) << isam <<
":" <<
setw(10) << fixed << sams[isam]
129 <<
" ?= " <<
setw(10) << fixed << sams2[isam] <<
endl;
130 assert( fabs(sams2[isam] - sams[isam]) < 1.
e-4 );
133 cout << myname << line <<
endl;
134 cout << myname <<
"Done." <<
endl;
auto norm(Vector const &v)
Return norm of the specified vector.
Q_EXPORT QTSManip setw(int w)
void line(double t, double *p, double &x, double &y, double &z)
Dft::FloatVector FloatVector
QTextStream & endl(QTextStream &s)