forked from anagamori/MU-Population-Model-Nagamori-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMU_population_model_no_tendon.m
349 lines (285 loc) · 10.7 KB
/
MU_population_model_no_tendon.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
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
%==========================================================================
% muscleModel_noTendon.m
% Author: Akira Nagamori
% Last update: 7/10/2020
% Descriptions:
% Full model without tendon
%==========================================================================
function [output] = MU_population_model_noTendon(Fs,time,synaptic_input,modelParameter,figOpt)
%% Motor unit architecture
N_MU = modelParameter.N_MU; % number of motor units
i_MU = modelParameter.i_MU; % index for motor units
index_slow = modelParameter.index_slow;
%% Peak tetanic force
PTi = modelParameter.PTi;
%% Recruitment threshold
U_th = modelParameter.U_th;
%% Minimum and maximum firing rate
FR_half = modelParameter.FR_half;
MDR = modelParameter.MDR;
PDR = modelParameter.PDR;
g_e = modelParameter.g_e;
index_saturation = modelParameter.index_saturation;
lamda = modelParameter.lamda;
k_e = modelParameter.k_e;
U_th_t = modelParameter.U_th_t;
Z = randn(N_MU,length(time));
Z(Z>3.9) = 3.9;
Z(Z<-3.9) = -3.9;
%% Motor unit parameters
parameter_Matrix = modelParameter.parameterMatrix;
%% Activation dynamics (Song et al., 2008)
tau_1 = parameter_Matrix(:,7);
tau_2 = parameter_Matrix(:,8);
R_temp = 1-exp(-time./tau_1);
R_temp_2 = exp(-time./tau_2);
%% Initilization
spike_time = zeros(N_MU,1);
spike_time_mat = zeros(N_MU,length(time));
spike_train = zeros(N_MU,length(time));
force = zeros(N_MU,length(time));
Force = zeros(1,length(time));
% Module 2 parameteres
R = zeros(N_MU,length(time));
c = zeros(N_MU,1);
cf = zeros(N_MU,1);
A = zeros(N_MU,1);
c_mat = zeros(N_MU,length(time));
cf_mat = zeros(N_MU,length(time));
A_tilde_mat = zeros(N_MU,length(time));
A_mat = zeros(N_MU,length(time));
a_s = ones(N_MU,1)*0.96;
S_i = zeros(N_MU,1);
Y_i = zeros(N_MU,1);
S_mat = zeros(N_MU,length(time));
Y_mat = zeros(N_MU,length(time));
% Muscle length
Lce = 1;
Vce = 0;
FL = zeros(N_MU,1);
FV = zeros(N_MU,1);
DR_temp = zeros(N_MU,1);
DR_mat = zeros(N_MU,length(time));
%% Simulation
rng('shuffle')
for t = 1:length(time)
if t > 1
%% Module 1
U_eff = synaptic_input(t);
CV_ISI = 10+20*exp(-(U_eff*100-U_th*100)/2.5);
CV_ISI = CV_ISI./100;
% for constant CoV of ISI
% CV_ISI = ones(N_MU)*0.1;
% compute discharge rate (DR_MU)
DR_MU = g_e.*(U_eff-U_th)+MDR;
for m = 1:length(index_saturation)
index = index_saturation(m);
if U_eff <= U_th_t(index)
DR_temp(index) = MDR(index) + lamda(index).*k_e(index)*(U_eff-U_th(index));
else
DR_temp(index) = PDR(index)-k_e(index)*(1-U_eff);
end
end
DR_MU(index_saturation) = DR_temp(index_saturation);
DR_MU(DR_MU<MDR) = 0;
DR_MU(DR_MU>PDR) = PDR(DR_MU>PDR);
DR_mat(:,t) = DR_MU;
%% Sag & Yield (Song et al., 2008)
f_eff = DR_MU./FR_half;
S_i = sag_function(S_i,f_eff,a_s,Fs);
S_i(1:index_slow) = 1;
S_mat(:,t) = S_i;
Y_i = yield_function(Y_i,Vce,Fs);
Y_i(index_slow+1:end) = 1;
Y_mat(:,t) = Y_i;
% Convert activation into spike trains
index_1 = i_MU(DR_MU >= MDR & DR_mat(:,t-1) == 0);
index_2 = i_MU(DR_MU >= MDR & spike_time ==t);
index = [index_1;index_2];
% Generate spike trains
index_1 = i_MU(DR_MU >= MDR & DR_mat(:,t-1) == 0); % find index of units that discharge for the first time
index_2 = i_MU(DR_MU >= MDR & spike_time ==t); % find index of units whose spike time is at time = t
index = [index_1;index_2];
for j = 1:length(index) % loop through motor units whose firing rate is greater than minimum firing rate defined by the user
n = index(j);
spike_train_temp = zeros(1,length(t));
if ~any(spike_train(n,:)) % when the motor unit fires for the first time
spike_train(n,t) = 1; % add a spike to the vector
spike_train_temp(t) = 1;
% compute the spike time of the next spike
mu = 1/DR_MU(n); % interspike interval
spike_time_temp = (mu + mu*CV_ISI(n)*Z(n,t))*Fs; % add variabiltiy
if spike_time_temp <= 0.002*Fs
spike_time_temp = 0.002*Fs;
end
spike_time(n) = round(spike_time_temp) + t;
% assign the value of R
temp = conv(spike_train_temp,R_temp_2(n,:).*R_temp(n,:));
R(n,:) = R(n,:) + temp(1:length(time));
else % when the motor unit have already fired at least once
if spike_time(n) == t % when the motor unit fires
spike_train(n,t) = 1;
spike_train_temp(t) = 1;
% compute the spike time of the next spike
mu = 1/DR_MU(n); % interspike interval
spike_time_temp = (mu + mu*CV_ISI(n)*Z(n,t))*Fs; % add variabiltiy
if spike_time_temp <= 0.002*Fs
spike_time_temp = 0.002*Fs;
end
spike_time(n) = round(spike_time_temp) + t;
% assign the value of R
temp = conv(spike_train_temp,R_temp_2(n,:).*R_temp(n,:));
R(n,:) = R(n,:) + temp(1:length(time));
elseif t > spike_time(n) + round(1/DR_MU(n)*Fs) % after the motor unit stops firing
spike_train(n,t) = 1;
spike_train_temp(t) = 1;
spike_time(n) = t;
% compute the spike time of the next spike
mu = 1/DR_MU(n); % interspike interval
spike_time_temp = (mu + mu*CV_ISI(n)*Z(n,t))*Fs; % interspike interval
if spike_time_temp <= 0.002*Fs
spike_time_temp = 0.002*Fs;
end
spike_time(n) = round(spike_time_temp) + t;
% assign the value of R
temp = conv(spike_train_temp,R_temp_2(n,:).*R_temp(n,:));
R(n,:) = R(n,:) + temp(1:length(time));
end
end
end
%% Module 2: Convert spikes into activation
[c,cf,A_tilde,A] = spike2activation(R(:,t),c,cf,A,parameter_Matrix,Lce,S_i,Y_i,Fs);
c_mat(:,t) = c;
cf_mat(:,t) = cf;
A_tilde_mat(:,t) = A_tilde;
A_mat(:,t) = A;
%% Force-length and force-velocity
FL(1:index_slow) = FL_slow_function(Lce);
FL(index_slow+1:end) = FL_fast_function(Lce);
if Vce > 0
FV(1:index_slow) = FVecc_slow_function(Lce,Vce);
FV(index_slow+1:end) = FVecc_fast_function(Lce,Vce);
else
FV(1:index_slow) = FVcon_slow_function(Lce,Vce);
FV(index_slow+1:end) = FVcon_fast_function(Lce,Vce);
end
%%
f_i = A.*PTi.*FL.*FV;
force(:,t) = f_i;
Force(t) = sum(f_i);
end
spike_time_mat(:,t) = spike_time;
end
%%
if figOpt == 1
figure(1)
plot(time,Force)
xlabel('Time (s)')
ylabel('Force (N)')
hold on
end
output.Force = Force;
output.spike_train = spike_train;
%% Convert spike trian into activation
function [c,cf,A_tilde,A] = spike2activation(R,c,cf,A,parameter_Matrix,Lce,S_i,Y_i,Fs)
S = parameter_Matrix(:,1);
C = parameter_Matrix(:,2);
k_1 = parameter_Matrix(:,3);
k_2 = parameter_Matrix(:,4);
k_3 = parameter_Matrix(:,5);
k_4_i = parameter_Matrix(:,6);
N = parameter_Matrix(:,9);
K = parameter_Matrix(:,10);
tau_3 = parameter_Matrix(:,11);
gamma = parameter_Matrix(:,12);
phi_1 = parameter_Matrix(:,13);
phi_2 = parameter_Matrix(:,14);
if Lce >= 1
k_3 = (phi_1.*k_3)*(Lce-1) + k_3;
N = (-phi_1.*N)*(Lce-1) + N;
K = (-phi_1.*K)*(Lce-1) + K;
gamma = (phi_1.*gamma)*(Lce-1) + gamma;
elseif Lce < 1
k_3 = (phi_2.*k_3)*(Lce-1) + k_3;
N = (-phi_2.*N)*(Lce-1) + N;
K = (-phi_2.*K)*(Lce-1) + K;
gamma = (phi_2.*gamma)*(Lce-1) + gamma;
end
%% Stage 1
k_4 = k_4_i./(1+gamma.*A);
c_dot = k_1.*(C-c-cf).*R - k_2.*c.*(S-C+c+cf)-(k_3.*c-k_4.*cf).*(1-cf);
cf_dot = (1-cf).*(k_3.*c-k_4.*cf);
c = c_dot/Fs + c;
cf = cf_dot/Fs + cf;
%% Stage 2
if cf < 0
cf_temp = 0;
else
cf_temp = cf.*S_i.*Y_i;
end
A_tilde = cf_temp.^N./(cf_temp.^N+K.^N);
%% Stage 3
% First-order dynamics to muscle activation, A
A_dot = (A_tilde-A)./tau_3;
A = A_dot./Fs + A;
end
%% Sag
function [S] = sag_function(S,f_eff,a_s,Fs)
a_s(f_eff<0.1) = 20;
T_s = 0.015;
S_dot = (a_s - S)./T_s;
S = S_dot/Fs + S;
end
%% Yield
function [Y] = yield_function(Y,V,Fs)
c_y = 0.35;
V_y = 0.1;
T_y = 0.2;
Y_dot = (1-c_y.*(1-exp(-abs(V)./V_y))-Y)./T_y;
Y = Y_dot/Fs + Y;
end
%% Force-length relationship for slow twitch
function FL = FL_slow_function(L)
beta = 2.3;
omega = 1.12;
rho = 1.62;
FL = exp(-abs((L^beta - 1)/omega)^rho);
end
%% Force-length relationship for fast twitch
function FL = FL_fast_function(L)
beta = 1.55;
omega = 0.75;
rho = 2.12;
FL = exp(-abs((L^beta - 1)/omega)^rho);
end
%% Concentric force-velocity relationship for slow twitch
function FVcon = FVcon_slow_function(L,V)
Vmax = -7.88;
cv0 = 5.88;
cv1 = 0;
FVcon = (Vmax - V)/(Vmax + (cv0 + cv1*L)*V);
end
%% Concentric force-velocity relationship for fast twitch
function FVcon = FVcon_fast_function(L,V)
Vmax = -9.15;
cv0 = -5.7;
cv1 = 9.18;
FVcon = (Vmax - V)/(Vmax + (cv0 + cv1*L)*V);
end
%% Eccentric force-velocity relationship for slow twitch
function FVecc = FVecc_slow_function(L,V)
av0 = -4.7;
av1 = 8.41;
av2 = -5.34;
bv = 0.35;
FVecc = (bv - (av0 + av1*L + av2*L^2)*V)/(bv+V);
end
%% Eccentric force-velocity relationship for slow twitch
function FVecc = FVecc_fast_function(L,V)
av0 = -1.53;
av1 = 0;
av2 = 0;
bv = 0.69;
FVecc = (bv - (av0 + av1*L + av2*L^2)*V)/(bv+V);
end
end