TS++ library: time series library

◆ convolve()

template<class T >
aff::Series<T> ts::convolve ( const aff::ConstSeries< T > &  a,
const aff::ConstSeries< T > &  b 
)

Calculate convolution of two series.

The function evaluates

\[ c_k = \sum\limits_l a_l b_{k-l}, \]

where the index ranges of the input series are $ a_l: l \in [F_a,L_a] $ and $ b_l: l \in [F_b,L_b]. $ From the second factor we conclude $ F_b +l \leq k \leq L_b + l $ and thus the index range of $ c_l $ is

\[ F_b + F_a \leq k \leq L_b + L_a. \]

For a given $ k $ the range of summation index $ l $ is defined by the two conditions

\[ k- L_b \leq l \leq k- F_b \]

and

\[ F_a \leq k \leq L_a. \]

Note
This function is designed to be used as a discrete approximation to the convolution integral, if convolved series are sampled versions of functions. This has two consequences:
  1. The result should be appropriately scaled with the sampling interval. The sampling interval is not available to this function. The scaling therefore has to take place in the calling program.
  2. The time series are understood to have infinite length, while all samples outside the provided index range implicitely equal zero. The convolution result then necessarily equals zero for index values $k < F_b + F_a$ and $k > L_b + L_a$. The result $c_k$ will be output for $ k \in [F_a+F_b,L_a+L_b] $ with $(L_a-F_a)+(L_b-F_b)+1$ samples, thus being longer than either one of the input series. If the convolution filter response is not given completely, but just as a cut-out of the filter response function, the convolution potentially produces a step-response at the end of the filter sequence. This exactly is the behaviour of the convolution integral, if only a cut-out of the originally infinite filter impulse response function is used. If this is missed, the user might be surprised by an unexpected coda in the result of this function. Consider to trim the output sequence to a reasonable sample window to represent a proper cut-out of the expected result.
Parameters
a$ a_l $
b$ b_l $
Returns
c $ c_l $

Definition at line 103 of file convolve.h.

Referenced by main().

105  {
106  aff::Series<T> retval(a.first()+b.first(),b.last()+a.last());
107  for (long int k=retval.first(); k<=retval.last(); ++k)
108  {
109  retval(k)=T(0);
110  long int lmin=a.first() > (k-b.last()) ? a.first() : (k-b.last());
111  long int lmax=a.last() < (k-b.first()) ? a.last() : (k-b.first());
112  for(long int l=lmin; l<=lmax; ++l)
113  {
114  retval(k)+=a(l)*b(k-l);
115  }
116  }
117  return(retval);
118  } // convolve
Here is the caller graph for this function: