17 template<
typename _InputIterator,
typename _OutputIterator>
18 void ShortCorr(_InputIterator masterbegin, _InputIterator masterend,
19 _InputIterator shortbegin, _InputIterator shortend,
20 _OutputIterator outbegin)
23 if (distance(shortbegin, shortend) > distance(masterbegin, masterend))
27 typename std::iterator_traits<_InputIterator>::value_type>
29 _InputIterator currstart = masterbegin;
30 _OutputIterator currout = outbegin;
31 const int shortsize = distance(shortbegin, shortend);
34 tinvector shortts(shortbegin, shortend);
35 SubMean(shortts.begin(), shortts.end());
37 tinvector shortauto(shortts.begin(), shortts.end());
38 std::transform(shortauto.begin(), shortauto.end(), shortauto.begin(),
39 shortauto.begin(), std::multiplies<double>());
40 const double shortpower = std::accumulate(shortauto.begin(),
42 typename std::iterator_traits<_OutputIterator>::value_type());
44 while (currstart + shortsize < masterend)
46 tinvector currmul(currstart, currstart + shortsize);
48 SubMean(currmul.begin(), currmul.end());
49 tinvector currauto(currmul.begin(), currmul.end());
50 std::transform(currauto.begin(), currauto.end(), currauto.begin(),
51 currauto.begin(), std::multiplies<double>());
52 double currpower = std::accumulate(currauto.begin(),
54 typename std::iterator_traits<_OutputIterator>::value_type());
56 std::transform(currmul.begin(), currmul.end(), shortts.begin(),
57 currmul.begin(), std::multiplies<double>());
58 *currout = std::accumulate(currmul.begin(), currmul.end(),
59 typename std::iterator_traits<_OutputIterator>::value_type());
60 *currout /= sqrt(shortpower * currpower);
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 basic exception class for all errors that arise in gplib.