-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalSynergy.m
149 lines (117 loc) · 4.18 KB
/
calSynergy.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
%% EMG
period = [1 3]
%% extract period trials
eval(['T = ',file,';']);
for i_sub = subject
trialNum = length(T(i_sub).ForcePlate);
for i_trial = 1:trialNum
n = size(T(i_sub).EMG2.Right(i_trial).M, 2);
temp = [1:2*f:n];
T(i_sub).Synergy(i_trial).period2.start = temp(1:end-1);
T(i_sub).Synergy(i_trial).period2.finish = temp(2:end)-1;
temp = [1:5*f:n];
T(i_sub).Synergy(i_trial).period5.start = temp(1:end-2);
T(i_sub).Synergy(i_trial).period5.finish = temp(2:end)-1;
temp = [1:10*f:n];
T(i_sub).Synergy(i_trial).period10.start = temp(1:end-1);
T(i_sub).Synergy(i_trial).period10.finish = temp(2:end)-1;
temp = [1:20*f:n];
if temp==1
temp=[1,n];
end
T(i_sub).Synergy(i_trial).period20.start = temp(end-1);
T(i_sub).Synergy(i_trial).period20.finish = temp(end)-1;
end
end
eval([file,' = T;']);
%% NNMF EMG
eval(['T = ',file,';']);
option.side = 'Right'; % Right: right side, Left: left side;
option.NormalizeToUnitVariance = 1; % 0:do not divide, 1:divide and then multiply, 3:divide and do not multiply
option.rep = 1;
option.mus = [];
SYN = 5;
for i_sub = subject
trialNum = length(T(i_sub).ForcePlate);
for i_trial = 1:trialNum
for i_period=nnmfID
M_t = T(i_sub).EMG2.(option.side)(i_trial).M;
start = T(i_sub).Synergy(i_trial).(nnmfField{i_period}).start;
finish = T(i_sub).Synergy(i_trial).(nnmfField{i_period}).finish;
for i_interval = 1:length(start)
% M = M_t(:,start(i_interval):min(finish(i_interval),size(M_t,2)));
M = M_t(:,start(i_interval):finish(i_interval));
% if finish(i_interval)< size(M_t,2)
% M = M_t(:,start(i_interval):finish(i_interval));
% else
%
% continue;
% end
for i_syn = SYN
disp(['sub:',num2str(i_sub),', trial:',num2str(i_trial),', syn:',num2str(i_syn),', ' ])
[W_best, S_best, M_rec] = nnmfEMG1122(M,i_syn,option);
T(i_sub).Synergy(i_trial).(nnmfField{i_period}).interval(i_interval).syn(i_syn).W_best = W_best;
T(i_sub).Synergy(i_trial).(nnmfField{i_period}).interval(i_interval).syn(i_syn).S_best = S_best;
T(i_sub).Synergy(i_trial).(nnmfField{i_period}).interval(i_interval).syn(i_syn).M_rec = M_rec;
end
end
end
end
end
eval([file,' = T;']);
save(['raw Data\' file '.mat'],file)
%%
file='T2'
load(['raw Data\' file '.mat'])
eval(['T = ',file,';']);
%% intra_period
type = 'EMG2';
subjects = [3];
period = {'period2' 'period5' 'period10' 'period20'};
% period = {'period2' 'period5'}
trial=0;
toPlot=0;
SYN = 5;
N=5;
[T, W, name, Wtype, id] = intra_period(T, type, subjects, period, trial, SYN, N, toPlot);
%% inter_period
type = 'EMG2';
subjects = [3 4];
period = {'period2' 'period5'};
trial=0;
toPlot=1;
SYN = 5;
N=5;
[T, W, name, Wtype, id] = inter_period(T, type, subjects, period, trial, SYN, N, toPlot);
%% inter_trial
type = 'EMG2';
subjects = [3 4];
period = {'period2' 'period5' 'period10' 'period20'};
trial=0;
toPlot=1;
SYN = 5;
N=5;
[T, W, name, Wtype, id] = inter_trial(T, type, subjects, period, trial, SYN, N, toPlot);
%% t-SNE Comp
type = 'EMG2';
subjects = [3];
files = {'T1' 'T2'};
period = {'period2' 'period5' 'period10' 'period20'};
period = {'period2'};
trial=0;
toPlot=1;
SYN = 5;
N=5;
[Y, TYPE] = tSNEComp(files, type, subjects, period, trial, SYN, N, toPlot);
%% tSNE plot
labels = {'subject' 'period' 'id'};
for i=1:length(labels)
tSNEPlot(Y, TYPE, labels{i})
end
%%
for i=1:5
subplot(5,2,2*i-1)
bar(T2(3).Synergy(1).period2.interval(1).syn(5).W_best(:,i))
subplot(5,2,2*i)
bar(T3(3).Synergy(1).period2.interval(1).syn(5).W_best(:,i))
end