-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelSeg.m
140 lines (116 loc) · 3.43 KB
/
velSeg.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
function [] = velSeg(subjectId)
fileDir=['O',num2str(subjectId),'_out\'];
load([fileDir,'vel_imu.mat'])
oxyFile=['O',num2str(subjectId),'_output_smooth.csv'];
oxygen=csvread(oxyFile);
windowStart = 1;
windowEnd = length(V_d);
Fs = 400;
vertVel = V_d(1, windowStart:windowEnd);
vertVel_d = detrend(vertVel);
maxV = max(vertVel_d);
thresh = 0.05 * maxV;
a = false;
b = false;
front = 0;
back = 0;
while (true)
if (abs(vertVel_d(1, 1)) > thresh || vertVel_d(1, 1) > vertVel_d(1, 2))
vertVel_d = vertVel_d(1, 3:end);
vertVel_d = detrend(vertVel_d);
front = front + 2;
a = false;
else
a = true;
end
if (vertVel_d(1, end) > thresh || vertVel_d(1, 1) > vertVel_d(1, 2))
vertVel_d = vertVel_d(1, 1:end - 3);
vertVel_d = detrend(vertVel_d);
back = back + 3;
a = false;
b = false;
else
b = true;
end
if (a && b)
break;
end
end
v_lon = V_lon(1, windowStart + front:windowEnd - back);
v_d = V_d(1, windowStart + front:windowEnd - back);
%%v_e = V_e(1, windowStart + front:windowEnd - back);
%%v_n = V_n(1, windowStart + front:windowEnd - back);
%%a_d = acc_d(1, windowStart + front:windowEnd - back);
%%a_lon = A_lon(1, windowStart + front:windowEnd - back);
%% Calculating steps
steps = [];
if (vertVel_d(1, 1) > 0)
steps = 1;
end
for i = 1:length(vertVel_d) - 1
if (vertVel_d(1, i) < 0 && vertVel_d(1, i + 1) > 0)
steps = [steps, i];
end
end
disp('Length Steps');
length(steps);
stepCount = length(steps) - 1;
%%
stepDuration = [];
stepLength = [];
vertOscillation_vel_amp = [];
vertOscillation_dist_amp = [];
speed = [];
speedChange = [];
stepVels_d_aray=[];
oxyTest=[];
disp('v_lon')
length(v_lon)
for i = 1:stepCount
stepDuration = [stepDuration, (steps(i + 1) - steps(i))/Fs];
stepVelsLon = v_lon(steps(i):steps(i + 1));
stepVels_d = v_d(steps(i):steps(i + 1));
stepLength = [stepLength, trapz(stepVelsLon./Fs)];% step displacement longitudinal in a step
vertOscillation_vel_amp = [vertOscillation_vel_amp, ...
((max(stepVels_d)) + (min(stepVels_d)))/2];
for j=steps(i):1:(steps(i+1)-1)
v_d(j)=v_d(j)-vertOscillation_vel_amp(i);
end
stepVels_d = v_d(steps(i):steps(i + 1));
stepDispDown = cumtrapz(stepVels_d./Fs); %step displacement downwards in a step
stepVels_d_aray=[stepVels_d_aray,stepDispDown];
vertOscillation_dist_amp = [vertOscillation_dist_amp, ...
(abs(max(stepDispDown)) + abs(min(stepDispDown)))/2];
speed = [speed, mean(stepVelsLon)];
speedChange = [speedChange, max(stepVelsLon) - min(stepVelsLon)];
time(i)=steps(i)/400;
j_ = floor(time(i)/5)+1;
oxyTest = [oxyTest, oxygen(j_)];
end
%
% nCut=4667;
% rat=nCut/length(speed);
% figure;
% plot(speed);
% n = ceil(numel(speed)*rat);
%
% B=speed(1:n);
% C=speed(n+1:end);
%figure
%plot(B)
%figure
%plot(C)
%figure
%plot(speedChange)
%figure
%plot(stepDuration)
%figure
%plot(vertOscillation_dist_amp)
%figure
%plot(oxyTest)
resultTest=[speed;speedChange;stepDuration;vertOscillation_dist_amp;oxyTest];
fileName=['velSeg_O',num2str(subjectId),'_out.mat']
save(fileName,'steps', 'speed', 'speedChange', 'stepDuration', 'vertOscillation_dist_amp', 'oxyTest')
end
% resultWalk=resultTest(:,1:n);
% resultRun=resultTest(:,n+1:end);