-
Notifications
You must be signed in to change notification settings - Fork 0
/
right_stance_function.m
224 lines (193 loc) · 8.01 KB
/
right_stance_function.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
function [r_f_k_data, r_stance_kinematics_data, plate1, plate2, start_frame1, start_frame2, end_frame1, end_frame2] = right_stance_function(sample_freq, analog_freq, down_rate, markers, grw, start, finish, events, output_folder)
% Frame at which events happen in kinematics matrix
try
right_foot_strike = round((events.Right_Foot_Strike(1)*sample_freq) - start);
right_foot_off = round((events.Right_Foot_Off(1)*sample_freq) - start);
% If earlier foot-off picked out, then frame will be negative
if right_foot_off <= right_foot_strike
right_foot_off = (events.Right_Foot_Off(2)*sample_freq) - start;
end
% Frame at which events happen in force plate matrix size
r_strike = round(right_foot_strike*down_rate);
r_off = round(right_foot_off*down_rate);
r_frame = r_off-r_strike+1;
catch
r_stance_kinematics_data = zeros(finish-start,96);
r_f_k_data = zeros(finish-start,97);
start_frame1 = 1;
start_frame2 = 1;
end_frame1 = 1;
end_frame2 = 1;
plate1 = 'X';
plate2 = 'X';
return
end
% Force plate information
COP1 = grw(1).P;
ex_force1 = grw(1).F;
COP2 = grw(2).P;
ex_force2 = grw(2).F;
% Determine which force plate is right/left
if (ex_force1(r_strike-50,1) == 0)&&(ex_force1(r_strike+50,1) ~= 0)
plate1 = 'R';
plate2 = 'L';
r_force(:,1:3) = COP1(r_strike+1:r_strike+r_frame,:);
r_force(:,4:6) = ex_force1(r_strike+1:r_strike+r_frame,:);
elseif (ex_force2(r_strike-50,1) == 0)&&(ex_force2(r_strike+50,1) ~= 0)
plate2 = 'R';
plate1 = 'L';
r_force(:,1:3) = COP2(r_strike+1:r_strike+r_frame,:);
r_force(:,4:6) = ex_force2(r_strike+1:r_strike+r_frame,:);
end
% Create shortened matrices (to match dimensions of kinematics data) which
% display a 1 or 0, depending on whether a force is measured
binary_force1 = zeros(finish-start,1);
binary_force2 = zeros(finish-start,1);
for row = 1:(finish-start)
if ex_force1(row*down_rate,1) ~= 0
binary_force1(row,1) = 1;
end
if ((ex_force1(row*down_rate-1,1) == 1)||(ex_force1(row*down_rate-2,1) == 1)) && ((ex_force1(row*down_rate+1,1) == 1)||(ex_force1(row*down_rate+1,1) == 1))
binary_force1(row,1) = 1;
end
if ex_force2(row*down_rate,1) ~= 0
binary_force2(row,1) = 1;
end
if ((ex_force2(row*down_rate-1,1) == 1)||(ex_force2(row*down_rate-2,1) == 1)) && ((ex_force2(row*down_rate+1,1) == 1)||(ex_force2(row*down_rate+1,1) == 1))
binary_force2(row,1) = 1;
end
end
% Find frames with first and last force plate readings
start_frame1 = 1;
while binary_force1(start_frame1,1) == 0
start_frame1=start_frame1+1;
end
start_frame2 = 1;
while binary_force2(start_frame2,1) == 0
start_frame2=start_frame2+1;
end
end_frame1 = start_frame1;
try
while binary_force1(end_frame1,1) == 1
end_frame1=end_frame1+1;
end
catch
r_stance_kinematics_data = zeros(finish-start,96);
r_f_k_data = zeros(finish-start,97);
start_frame1 = 1;
start_frame2 = 1;
end_frame1 = 1;
end_frame2 = 1;
return
end
end_frame2 = start_frame2;
try
while binary_force2(end_frame2,1) == 1
end_frame2=end_frame2+1;
end
catch
r_stance_kinematics_data = zeros(finish-start,96);
r_f_k_data = zeros(finish-start,97);
start_frame1 = 1;
start_frame2 = 1;
end_frame1 = 1;
end_frame2 = 1;
return
end
try
RASIS(start:finish,:) = markers.RASIS;
LASIS(start:finish,:) = markers.LASIS;
RPSIS(start:finish,:) = markers.RPSIS;
LPSIS(start:finish,:) = markers.LPSIS;
RFLE(start:finish,:)= markers.RFLE;
RFME(start:finish,:) = markers.RFME;
RT1(start:finish,:) = markers.RT1;
RT2(start:finish,:) = markers.RT2;
RT3(start:finish,:) = markers.RT3;
RFAM(start:finish,:) = markers.RFAM;
RTAM(start:finish,:) = markers.RTAM;
RC1(start:finish,:) = markers.RC1;
RC2(start:finish,:) = markers.RC2;
RC3(start:finish,:) = markers.RC3;
RFCC(start:finish,:) = markers.RFCC;
RFM2(start:finish,:) = markers.RFM2;
RTF(start:finish,:) = markers.RTF;
RFMT(start:finish,:) = markers.RFMT;
LFLE(start:finish,:)= markers.LFLE;
LFME(start:finish,:) = markers.LFME;
LT1(start:finish,:) = markers.LT1;
LT2(start:finish,:) = markers.LT2;
LT3(start:finish,:) = markers.LT3;
LFAM(start:finish,:) = markers.LFAM;
LTAM(start:finish,:) = markers.LTAM;
LC1(start:finish,:) = markers.LC1;
LC2(start:finish,:) = markers.LC2;
LC3(start:finish,:) = markers.LC3;
LFCC(start:finish,:) = markers.LFCC;
LFM2(start:finish,:) = markers.LFM2;
LTF(start:finish,:) = markers.LTF;
LFMT(start:finish,:) = markers.LFMT;
r_stance_kinematics_data = zeros(finish-start,96);
for row = 1:finish-start
for col = 1:3
r_stance_kinematics_data(row,col) = RFLE(row+start,col);
r_stance_kinematics_data(row,col+3) = RFME(row+start,col);
r_stance_kinematics_data(row,col+6) = RT1(row+start,col);
r_stance_kinematics_data(row,col+9) = RT2(row+start,col);
r_stance_kinematics_data(row,col+12) = RT3(row+start,col);
r_stance_kinematics_data(row,col+15) = RFAM(row+start,col);
r_stance_kinematics_data(row,col+18) = RTAM(row+start,col);
r_stance_kinematics_data(row,col+21) = RC1(row+start,col);
r_stance_kinematics_data(row,col+24) = RC2(row+start,col);
r_stance_kinematics_data(row,col+27) = RC3(row+start,col);
r_stance_kinematics_data(row,col+30) = RFCC(row+start,col);
r_stance_kinematics_data(row,col+33) = RFM2(row+start,col);
r_stance_kinematics_data(row,col+36) = RTF(row+start,col);
r_stance_kinematics_data(row,col+39) = RFMT(row+start,col);
r_stance_kinematics_data(row,col+42) = LFLE(row+start,col);
r_stance_kinematics_data(row,col+45) = LFME(row+start,col);
r_stance_kinematics_data(row,col+48) = LT1(row+start,col);
r_stance_kinematics_data(row,col+51) = LT2(row+start,col);
r_stance_kinematics_data(row,col+54) = LT3(row+start,col);
r_stance_kinematics_data(row,col+57) = LFAM(row+start,col);
r_stance_kinematics_data(row,col+60) = LTAM(row+start,col);
r_stance_kinematics_data(row,col+63) = LC1(row+start,col);
r_stance_kinematics_data(row,col+66) = LC2(row+start,col);
r_stance_kinematics_data(row,col+69) = LC3(row+start,col);
r_stance_kinematics_data(row,col+72) = LFCC(row+start,col);
r_stance_kinematics_data(row,col+75) = LFM2(row+start,col);
r_stance_kinematics_data(row,col+78) = LTF(row+start,col);
r_stance_kinematics_data(row,col+81) = LFMT(row+start,col);
r_stance_kinematics_data(row,col+84) = RASIS(row+start,col);
r_stance_kinematics_data(row,col+87) = LASIS(row+start,col);
r_stance_kinematics_data(row,col+90) = RPSIS(row+start,col);
r_stance_kinematics_data(row,col+93) = LPSIS(row+start,col);
end
end
catch %unlabeled
r_stance_kinematics_data = zeros(finish-start,96);
r_f_k_data = zeros(finish-start,97);
start_frame1 = 1;
start_frame2 = 1;
end_frame1 = 1;
end_frame2 = 1;
return
end
if plate1 == 'R'
r_f_k_data = zeros(end_frame1-start_frame1+20, 97);
for row = 1:end_frame1-start_frame1+20
r_f_k_data(row,97) = binary_force1(row+start_frame1-11,1);
for col = 1:96
r_f_k_data(row,col) = r_stance_kinematics_data(row+start_frame1-11,col);
end
end
end
if plate2 == 'R'
r_f_k_data = zeros(end_frame2-start_frame2+20, 97);
for row = 1:end_frame2-start_frame2+20
r_f_k_data(row,97) = binary_force2(row+start_frame2-11,1);
for col = 1:96
r_f_k_data(row,col) = r_stance_kinematics_data(row+start_frame2-11,col);
end
end
end