How do I measure the time lag between two non-periodic data sets?

5 views (last 30 days)
I have two data sets that I wish to compare. These behave like x = t+ 2*sin(t) but one takes longer to complete than the other.
eg.
t = 0:0.1:30;
x1 = t+2*sin(t);
x2 = t-1+2*sin(t-1);
I am unable to use a cross-correlation (xcorr) or cross-covariance (xcov) function to determine the time loss. I have tried plotting the change in t over x but as the functions are not monotonically increasing they overlap, so I cannot simply measure the maximum time difference.
Is there another way that I can measure the maximum time difference between these two data sets?
  2 Comments
Walter Roberson
Walter Roberson on 11 Apr 2014
Edited: Walter Roberson on 11 Apr 2014
Will the lag always be integral? Is there an known upper bound on the lag?
Is it like you have a general form similar to
xn = t - n + 2*sin(t-n)
with xn and t known, and you want to find n ?
Walter Roberson
Walter Roberson on 11 Apr 2014
Is there significant noise in the data?
In the case of x0 = t + 2*sin(t) vs xn = t - n + 2 * sin(t-n), I played around as follows:
I took the difference xn - x0 and taylor'd it with order 11, around t = Pi. I then invoked the traditional sin and cos identity functions and simplified the result. Call that R for the moment.
Now evaluate R at t = 0; the evaluated R reduces to something of the form C1 * sin(n) + C2 * cos(n) + C3 - n, where C1, C2, C3 are constant expressions that fall out of the simplification. This formula, with the three terms that depend relatively simply on n, is now a model for the difference between the first point in each of the two data sets -- a known value. The model depends upon n. Now, plot the model function over n. Notice in the graph that for any one value on the y axis (the difference of the points) can correspond to either 1, 2, or 3 different points on the n axis (the lag.) Thus, by knowing the difference between the two initial points, we can narrow the lag to at most 3 different values.
Now evaluate R at t = 1, run the identities, simplify. The result will be of the same form as for t = 0, but with different constants. Plot this result over values of n, and notice that for it as well, any given difference corresponds to at most 3 different lags.
Now if you plot the two model difference functions on the same graph, you will find that in each case in which there is ambiguity in the lag for the first model (for t = 0), there is only a single possibility for the lag for the second model (for t = 1); and similarity, for each case in which there is ambiguity in the lag for the second model (for t = 1), there is no ambiguity in the first model (for t = 0).
Therefore, in the situation of a dataset xn = t - n + 2*sin(t-n) with unknown n, together with a dataset x0 = t + 2 * sin(t), taking the respective differences of the first two model points is enough to pinpoint the lag, n.
Now it would not surprise me if in your actual functions, the result does not turn out nearly as nicely!

Sign in to comment.

Answers (0)

Categories

Find more on Preprocessing Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!