This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompute_delays.m
47 lines (38 loc) · 1.47 KB
/
compute_delays.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
% assuming that both real_changes and detected_changes are sorted
function delays = compute_delays(real_changes, detected_changes)
delays = [];
i = 1; % index of real_changes
j = 1; % index of detected_changes
num_real_changes = numel(real_changes);
num_detected_changes = numel(detected_changes);
while j <= num_detected_changes
% case 1
if detected_changes(j) <= real_changes(i)
negative_delay = detected_changes(j) - real_changes(i);
delays = [delays negative_delay];
j = j+1;
% case 2
elseif detected_changes(j) > real_changes(i) &&...
i+1 <= num_real_changes &&...
detected_changes(j) >= real_changes(i+1)
i = i+1;
% case 3
elseif detected_changes(j) > real_changes(i) &&...
i+1 <= num_real_changes &&...
detected_changes(j) < real_changes(i+1)
positive_delay = detected_changes(j) - real_changes(i);
negative_delay = detected_changes(j) - real_changes(i+1);
if abs(negative_delay) < positive_delay
delays = [delays negative_delay];
else
delays = [delays positive_delay];
end
j = j+1;
% case 4
else
positive_delay = detected_changes(j) - real_changes(i);
delays = [delays positive_delay];
j = j+1;
end
end
end