-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxMinCleaning.m
88 lines (84 loc) · 3.46 KB
/
maxMinCleaning.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% Copyright: (C) 2023 Department of COgNiTive Architecture for Collaborative Technologies
% Istituto Italiano di Tecnologia
% Author: Alessandro Tiozzo
% email: [email protected]
% Permission is granted to copy, distribute, and/or modify this program
% under the terms of the GNU General Public License, version 2 or any
% later version published by the Free Software Foundation.
%
% A copy of the license can be found at
% http://www.robotcub.org/icub/license/gpl.txt
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details
function [newMinPeaksVal,newMinLocalization,newMaxPeaksVal,newMaxLocalization] = maxMinCleaning(minPeaksVal,minLocalization,maxPeaksVal,maxLocalization,ITERATE)
% Function used to remove double peaks which can alterate results
if nargin == 4
ITERATE = 1;
end
numberOfBackIndx = 3;
iterations = 0;
processComplete = 0;
timeThreshold = 2*100; % Check that this has to be lower than the average phase duration for baselines
while abs(length(minLocalization)-length(maxLocalization)) > 1 || (length(minLocalization) >= 80 && length(maxLocalization) >= 80) || processComplete == 0
processComplete = 1;
cnt = 1;
while cnt <= length(minLocalization) - 1
if minLocalization(cnt+1) - minLocalization(cnt) < timeThreshold
processComplete = 0;
if minPeaksVal(cnt+1) < minPeaksVal(cnt)
minLocalization(cnt) = [];
minPeaksVal(cnt) = [];
else
minLocalization(cnt+1) = [];
minPeaksVal(cnt+1) = [];
end
if cnt - numberOfBackIndx < 1
cnt = 1;
else
cnt = cnt - numberOfBackIndx;
end
else
cnt = cnt + 1;
end
end
cnt = 1;
while cnt <= length(maxLocalization) - 1
if maxLocalization(cnt+1) - maxLocalization(cnt) < timeThreshold
processComplete = 0;
if maxPeaksVal(cnt+1) > maxPeaksVal(cnt)
maxLocalization(cnt) = [];
maxPeaksVal(cnt) = [];
else
maxLocalization(cnt+1) = [];
maxPeaksVal(cnt+1) = [];
end
if cnt - numberOfBackIndx < 1
cnt = 1;
else
cnt = cnt - numberOfBackIndx;
end
else
cnt = cnt + 1;
end
end
iterations = iterations + 1;
if iterations > 10 && abs(length(minLocalization)-length(maxLocalization)) < 3
% disp("Threshold of minimum reached, ending cleaning.")
break;
else
if iterations > 20 && ITERATE
error("Error in maxMinCleaning.m - Peaks cleaning has not been successfull.");
else
% If ITERATE is = 0 we do not care of the error
break;
end
end
end
newMinPeaksVal = minPeaksVal;
newMinLocalization = minLocalization;
newMaxPeaksVal = maxPeaksVal;
newMaxLocalization = maxLocalization;
end