Align two arrays by time column

9 views (last 30 days)
Tom
Tom on 7 Mar 2011
Does anyone know of a MatLab utility to facilitate alignment of two datasets acquired on two devices whose clocks are slightly off? .. we currently resample each and cross-correlate one column from each that contains similar signal (for example the EKG signal) and then shift one of teh two sets .... this is a pain do do manually and i am hoping someone has written a GUI utility to facilitate this ... before we write our own!
  2 Comments
Oleg Komarov
Oleg Komarov on 8 Mar 2011
can you post a brief example of two series and the desired output?
Philippe
Philippe on 25 Jul 2011
Table1 (2s sampling rate with missing points):
0 0 14 30,4
2 1,4 14 30,6
4 2,8 14 30,7
6 4,2 14 30,8
8 4,48 14 31
10 7 14 31
12 10 14 31
14 9,8 14 31,1
16 10,4 13 31,3
18 7,56 14 31,4
20 14 14 31,5
22 15,4 14 31,4
24 15,6 13 31,4
26 14,56 14 31,5
28 18,2 13 31,5
30 15,6 13 31,5
32 16,64 13 31,5
34 22,1 13 31,5
36 23,4 13 31,5
38 24,7 13 31,5
40 20,8 13 31,5
42 16,38 13 31,5
44 22,88 13 31,5
46 22,08 12 31,5
48 28,8 12 31,5
50 30 12 31,5
52 24,96 12 31,5
54 32,4 12 31,5
56 26,88 12 31,5
58 19,14 11 31,5
62 20,46 11 31,5
64 28,16 11 31,5
69 30,3 11 31,5
70 21 10 31,5
72 19,44 9 31,5
74 19,98 9 31,5
76 20,52 9 31,5
78 21,06 9 31,5
80 19,2 8 31,5
82 22,96 7 33,7
84 11,76 7 33,9
86 18,06 7 34
88 18,48 7 34,1
90 16,2 6 34,2
92 11,04 6 34,2
94 16,92 6 34,4
96 14,4 5 34,4
98 7,84 4 34,5
100 20 4 34,6
Table2 (3s sampling rate with missing points:
0 7,55390615 9,3871132425
3 26,9564624 35,8988782425000
6 25,7416124 36,5810632425
9 25,9596624 36,7492732425
15 25,8194874 36,6137707425
18 25,65205615 36,5483557425
21 25,66763115 36,4642507425
24 25,7883374 36,3614557425
27 25,58196865 36,4175257425
30 25,7104624 36,4362157425
33 25,5469249 36,3988357425
36 25,6870999 36,5063032425
39 25,5936499 36,3708007425
42 25,7338249 36,3567832425
45 25,50409365 36,4455607425
48 25,63648115 36,4128532425
51 25,64426865 36,4128532425
54 25,3755999 36,4408882425
57 25,4534749 36,3988357425
60 25,63648115 36,3708007425
63 25,63648115 36,3708007425
66 25,4768374 36,2633332425
69 25,57418115 36,4315432425
72 25,5780749 36,3614557425
75 25,5157749 36,3053857425
78 25,5858624000000 36,5249932425000
81 25,5235624 36,4081807425
84 25,58196865 36,2866957425
87 25,49630615 36,1231582425
90 25,4690499 36,2399707425
93 25,58196865 36,2072632425
96 25,5391374 36,2820232425
99 25,5702874 36,3380932425
102 25,4768374 36,2913682425
105 25,55081865 36,2680057425
MergedTable:
0 0 14 30,4 7,55390615 9,3871132425
6 4,2 14 30,8 25,7416124 36,5810632425
18 7,56 14 31,4 25,65205615 36,5483557425
24 15,6 13 31,4 25,7883374 36,3614557425
30 15,6 13 31,5 25,7104624 36,4362157425
36 23,4 13 31,5 25,6870999 36,5063032425
42 16,38 13 31,5 25,7338249 36,3567832425
48 28,8 12 31,5 25,63648115 36,4128532425
54 32,4 12 31,5 25,3755999 36,4408882425
72 19,44 9 31,5 25,5780749 36,3614557425
78 21,06 9 31,5 25,5858624 36,5249932425
84 11,76 7 33,9 25,58196865 36,2866957425
90 16,2 6 34,2 25,4690499 36,2399707425
96 14,4 5 34,4 25,5391374 36,2820232425
Obviously, in pratice there might be no difference in sampling rate or more complicated difference in sampling rate.

Sign in to comment.

Answers (1)

Andreas Goser
Andreas Goser on 8 Mar 2011
The generic idea is to create a time vector that is equidistant and then map the measured data to it (interpolating). Example code:
a=[1 1; 2 2; 3 2.5; 4 2.2; 5 2.1]; % time and data 'a'
b=[1.1 1.1; 2.1 2.2; 3.0 2.8; 4.1 2.3; 5.0 2.0]; % time and data 'b'
plot(a(:,1),a(:,2),'-ks',b(:,1),b(:,2),'-bs');
t=0:0.2:5; % new equidistant time vector
a_i=interp1(a(:,1),a(:,2),t); % mapping (interpolate data 'a' to new time vector)
b_i=interp1(b(:,1),b(:,2),t); % mapping (interpolate data 'b' to new time vector)
figure
plot(t,a_i,'-ks',t,b_i,'-bs');

Products

Community Treasure Hunt

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

Start Hunting!