-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5_GaitEventsSplitBelt.m
150 lines (121 loc) · 3.42 KB
/
P5_GaitEventsSplitBelt.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
function TrialData = P5_GaitEventsSplitBelt(TrialData,Plates,VTaxis,Fthres,pltflag)
%This function finds the gait events for a left right split treadmill
% Plates = 1x2 array of the plate number for the right and left plates
% VTaxis = vertical axis for threasholding
% Fthres = force threshold
% pltflag = optional plot flag
% Note gait events are indexes in the force framerate not the marker
% framerate
%Originally Written By: Aaron N. Best (July 2023)
%Update Record:
%% Check for pltflag
if nargin == 4
pltflag = 0;
end
%% Pull out the force data
plate_names = fieldnames(TrialData.ForceData);
RF = TrialData.ForceData.(plate_names{Plates(1)}).Force(:,VTaxis);
LF = TrialData.ForceData.(plate_names{Plates(2)}).Force(:,VTaxis);
%% Find the Gait Events
RHS = [];
LTO = [];
LHS = [];
RTO = [];
for i = 2:length(RF)
%Right Heel Strike
if RF(i,1) > Fthres && RF(i-1,1) < Fthres
RHS = [RHS;i];
end
%Left toe off
if LF(i,1) < Fthres && LF(i-1) > Fthres
LTO = [LTO;i];
end
%Left Heel Strike
if LF(i,1) > Fthres && LF(i-1,1) < Fthres
LHS = [LHS;i];
end
%Right toe off
if RF(i,1) < Fthres && RF(i-1,1) > Fthres
RTO = [RTO;i];
end
end
%% Organize into strides
GaitEvents = NaN(length(RHS)-1,5);
GaitEvents(:,1) = RHS(1:end-1);
GaitEvents(:,5) = RHS(2:end,:);
%Check to see if the stride is to long
for i = 1:length(GaitEvents)
if GaitEvents(i,5) - GaitEvents(i,1) > 2*TrialData.ForceData.Plate1.FrameRate
GaitEvents(i,1) = NaN;
end
end
%Add in the LTO
for i = 1:length(LTO)
for j = 1:length(GaitEvents(:,1))
if isnan(GaitEvents(j,1))
%Don't add an event
else
if LTO(i,1) > GaitEvents(j,1) && LTO(i,1) < GaitEvents(j,5)
GaitEvents(j,2) = LTO(i,1);
end
end
end
end
%Add in the LHS
for i = 1:length(LHS)
for j = 1:length(GaitEvents(:,1))
if isnan(GaitEvents(j,2))
%Don't add an event
else
if LHS(i,1) > GaitEvents(j,2) && LHS(i,1) < GaitEvents(j,5)
GaitEvents(j,3) = LHS(i,1);
end
end
end
end
%Add in the RTO
for i = 1:length(RTO)
for j = 1:length(GaitEvents(:,1))
if isnan(GaitEvents(j,3))
%Don't add an event
else
if RTO(i,1) > GaitEvents(j,3) && RTO(i,1) < GaitEvents(j,5)
GaitEvents(j,4) = RTO(i,1);
end
end
end
end
%% Eliminate the Gait Cycles that have NaN Value
TrialData.GaitEvents = [];
for i = 1:length(GaitEvents(:,1))
if isnan(mean(GaitEvents(i,:)))
%Do nothing
else
TrialData.GaitEvents = [TrialData.GaitEvents;GaitEvents(i,:)];
end
end
%% Optional Plotting
if pltflag == 1
figure;
subplot(2,1,1);
hold on;
plot(RF);
ylim([0 1000]);
for i = 1:length(TrialData.GaitEvents(:,1))
line([TrialData.GaitEvents(i,1) TrialData.GaitEvents(i,1)],[0 1000],'Color','r');
line([TrialData.GaitEvents(i,4) TrialData.GaitEvents(i,4)],[0 1000],'Color','k');
end
title('Right Foot');
hold off;
subplot(2,1,2);
hold on;
plot(LF);
ylim([0 1000]);
for i = 1:length(TrialData.GaitEvents(:,1))
line([TrialData.GaitEvents(i,2) TrialData.GaitEvents(i,2)],[0 1000],'Color','k');
line([TrialData.GaitEvents(i,3) TrialData.GaitEvents(i,3)],[0 1000],'Color','r');
end
title('Left Foot');
hold off;
end
end