36 const string myname =
"test_AdcChannelFFT: ";
38 cout << myname <<
"NDEBUG must be off." <<
endl;
41 string line =
"-----------------------------";
43 cout << myname << line <<
endl;
44 string fclfile =
"test_AdcChannelFFT.fcl";
45 if ( ! useExistingFcl ) {
46 cout << myname <<
"Creating top-level FCL." <<
endl;
47 ofstream
fout(fclfile.c_str());
50 fout <<
" tool_type: AdcChannelFFT" <<
endl;
60 fout <<
" tool_type: AdcChannelFFT" <<
endl;
72 cout << myname <<
"Using existing top-level FCL." <<
endl;
75 cout << myname << line <<
endl;
76 cout << myname <<
"Fetching tool manager." <<
endl;
78 assert ( ptm !=
nullptr );
83 cout << myname << line <<
endl;
84 cout << myname <<
"Fetching tool." <<
endl;
86 assert( pfft !=
nullptr );
88 cout << myname << line <<
endl;
89 cout << myname <<
"Create data." <<
endl;
92 vector<float> sams = { 3.0, 6.0, 16.1, 28.6, 30.2, 27.7, 16.3, 9.6, 4.2, -1.0,
93 -2.3, -4.2, -9.2, -18.6, -21.9, -29.0, -24.3, -14.2, -5.0, -3.0};
94 if ( len > 0 ) sams.resize(len, 0.0);
96 assert( sams.
size() == nsam );
97 cout << myname <<
"Sample length: " << nsam <<
endl;
99 for (
float sam : sams ) samsum +=
sam;
100 cout << myname <<
"Sample mean: " << samsum/nsam <<
endl;
102 Index nmag = (nsam+2)/2;
103 Index npha = (nsam+1)/2;
104 cout << myname <<
" # samples: " << nsam <<
endl;
105 cout << myname <<
"Expected mag size: " << nmag <<
endl;
106 cout << myname <<
"Expected mag size: " << nmag <<
endl;
107 cout << myname <<
"Expected pha size: " << npha <<
endl;
109 cout << myname << line <<
endl;
110 cout << myname <<
"Call tool view." <<
endl;
127 cout << myname << line <<
endl;
128 cout << myname <<
"Check power." <<
endl;
130 for (
float sam : sams ) pwr1 +=
sam*
sam;
134 for (
Index ifrq=0; ifrq<nmag; ++ifrq ) {
137 pwr3 += xre*xre + xim*xim;
139 cout << myname <<
"Tick power: " << pwr1 <<
endl;
140 cout << myname <<
"Freq power: " << pwr2 <<
endl;
141 cout << myname <<
"Frq2 power: " << pwr3 <<
endl;
142 assert( fabs(pwr2 - pwr1) < 1.
e-5*pwr1 );
143 assert( fabs(pwr3 - pwr1) < 1.
e-5*pwr1 );
145 cout << myname << line <<
endl;
146 cout << myname <<
"Call tool update." <<
endl;
147 dm = pfft->update(acd);
149 assert( acd.
dftmags.size() == nmag );
152 cout << myname << line <<
endl;
153 cout << myname <<
"Fetching inverse tool." <<
endl;
155 assert( pffi !=
nullptr );
157 cout << myname << line <<
endl;
158 cout << myname <<
"Call inverse tool." <<
endl;
160 assert( acd.
samples.size() == 0 );
161 assert( acd.
dftmags.size() == nmag );
163 dm = pffi->update(acd);
166 assert( acd.
samples.size() == nsam );
167 for (
Index isam=0; isam<nsam; ++isam ) {
168 cout <<
setw(4) << isam <<
":" <<
setw(10) << fixed << acd.
samples[isam]
169 <<
" ?= " <<
setw(10) << fixed << sams[isam] <<
endl;
170 assert( fabs(acd.
samples[isam] - sams[isam]) < 1.e-4 );
173 cout << myname << line <<
endl;
174 cout << myname <<
"Done." <<
endl;
const FloatVector & getFloatVector(Name name) const
void print(std::ostream *pout) const
void setChannelInfo(ChannelInfoPtr pchi)
AdcSignalVector dftphases
Q_EXPORT QTSManip setw(int w)
int getInt(Name name, int def=0) const
void line(double t, double *p, double &x, double &y, double &z)
bool haveFloatVector(Name name) const
QTextStream & endl(QTextStream &s)