-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_SelectEventsGUI.asv
397 lines (319 loc) · 11 KB
/
f_SelectEventsGUI.asv
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
% f_SelectEventsGUI.m
%
function f_SelectEventsGUI()
clc
addpath('../../Functions/');
% str_FileName = 'testLaurence-tout-trace';
% s_Inv = 1;
% str_FileName = 'testPierre-tout-trace';
% s_Inv = -1;
% str_FileName = 'pierre_10_C3-Fz';
% s_Inv = 1;
% v_TimeSegs = [24 287;298.5 596];
% v_TimeRef = [188.5 190;239 241;418 420];
% str_FileName = 'paolo_10_C3F3P3-cz2';
% v_TimeSegs = [55 624];
% s_SigInd = 5;
% s_PeakLevelTres = 20;
% str_FileName = 'Pierre10_forcemax';
% v_TimeSegs = [25 595];
% s_SigInd = 5;
% s_PeakLevelTres = 20;
% str_FileName = 'arlette 10-6-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 20;
% str_FileName = 'diabete-2';
% v_TimeSegs = [0 -1];
% s_SigInd = 3;
% s_PeakLevelTres = 20;
% str_FileName = 'Cyril-AgH';
% v_TimeSegs = [0 -1];
% s_SigInd = 2;
% s_PeakLevelTres = 10;
% str_FileName = 'david-vision';
% v_TimeSegs = [0 -1];
% s_SigInd = 2;
% s_PeakLevelTres = 10;
% str_FileName = 'LOIC_03-07-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'marion_03-07-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'didier 08-07-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'Ahmed 07-07-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'Catherine 07-07-14';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'paolo 15-1-2015-1';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'pierre 15-1-2015-1';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'pierre 15-1-2015-2';
% v_TimeSegs = [0 -1];
% s_SigInd = 5;
% s_PeakLevelTres = 10;
% str_FileName = 'pierre _2015-05-18';
% v_TimeSegs = [0 -1];
% s_SigInd = 2;
% s_PeakLevelTres = 10;
% str_FileName = 'paolo _2015-05-18';
% v_TimeSegs = [0 -1];
% s_SigInd = 3;
% s_PeakLevelTres = 10;
% str_FileName = 'paolo _2015-05-19';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'anne01-09-15';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
%
% str_FileName = 'david01-09-15';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'thibault 23-07-15';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'valentin 23-07-15';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'thibaud6-10-15';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'paolomilani_11-23';
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'pierrelozeron_11-23';
% v_TimeSegs = [375 635;690 1070;1415 2110];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'PL26-11-15';
% v_TimeSegs = [410 1075];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'pm26-11-15';
% v_TimeSegs = [375 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'Lozeron08092016'; % Constant force
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'Lozeron130919'; % Variable force
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'Milani08092106'; % Constant force
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
% str_FileName = 'Milani150916'; % Variable force
% v_TimeSegs = [0 -1];
% s_SigInd = 8;
% s_PeakLevelTres = 10;
str_FileName = 'LUOISON_MAURICE_DIAB';
v_TimeSegs = [0 -1];
s_SigInd = 8;
s_PeakLevelTres = 10;
str_FileFullName = ['../' str_FileName '.edf'];
str_DataFileName = ['../' str_FileName '.mat'];
if ~exist(str_FileFullName, 'file')
error('[p_DataAnalysis_01] - The following file does not exist: %s', ...
str_FileFullName);
end
[st_Header, m_SignalsMat] = edfread(str_FileFullName);
s_SRate = st_Header.samples(1);
v_EMGSigs = m_SignalsMat(s_SigInd, :)';
v_Time = (0:size(v_EMGSigs, 1) - 1)./ s_SRate;
st_Filt = f_GetIIRFilter(s_SRate, [10 30]);
v_EMGFiltSigs = f_IIRBiFilter(v_EMGSigs, st_Filt);
% v_EMGFiltEnvSigs = abs(v_EMGFiltSigs);
% v_EMGFiltEnvSigs = abs(hilbert(v_EMGFiltSigs));
s_RMSHalfSeg = (1 / 20) * 3;
s_RMSHalfSam = round(s_RMSHalfSeg * s_SRate);
% v_EMGFiltRMSSigs = f_RMSSignal(v_EMGFiltSigs, s_RMSHalfSam);
v_EMGFiltRMSSigs = filter(ones(1, s_RMSHalfSam), 1, v_EMGFiltSigs.^2)./ s_RMSHalfSam;
v_EMGFiltRMSSigs = sqrt(v_EMGFiltRMSSigs);
figure;
s_Axes1 = subplot(1, 1, 1);
plot(v_Time, v_EMGSigs)
v_Axe1Lims = get(s_Axes1, 'YLim');
set(s_Axes1, 'YLim', v_Axe1Lims);
hold on
plot(v_Time, v_EMGFiltRMSSigs, 'r')
plot(v_Time, v_EMGFiltSigs, 'r')
hold on
if exist(str_DataFileName, 'file')
v_TimeStartEvts = load(str_DataFileName, 'v_TimeStartEvts');
v_TimeStartEvts = v_TimeStartEvts.v_TimeStartEvts;
s_Min = min([min(v_EMGSigs) min(v_EMGFiltRMSSigs)]);
s_Max = max([max(v_EMGSigs) max(v_EMGFiltRMSSigs)]);
s_Dis = (s_Max - s_Min) * 0.05;
s_Min = s_Min - s_Dis;
s_Max = s_Max + s_Dis;
ylim([s_Min s_Max]);
for s_Counter = 1:numel(v_TimeStartEvts)
plot([v_TimeStartEvts(s_Counter) v_TimeStartEvts(s_Counter)], ...
[s_Min s_Max], 'k');
end
clear v_TimeStartEvts
return;
end
v_SigTemp = [];
v_SigFiltTemp = [];
v_TimeTemp = [];
for s_SegsCounter = 1:size(v_TimeSegs, 1)
if v_TimeSegs(s_SegsCounter, 1) == 0
s_FirstIndSam = 1;
else
s_FirstIndSam = round(v_TimeSegs(s_SegsCounter, 1) * s_SRate);
end
if v_TimeSegs(s_SegsCounter, 2) == -1
s_LastIndSam = numel(v_EMGSigs);
else
s_LastIndSam = round(v_TimeSegs(s_SegsCounter, 2) * s_SRate);
end
v_SigTemp = f_AddVerElems(v_SigTemp, v_EMGFiltRMSSigs(s_FirstIndSam:s_LastIndSam));
v_SigFiltTemp = f_AddVerElems(v_SigFiltTemp, v_EMGFiltSigs(s_FirstIndSam:s_LastIndSam));
v_TimeTemp = f_AddHorElems(v_TimeTemp, v_Time(s_FirstIndSam:s_LastIndSam));
end
[v_HistY, v_HistX] = hist(v_SigTemp, 100);
[v_Peaks, v_Ind] = findpeaks(-1.* v_HistY);
s_Ind = v_Ind(1);
s_StdThres = v_HistX(v_Ind(1));
s_Max = v_Peaks(1);
for s_Counter = 2:numel(v_Ind)
if v_HistX(v_Ind(s_Counter)) >= s_PeakLevelTres
break;
end
if v_Peaks(s_Counter) > s_Max
s_Ind = v_Ind(s_Counter);
s_StdThres = v_HistX(s_Ind);
s_Max = v_Peaks(s_Counter);
end
end
figure;
plot(v_HistX, v_HistY)
s_Min = min(v_HistY);
s_Max = max(v_HistY);
s_Dis = (s_Max - s_Min) * 0.05;
s_Min = s_Min - s_Dis;
s_Max = s_Max + s_Dis;
ylim([s_Min s_Max]);
hold on
plot([s_StdThres s_StdThres], [s_Min s_Max], 'r');
v_SigTemp = v_EMGFiltRMSSigs;
v_SigFiltTemp = v_EMGFiltSigs;
v_TimeTemp = v_Time;
v_SigTemp = v_SigTemp > s_StdThres;
v_Ind = zeros(numel(v_SigTemp), 1);
v_Ind(2:end) = diff(v_SigTemp);
v_Ind(1) = v_Ind(2);
v_IndStart = find(v_Ind == 1);
% v_IndStop = v_Ind == -1;
%
% s_Ind = 1;
% while v_IndStop(s_Ind) <= v_IndStart(1)
% s_Ind = s_Ind + 1;
% end
% v_IndStop = v_IndStop(s_Ind:end);
% if numel(v_IndStart) > numel(v_IndStop)
% v_IndStart = v_IndStart(1:end - 1);
% end
s_BefSec = 10;
s_AftSec = 10;
s_BefSam = s_BefSec * s_SRate;
s_AftSam = s_AftSec * s_SRate;
v_IndStart = [v_IndStart zeros(numel(v_IndStart), 1)];
s_Fig = figure;
s_Axes = subplot(1,1,1);
plot(v_SigFiltTemp./ max(v_SigFiltTemp))
hold on
plot(v_SigTemp, 'r')
s_Counter = 1;
while s_Counter <= size(v_IndStart, 1)
s_FisrtSam = v_IndStart(s_Counter, 1) - s_BefSam;
s_LastSam = v_IndStart(s_Counter, 1) + s_AftSam;
if s_FisrtSam < 1
s_FisrtSam = 1;
end
if s_LastSam > numel(v_SigFiltTemp)
s_LastSam = numel(v_SigFiltTemp);
end
s_FisrtSamAux = round(v_IndStart(s_Counter, 1) - 20 * s_SRate);
s_LastSamAux = round(v_IndStart(s_Counter, 1) + 20 * s_SRate);
if s_FisrtSamAux < 1
s_FisrtSamAux = 1;
end
if s_LastSamAux > numel(v_SigFiltTemp)
s_LastSamAux = numel(v_SigFiltTemp);
end
v_Axe1Lims = [min(v_EMGSigs(s_FisrtSamAux:s_LastSamAux)) max(v_EMGSigs(s_FisrtSamAux:s_LastSamAux))];
axes(s_Axes1);
plot([(v_IndStart(s_Counter, 1) / s_SRate) (v_IndStart(s_Counter, 1) / s_SRate)], ...
v_Axe1Lims, 'k');
set(s_Axes1, 'XLim', [(s_FisrtSamAux / s_SRate) (s_LastSamAux / s_SRate)], ...
'YLim', v_Axe1Lims);
axes(s_Axes);
xlim([s_FisrtSam s_LastSam]);
ylim([-1.5 1.5]);
hold on
plot([v_IndStart(s_Counter, 1) v_IndStart(s_Counter, 1)], [-1.5 1.5], 'g');
hold off
s_W = 0;
while s_W ~= 1
s_W = waitforbuttonpress;
end
s_W = get(s_Fig, 'CurrentCharacter');
switch s_W
case 'i',
v_IndStart(s_Counter, 2) = 1;
hold on
plot([v_IndStart(s_Counter, 1) v_IndStart(s_Counter, 1)], [-1.5 1.5], 'k');
hold off
s_Counter = s_Counter + 1;
case 'e',
v_IndStart(s_Counter, 2) = 0;
hold on
plot([v_IndStart(s_Counter, 1) v_IndStart(s_Counter, 1)], [-1.5 1.5], 'w');
plot([v_IndStart(s_Counter, 1) v_IndStart(s_Counter, 1)], [0 1], 'r');
hold off
s_Counter = s_Counter + 1;
case 'r',
s_Counter = s_Counter - 1;
case 's',
v_Ind = v_IndStart(:, 2) == 1;
v_TimeStartEvts = v_TimeTemp(v_IndStart(v_Ind, 1));
save(str_DataFileName, 'v_TimeStartEvts');
display(sprintf('[f_SelectEventsGUI] - Saved file: %s', ...
str_DataFileName));
otherwise,
end
end
v_Ind = v_IndStart(:, 2) == 1;
v_TimeStartEvts = v_TimeTemp(v_IndStart(v_Ind, 1));
save(str_DataFileName, 'v_TimeStartEvts');
display(sprintf('[f_SelectEventsGUI] - Saved file: %s', ...
str_DataFileName));
end