7 #include <boost/bind.hpp>
27 bool ExistsPlanForward;
29 bool ExistsPlanReverse;
35 fftw_complex *freqdomain;
41 void Prepare_Calculation(
const int size);
43 void Finish_Calculation(
const int size);
45 void AssignMem(
const int size);
53 explicit TsSpectrum(
bool WantMultiCalc =
false);
59 template<
typename _InputIterator,
typename _OutputIterator>
60 void CalcSpectrum(_InputIterator tsbegin, _InputIterator tsend,
61 _OutputIterator freqbegin, _OutputIterator freqend);
66 template<
typename _InputIterator,
typename _OutputIterator>
67 void CalcTimeSeries(_InputIterator freqbegin, _InputIterator freqend,
68 _OutputIterator tsbegin, _OutputIterator tsend);
79 template<
typename _InputIterator,
typename _OutputIterator>
81 _OutputIterator freqbegin, _OutputIterator freqend)
83 const int size = distance(tsbegin, tsend);
86 if (distance(freqbegin, freqend) != size / 2 + 1)
88 "Time Series and Spectrum have incompatible size !");
89 Prepare_Calculation(size);
90 copy(tsbegin, tsend, timedomain);
91 fftw_execute(p_forward);
92 for (
int i = 0; i < size / 2 + 1; ++i, ++freqbegin)
94 *freqbegin = freqdomain[i][0] + I * freqdomain[i][1];
95 Finish_Calculation(size);
105 template<
typename _InputIterator,
typename _OutputIterator>
107 _InputIterator freqend, _OutputIterator tsbegin, _OutputIterator tsend)
109 if (freqbegin > freqend || tsbegin > tsend)
110 throw FatalException(
"Negative size of input in CalcTimeSeries !");
111 const int size = distance(tsbegin, tsend);
112 if (distance(freqbegin, freqend) != size / 2 + 1)
114 "Time Series and Spectrum have incompatible size !");
115 Prepare_Calculation(size);
116 for (
int i = 0; freqbegin != freqend; ++freqbegin, ++i)
118 freqdomain[i][0] = (*freqbegin).real();
119 freqdomain[i][1] = (*freqbegin).imag();
121 fftw_execute(p_reverse);
122 double factor = 1. / double(size);
124 std::transform(timedomain, timedomain + size, tsbegin, boost::bind<
125 double>(std::multiplies<double>(), factor, _1));
126 Finish_Calculation(size);
130 #endif // CTSSPECTRUM_H
The class CTsSpectrum is used to calculate spectra from (real) time series data.
TsSpectrum(bool WantMultiCalc=false)
The constructor is explicit to prohibit conversion from bool.
The basic exception class for all errors that arise in gplib.