-
Notifications
You must be signed in to change notification settings - Fork 0
/
forcematrixfunction.m
128 lines (90 loc) · 3.48 KB
/
forcematrixfunction.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
wd = pwd;
load_file = sprintf('WALKING 3.c3d');
btk_load = [load_file];
raw_markers_unmirrored = 'raw_markers_unmirrored.txt';
raw_markers_opposite = 'raw_markers_opposite.txt';
output_filename = 'marker_and_force_data.txt';
acq = btkReadAcquisition(btk_load);
% Sample frequency (motion tracking vicon)
sample_freq = btkGetPointFrequency(acq);
% Analog Frequency (forceplates)
analog_freq = btkGetAnalogFrequency(acq);
% Downsampling Rate
down_rate = analog_freq/sample_freq;
markers = btkGetMarkers(acq);
grw = btkGetGroundReactionWrenches(acq);
start = btkGetFirstFrame(acq); % These use relative frame numbering. So if you want Nexus frame # 200, you need to go to "200 - start + 1"
finish = btkGetLastFrame(acq); % When event markers are set up, use them to define the start/end of the data
% Events from the trial
[events] = btkGetEvents(acq);
%frame at which events happen in kinematics matrix
right_foot_strike = (events.Right_Foot_Strike(1)*sample_freq) - start;
right_foot_off = (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);
%frame at which events happen in kinematics matrix
left_foot_strike = (events.Left_Foot_Strike(1)*sample_freq) - start;
left_foot_off = (events.Left_Foot_Off(1)*sample_freq) - start;
%if earlier foot-off picked out, then frame will be negative
if left_foot_off <= left_foot_strike
left_foot_off = (events.Left_Foot_Off(2)*sample_freq) - start;
end
%frame at which events happen in force plate matrix size
l_strike = round(left_foot_strike*down_rate);
l_off = round(left_foot_off*down_rate);
% 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';
elseif (ex_force2(r_strike-50,1) == 0)&&(ex_force2(r_strike+50,1) ~= 0)
plate2 = 'R';
end
if (ex_force1(l_strike-50,1) == 0)&&(ex_force1(l_strike+50,1) ~= 0)
plate1 = 'L';
end
if (ex_force2(l_strike-50,1) == 0)&&(ex_force2(l_strike+50,1) ~= 0)
plate2 = 'L';
end
%create matrices which display a 1 or 0, depending on whether a force is
%measured
binary_force1 = zeros((finish-start)*down_rate, 1);
binary_force2 = zeros((finish-start)*down_rate, 1);
for row = 1:(finish-start)*down_rate
if ex_force1(row,1) ~= 0
binary_force1(row,1) = 1;
end
if ex_force2(row,1) ~= 0
binary_force2(row,1) = 1;
end
end
r_binary_force = zeros(r_off-r_strike+40, 1);
l_binary_force = zeros(l_off-l_strike+40, 1);
if plate1 == 'R'
for row = 1:r_off-r_strike+40
r_binary_force(row,1) = binary_force1(row+r_strike,1);
end
end
if plate2 == 'L'
for row = 1:l_off-l_strike+40
l_binary_force(row,1) = binary_force2(row+l_strike,1);
end
end
if plate2 == 'R'
for row = 1:r_off-r_strike+40
r_binary_force(row,1) = binary_force2(row+r_strike,1);
end
end
if plate1 == 'L'
for row = 1:l_off-l_strike+40
l_binary_force(row,1) = binary_force1(row+l_strike,1);
end
end