MATLAB: Sync data with two sync points

syncronization

Hi, I have two signal recorded by two different devices (with different clock). In addition, this signals can have two different "time" length. Anyway, I have two data (in the middle of the signal) that can be used to sync them (interpolating the smaller one).
As example, you can consider the data generated by this code:
a = [(1:1000)' (zeros(1,1000))'];
b = [(1:3500)' (zeros(1,3500))'];
a(500,2) = 1; %Starting sync point

a(750,2) = 2; %Ending sync point

b(640,2) = 1; %Starting sync point
b(1020,2) = 2; %Ending sync point
Where the value 1 defines the "first" sync point, and 2 defines the "second" sync point.
There is a Matlab method able to resync these data?
Thanks

Best Answer

At first determine the factor between the time steps:
a1 = find(a(:, 2) == 1);
a2 = find(a(:, 2) == 2);
b1 = find(b(:, 2) == 1);
b2 = find(b(:, 2) == 2);
aInt = a2 - a1;
bInt = b2 - b1;
abFactor = bInt / aInt;
Now you can scale the times:
aTime = (0:size(a, 1) - 1) * abFactor;
bTime = 0:size(b, 1) - 1;
Now you can calculate initial and final time frame of a related to b. You see that this is simple arithmetics, so I leave this up to you.
Related Question