-
Notifications
You must be signed in to change notification settings - Fork 7
/
sync.m
30 lines (30 loc) · 989 Bytes
/
sync.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [data_1_sync, timestamp_1_sync, data_2_sync, timestamp_2_sync] = sync(data_1, timestamp_1, data_2, timestamp_2, threshold, flag)
print = flag;
if print
fprintf('|\tTimestamp 1 Sync\t|\tTimestamp 2 Sync\t|\n');
end
data_1_sync = [];
data_2_sync = [];
timestamp_1_sync = [];
timestamp_2_sync = [];
[m, ~] = size(data_1);
[n, ~] = size(data_2);
index = 1;
last_index = 1;
for i = 1 : m
[ind, err] = findNearest(timestamp_1(i), timestamp_2(last_index : n));
if err < threshold
data_1_sync(index, :) = data_1(i, :);
data_2_sync(index, :) = data_2(last_index + ind - 1, :);
timestamp_1_sync(index, 1) = timestamp_1(i);
timestamp_2_sync(index, 1) = timestamp_2(last_index + ind - 1);
if print
fprintf('|\t%f\t|\t%f\t|\n',timestamp_1(i), timestamp_2(last_index + ind - 1)); % Print Synchronization Result
end
index = index + 1;
last_index = last_index + ind;
else
continue
end
end
end