-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgreaterFunc.m
149 lines (106 loc) · 3.04 KB
/
greaterFunc.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function grtRes = greaterFunc(nodeID,grtData)
analogSgl = [];
timeArr = [];
tmpTs = [];
grtRes = [];
risingEdgs = [];
fallingEdges = [];
res = {};
sit = -1;
risIsEmpty = 0;
falIsEmpty = 0;
firstRow = grtData(1,:);
secondRow = grtData(2,:);
% if (firstRow{2} == 2 || secondRow{2} == 2 )
% we have comparison a signal with a threshold
if(firstRow{1} < secondRow{1})
signalRow = grtData(1,:);
valueRow = grtData(2,:);
else
signalRow = grtData(2,:);
valueRow = grtData(1,:);
end
thrshdVlu = valueRow{3};
thrshdVlu= str2double(thrshdVlu);
timeArr = signalRow{3};
analogSgl = signalRow{4};
if(signalRow{2}==2)
timeArr = timeArr.';
analogSgl = analogSgl.';
end
timStp = length(timeArr);
% timeStemps = timStp(1,2);
if(~isempty(analogSgl))
% for i=1 : timStp - 1
%
% if (analogSgl(i)<=thrshdVlu && analogSgl(i+1)>thrshdVlu)
% % if(length(fallingEdges)==length(risingEdgs))
% risingEdgs = [risingEdgs,timeArr(i+1)];
% % end
% end
% if (analogSgl(i)>thrshdVlu && analogSgl(i+1)<=thrshdVlu)
% fallingEdges = [fallingEdges,timeArr(i+1)];
%
% end
%
% end
for i=1 : timStp
if(i==1)
if(analogSgl(i)>thrshdVlu)
sit = 1;
else
sit = 0;
end
else
if(analogSgl(i)>thrshdVlu && sit == 0)
risingEdgs = [risingEdgs,timeArr(i)];
sit = 1;
elseif(analogSgl(i)<thrshdVlu && sit == 1)
fallingEdges = [fallingEdges,timeArr(i)];
sit = 0;
end
end
end
if (isempty(risingEdgs))
risIsEmpty = 1;
else
risIsEmpty = 0;
end
if(isempty(fallingEdges))
falIsEmpty = 1;
else
falIsEmpty = 0;
end
% If there is no edge and the signal is always greater than threshold
if (risIsEmpty == 1 && falIsEmpty == 1)
if (analogSgl(1)>=thrshdVlu)
risingEdgs = [-1,risingEdgs];
fallingEdges = [fallingEdges,-1];
else
% If the signal is always less than threshold both rising and falling edegs reamin empty
end
% Else if rising is not empty but falling is empty
elseif(risIsEmpty == 0 && falIsEmpty == 1)
% we add a vritual falling at the end of falling
fallingEdges = [fallingEdges,-1];
% If rising is empty but falling is not empty, It means the signal remains
% 1 until stoptime.
elseif (risIsEmpty == 1 && falIsEmpty == 0)
% we should add a virtual rising
risingEdgs = [-1,risingEdgs];
% If none of them are empty
else
if(~isempty(fallingEdges))
if(fallingEdges(1)<risingEdgs(1))
risingEdgs = [-1,risingEdgs];
end
if(fallingEdges(length(fallingEdges))<risingEdgs(length(risingEdgs)))
fallingEdges = [fallingEdges,-1];
end
end
end
end
grtRes = {nodeID,3,risingEdgs,fallingEdges};
disp('GreaterFunc');
disp(risingEdgs);
end