TS++ library: time series library
correlate.h
Go to the documentation of this file.
1 
35 // include guard
36 #ifndef TF_CORRELATE_H_VERSION
37 
38 #define TF_CORRELATE_H_VERSION \
39  "TF_CORRELATE_H V1.0 "
40 
41 #include<aff/series.h>
42 
43 namespace ts {
44 
74  template<class T>
75  aff::Series<T> correlate(const aff::ConstSeries<T>& a,
76  const aff::ConstSeries<T>& b)
77  {
78  aff::Series<T> retval(b.first()-a.last(),b.last()-a.first());
79  for (long int k=retval.first(); k<=retval.last(); ++k)
80  {
81  retval(k)=T(0);
82  long int lmin=a.first() > (b.first()-k) ? a.first() : (b.first()-k);
83  long int lmax=a.last() < (b.last()-k) ? a.last() : (b.last()-k);
84  for(long int l=lmin; l<=lmax; ++l)
85  {
86  retval(k)+=a(l)*b(l+k);
87  }
88  }
89  return(retval);
90  } // correlate
91 
92 } // namespace ts
93 
94 #endif // TF_CORRELATE_H_VERSION (includeguard)
95 
96 /* ----- END OF correlate.h ----- */
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
aff::Series< T > correlate(const aff::ConstSeries< T > &a, const aff::ConstSeries< T > &b)
Calculate crosscorrelation of two series.
Definition: correlate.h:75