-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.m
73 lines (68 loc) · 1.68 KB
/
main2.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
clear all;
c_n = 1; % choose the channel number
result_list= load(['results/12_',num2str(c_n),'.mat']);
en_g_list = result_list.en_g_list;
semg = result_list.semg;
%% hyper-parameter
lambda_h = 0.15; % high factor
lambda_l = 0.05; % low factor
detection_range = 100; % detection range
act_flag = 0;
global_flag = 0;
on_buffer = [];
off_buffer = [];
th = min(en_g_list)+lambda_h*(max(en_g_list)-min(en_g_list));
tl = min(en_g_list)+lambda_l*(max(en_g_list)-min(en_g_list));
%% scanning from begin to end
len = length(en_g_list);
i = 1;
while i+detection_range-1 <= len
if act_flag == 0
thread = th;
elseif act_flag == 1
thread = tl;
end
if sum(en_g_list(i:i+detection_range-1) >= thread)==detection_range && global_flag == 0
on_buffer = [on_buffer, i];
act_flag = 1;
global_flag = 1;
end
if sum(en_g_list(i:i+detection_range-1) < thread)==detection_range && global_flag == 1
off_buffer = [off_buffer, i];
act_flag = 0;
global_flag = 0;
end
i = i + 1;
end
on_position = on_buffer;
off_position = off_buffer;
subplot(211)
plot(semg)
hold on
i = 1;
while i <= length(on_position)
plot([on_position(i),on_position(i)], [-1, 1], 'r')
i = i+ 1;
hold on
end
i = 1;
while i <= length(off_position)
plot([off_position(i),off_position(i)], [-1, 1], 'g')
i = i+ 1;
hold on
end
subplot(212)
plot(en_g_list)
hold on
i = 1;
while i <= length(on_position)
plot([on_position(i),on_position(i)], [0, 1], 'r')
i = i+ 1;
hold on
end
i = 1;
while i <= length(off_position)
plot([off_position(i),off_position(i)], [0, 1], 'g')
i = i+ 1;
hold on
end