-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTREATMILL_force_split_mot.asv
75 lines (71 loc) · 2.22 KB
/
TREATMILL_force_split_mot.asv
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
function [L, R]=TREATMILL_force_split_mot(path,OPTIONS)
[out] = ReadMotFile(path);
%% I assume that the first strike is gone be a right foot strike!
if OPTIONS.FP_used ==1
indexuse = 3;
forcevaluesindex = [2:10];
elseif OPTIONS.FP_used ==2
indexuse = 12;
forcevaluesindex = [11:18];
end
v = (out.data(:,indexuse)>OPTIONS.FP_Stance_Threshold);
streaks = [];
streak_indices = {};
current_streak = 0;
start_index = 0;
for i = 1:length(v)
if v(i) == 1
if current_streak == 0
start_index = i;
end
current_streak = current_streak + 1;
elseif current_streak > 0
streaks(end+1) = current_streak;
streak_indices{end+1}= start_index:(i-1);
current_streak = 0;
end
end
if current_streak > 0
streaks(end+1) = current_streak;
streak_indices{end+1}= start_index:(i-1);
end
odd_streak_indices = [];
for i = 1:2:numel(streak_indices)
odd_streak_indices = [odd_streak_indices streak_indices{i}];
end
even_streak_indices = [];
for d = 2:2:numel(streak_indices)
even_streak_indices = [even_streak_indices streak_indices{d}];
end
[b_filt,a_filt] = butter(2, 20/(OPTIONS.FREQ_ANALOG/2), 'low');
inforce_moments = [forcevaluesindex(1:3), [forcevaluesindex(end-2):forcevaluesindex(end)]];
for y = 1 : length (inforce_moments)
out.data(:,inforce_moments(y)) = filtfilt(b_filt,a_filt,out.data(:,inforce_moments(y)));
end
GRF1= out.data;
GRF1(odd_streak_indices',forcevaluesindex)= 0;
GRF2= out.data;
GRF2(even_streak_indices',forcevaluesindex)= 0;
vector = GRF1(:,3);
above_threshold = vector > OPTIONS.FP_Stance_Threshold;
diffs = [0; diff(above_threshold)];
starts = find(diffs == 1);
ends = find(diffs == -1);
use_stance = find(ends-starts(1:end-1)>100)
for u = 1 : length(use_stance)
% starts(use_stance(u))
% ends(use_stance(u))
V{1,u} = [starts(use_stance(u)):ends(use_stance(u))]
end
all = [1:length(GRF2(:,1))];
combines = [all'; cell2mat(V)']';
[vals,~,ic] = unique(combines);
counts = accumarray(ic,1);
dup_vals = vals(counts == 2);
combines(ismember(combines,dup_vals)) = [];
GRF1(combines,:) = 0;
L = [erase(path, '.mot'), '_LeftGroundContact.mot'];
R = [erase(path, '.mot'), '_RightGroundContact.mot'];
writeMot(GRF1(:,2:end),GRF1(:,1),L);
writeMot(GRF2(:,2:end),GRF2(:,1),R);
end