1 #ifndef CSTACKEDSPECTRUM_H
2 #define CSTACKEDSPECTRUM_H
8 #include <boost/bind.hpp>
22 template<
typename InputIterator,
typename OutputIterator,
23 typename WindowFunctype>
25 OutputIterator freqbegin,
const size_t seglength, WindowFunctype WFunc)
29 typename std::iterator_traits<OutputIterator>::value_type>
32 typename std::iterator_traits<InputIterator>::value_type> tinvector;
33 const size_t insize = distance(tsbegin, tsend);
34 if (insize < seglength)
36 "Time Series shorter than requested segment length");
37 const unsigned int nsegments = insize / seglength;
39 std::fill_n(freqbegin, seglength / 2 + 1,
40 typename std::iterator_traits<OutputIterator>::value_type());
41 toutvector segspec(seglength / 2 + 1);
43 InputIterator currstart = tsbegin;
44 InputIterator currend = tsbegin;
45 advance(currend, seglength);
46 for (
unsigned int i = 0; i < nsegments; ++i)
48 tinvector currseg(currstart, currend);
50 SubMean(currseg.begin(), currseg.end());
52 for (
typename tinvector::iterator it = currseg.begin(); it
53 != currseg.end(); ++it)
57 static_cast<double> (distance(currseg.begin(), it))
63 segspec.begin(), segspec.end());
65 std::transform(segspec.begin(), segspec.end(), freqbegin,
66 freqbegin, std::plus<
typename std::iterator_traits<
67 OutputIterator>::value_type>());
68 advance(currstart, seglength);
69 advance(currend, seglength);
74 #endif // CSTACKEDSPECTRUM_H
void SubMean(InputIterator begin, InputIterator end, typename std::iterator_traits< InputIterator >::value_type mean)
Substract the mean from each element in the container, mean is passed as a parameter.
The class CTsSpectrum is used to calculate spectra from (real) time series data.
The basic exception class for all errors that arise in gplib.