# Compare Multiple Time Series in Matlab

I have a multi-variate time series which represent the heading (-2*PI - +2*PI) of a set of virtual agents over time.

What I would like to have is some form of correlation function which describes the relationship among the variation of heading of agents over time, so that given another multi-variate time series of another set of agents, I can state whether their motion pattern was similar to the 1st set or not.

I'm working with Matlab and read about cross-correlation, cross-variance, but with my limited knowledge in statistics I'm still unable to determine how I could come up with somekind of a function which maps to the given graph. I would appreciate any guidance to direct me in the correct path.

Edit: Both sets of agents that I talk about here are equal in number, and all environmental conditions are the same, except that the two sets have two different motion patterns.

• Can you be a bit more specific? Do you expect the second set to have the same number of agents as your observed set? Do you have a way to order your agents e.g. based on their starting locations? Oct 26, 2017 at 0:57
• Yes same number of agents, same environment, just a different motion pattern. I cannot identify which agent is which in the next set, if that's what you mean by ordering agents. They all start from the same location and may head towards the same or different directions. It changes for each set.
– zim
Oct 26, 2017 at 1:03

Suppose you have $N$ agents. You can estimate the covariance between the headings of each pair of agents to get an $N \times N$ covariance matrix $\Sigma$. This matrix essentially captures the joint structure in the pattern of headings of the different agents. This can be computed using the 'cov' function in Matlab. If you can track the identity of the agents across datasets, you can order the agents in the same way before computing the covariance and then directly compare the covariance matrices of the two datasets to see if there is a high degree of overlap.
However, since you say that you cannot track the identity of the agents across datasets, you cannot directly compare the covariances. Instead, you could perform an eigen decomposition of $\Sigma$ to get the set of eigenvalues $\it{\lambda_1, ... \lambda_N}$ and eigenvectors $V_1, ... V_N$ of your covariance matrix. Each eigenvector corresponds to a particular pattern of co-fluctuation (a particular mode) in the movements of the different agents and the magnitude of the corresponding eigenvalue tells you how dominant that mode is (the energy of that mode). You can perform eigen decomposition using the Matlab 'eig' function.