28 using namespace pwiz::util;
29 using namespace pwiz::frequency;
30 using namespace pwiz::data;
31 using namespace pwiz::data::peakdata;
39 if (
os_) *
os_ <<
"**************************************************\ntest()\n";
43 for (
int i=-5; i<=5; i++)
51 vector<Peak> peaks(2);
52 peaks[0].attributes[Peak::Attribute_Frequency] = .1;
53 peaks[1].attributes[Peak::Attribute_Frequency] = 7.4;
57 vector<Peak> estimatedPeaks;
61 auto_ptr<FrequencyEstimatorSimple>
64 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
65 estimatedPeaks.push_back(fe->
estimate(fd, *it));
71 *
os_ << setprecision(10);
73 *
os_ <<
"Initial peaks:\n";
74 copy(peaks.begin(), peaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
77 *os_ <<
"Parabola estimated peaks:\n";
78 copy(estimatedPeaks.begin(), estimatedPeaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
84 const Peak& pi0 = estimatedPeaks[0];
85 unit_assert(pi0.getAttribute(Peak::Attribute_Frequency) == 0);
88 const Peak& pi1 = estimatedPeaks[1];
95 estimatedPeaks.clear();
96 fe = FrequencyEstimatorSimple::create(FrequencyEstimatorSimple::Lorentzian);
98 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
99 estimatedPeaks.push_back(fe->
estimate(fd, *it));
105 *
os_ <<
"Lorentzian estimated peaks:\n";
106 copy(estimatedPeaks.begin(), estimatedPeaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
112 const Peak& pil0 = estimatedPeaks[0];
116 const Peak& pil1 = estimatedPeaks[1];
124 if (
os_) *
os_ <<
"**************************************************\ntestData()\n";
127 fd.
data().push_back(
FrequencyDatum(28558.59375, complex<double>(25243.032972361, -2820.6360692452)));
128 fd.
data().push_back(
FrequencyDatum(28559.895833333, complex<double>(39978.141686921, 291.1363106641)));
129 fd.
data().push_back(
FrequencyDatum(28561.197916667, complex<double>(189200.35822792, -2636.9254689346)));
130 fd.
data().push_back(
FrequencyDatum(28562.5, complex<double>(-62230.480432624, -2546.1033855971)));
131 fd.
data().push_back(
FrequencyDatum(28563.802083333, complex<double>(-32263.08735743, -2769.7946573836)));
133 vector<Peak> peaks(1);
134 peaks[0].attributes[Peak::Attribute_Frequency] = 28561.2;
138 *
os_ <<
"Initial peaks:\n";
139 copy(peaks.begin(), peaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
143 vector<Peak> estimatedPeaks;
145 auto_ptr<FrequencyEstimatorSimple>
148 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
149 estimatedPeaks.push_back(fe->
estimate(fd, *it));
153 *
os_ << setprecision(10);
155 *
os_ <<
"Parabola estimated peaks:\n";
156 copy(estimatedPeaks.begin(), estimatedPeaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
161 unit_assert_equal(estimatedPeaks[0].getAttribute(Peak::Attribute_Frequency), 28561.25049, 1
e-5);
168 complex<double> intensity;
174 {10981.7708333, complex<double>(1494.77333435,-827.565405375)},
175 {10982.421875, complex<double>(-522.951336943,-2933.77290646)},
176 {10983.0729167, complex<double>(1026.58070488,-2790.70883417)},
177 {10983.7239583, complex<double>(1002.03072708,-1020.67745139)},
178 {10984.375, complex<double>(-567.573503924,-2220.62261993)},
179 {10985.0260417, complex<double>(-6322.94426498,-3013.78424791)},
180 {10985.6770833, complex<double>(430.465272274,502.150355144)},
181 {10986.328125, complex<double>(2578.81032322,795.379729653)},
182 {10986.9791667, complex<double>(2864.69277204,-470.140696311)},
183 {10987.6302083, complex<double>(2788.00641762,4788.24971282)},
184 {10988.28125, complex<double>(-366.077646703,-6084.91428783)},
185 {10988.9322917, complex<double>(1220.81029308,-3297.88016503)},
186 {10989.5833333, complex<double>(2268.72858986,-646.091997391)},
187 {10990.234375, complex<double>(4681.74708664,2313.31976782)},
188 {10990.8854167, complex<double>(-955.7765424,5903.76925847)},
189 {10991.5364583, complex<double>(3957.71316667,-225.389114599)},
190 {10992.1875, complex<double>(-2159.60123121,3597.12682291)},
191 {10992.8385417, complex<double>(653.493128029,2229.46593497)},
192 {10993.4895833, complex<double>(6037.67518189,-4347.22639235)},
193 {10994.140625, complex<double>(-167.455004321,1848.75455373)}
202 if (
os_) *
os_ <<
"**************************************************\ntestData2_LocalMax()\n";
209 vector<Peak> peaks(1);
210 peaks[0].attributes[Peak::Attribute_Frequency] = 10983.74;
214 *
os_ <<
"Initial peaks:\n";
215 copy(peaks.begin(), peaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
219 vector<Peak> estimatedPeaks;
221 auto_ptr<FrequencyEstimatorSimple>
224 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
225 estimatedPeaks.push_back(fe->
estimate(fd, *it));
229 *
os_ << setprecision(10);
231 *
os_ <<
"Local max peaks:\n";
232 copy(estimatedPeaks.begin(), estimatedPeaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
237 unit_assert_equal(estimatedPeaks[0].getAttribute(Peak::Attribute_Frequency), 10985.02604, 1
e-5);
243 if (
os_) *
os_ <<
"**************************************************\ntestData2()\n";
250 vector<Peak> peaks(1);
251 peaks[0].attributes[Peak::Attribute_Frequency] = 10987.6;
255 *
os_ <<
"Initial peaks:\n";
256 copy(peaks.begin(), peaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
260 vector<Peak> estimatedPeaks;
262 auto_ptr<FrequencyEstimatorSimple>
265 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
266 estimatedPeaks.push_back(fe->
estimate(fd, *it));
270 *
os_ << setprecision(10);
272 *
os_ <<
"Parabola peaks:\n";
273 copy(estimatedPeaks.begin(), estimatedPeaks.end(), ostream_iterator<Peak>(*
os_,
"\n"));
278 unit_assert_equal(estimatedPeaks[0].getAttribute(Peak::Attribute_Frequency), 10988.07103, 1
e-5);
282 int main(
int argc,
char* argv[])
288 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
289 if (
os_) *
os_ <<
"FrequencyEstimatorSimpleTest\n";