-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFeatureMatrix2.m
157 lines (138 loc) · 6.94 KB
/
createFeatureMatrix2.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
function [feature_matrix] = createFeatureMatrix2(strideList, strideListOther, prediction_signals, w_start, w_end, two_feet, cnn)
POST_SWING_CUTOFF_SAMPLES = 15;
if two_feet
lenStrideList = min(length(strideList), length(strideListOther));
else
lenStrideList = length(strideList);
end
% lab_foot = labels_train([strideList.globalInitStanceSample]);
% disp('Extracting predictor features...');
nOutputSignals = numel(prediction_signals)*(two_feet+1);
means = zeros(lenStrideList, numel(prediction_signals)*(two_feet+1));
maxs = means;
mins = means;
ranges = means;
jrange = 1:(two_feet+1):nOutputSignals;
start = 1;
% handles.axes1 = axes;
% set(handles.axes1, 'NextPlot', 'add');
lone_sig = [];
data = [];
for i=1:lenStrideList
% window_start = strideList(i).globalFootStaticSample - strideList(i).globalInitStanceSample + 1;
% window_end = strideList(i).globalInitSwingSample - strideList(i).globalInitStanceSample + POST_SWING_CUTOFF_SAMPLES;
iter = 1;
lsend = start + length(strideList(i).(prediction_signals{1}));
% lsend = start + 10*length(strideList(i).(prediction_signals{1}));
% N = length(strideList(i).(prediction_signals{1}));
% timepts = linspace(start,lsend,N-1);
% timepts = ttot(start:lsend-1);
% labs = labels_train(start:lsend-1);
start = lsend(end);
lone_iter = 1;
delj = [];
for jj=1:length(jrange)
j = jrange(jj);
cycle_time = length(strideList(i).(prediction_signals{iter}));
if cycle_time == 1
lone_sig(i,lone_iter) = strideList(i).(prediction_signals{iter});
lone_iter = lone_iter+1;
delj = [delj, j];
else
% start after planatar flexion
% window_start = 1;
% window_end = round(.6*cycle_time - POST_SWING_CUTOFF_SAMPLES);
window_start = round(w_start*cycle_time);
window_end = round(w_end*cycle_time);
% window_end = window_start + 10;
% window_end = cycle_time;
% window_start = strideList(i).globalFootStaticSample - strideList(i).globalInitStanceSample + 1;
% if i < lenStrideList
% window_end = strideList(i+1).globalInitSwingSample - strideList(i).globalInitStanceSample + POST_SWING_CUTOFF_SAMPLES;
% else
% window_end = size(data_train, 1);
% end
if cnn
sig1 = strideList(i).(prediction_signals{iter})(window_start:window_end);
data{i}(:,j,1) = sig1';
% data(:,j,1,i) = strideList(i).(prediction_signals{iter})(window_start:window_end);
end
means(i,j) = mean(strideList(i).(prediction_signals{iter})(window_start:window_end));
maxs(i,j) = max(strideList(i).(prediction_signals{iter})(window_start:window_end));
mins(i,j) = min(strideList(i).(prediction_signals{iter})(window_start:window_end));
ranges(i,j) = range(strideList(i).(prediction_signals{iter})(window_start:window_end));
end
% if plot_pts
% figure(iter);
% hold on;
% plot(timepts,strideList(i).(prediction_signals{iter}),gp_mat{mode(labs(labs>0))})
% hold on;
% ax = gca;
% line([ttot(strideList(i).globalInitStanceSample) ...
% ttot(strideList(i).globalInitStanceSample)],get(ax,'YLim'),...
% 'Color',[1 0 0]);
% % line([ttot(strideList(i).globalFootStaticSample) ...
% % ttot(strideList(i).globalFootStaticSample)],get(ax,'YLim'),...
% % 'Color',[0 1 0]);
% % line([ttot(strideList(i).globalInitSwingSample) ...
% % ttot(strideList(i).globalInitSwingSample)],get(ax,'YLim'),...
% % 'Color',[0 0 1]);
%
% if i == lenStrideList
% legend('Strides','InitStance','Static','InitSwing');
% end
% end
% handles.handle_plotCD(i) = plot(timepts,...
% strideList(i).(prediction_signals{iter}),'parent',handles.axes1);
% if i == 1
% title(prediction_signals{iter})
% end
% hold off;
if two_feet
cycle_time = length(strideListOther(i).(prediction_signals{iter}));
% start after planatar flexion
% Start and second foot SWING
window_start = round((w_start - .5)*cycle_time);
% window_end = round(.6*cycle_time - POST_SWING_CUTOFF_SAMPLES);
% window_start = round(.6*cycle_time);
% window_end = window_start + 10;
window_end = round((w_end-.5)*cycle_time);
% window_end = cycle_time;
% window_start = strideListOther(i).globalFootStaticSample - strideListOther(i).globalInitStanceSample + 1;
% window_end = strideListOther(i).globalInitSwingSample - strideListOther(i).globalInitStanceSample + POST_SWING_CUTOFF_SAMPLES;
if cycle_time == 1
lone_sig(i,lone_iter) = strideListOther(i).(prediction_signals{iter});
lone_iter = lone_iter+1;
delj = [delj, j];
else
if cnn
sig2 = strideListOther(i).(prediction_signals{iter})(window_start:window_end);
sig2 = sig2(1:length(sig1));
data{i}(:,j+1,1) = sig2;
% data(:,j,1,i) = strideList(i).(prediction_signals{iter})(window_start:window_end);
end
means(i,j+1) = mean(strideListOther(i).(prediction_signals{iter})(window_start:window_end));
maxs(i,j+1) = max(strideListOther(i).(prediction_signals{iter})(window_start:window_end));
mins(i,j+1) = min(strideListOther(i).(prediction_signals{iter})(window_start:window_end));
ranges(i,j+1) = range(strideListOther(i).(prediction_signals{iter})(window_start:window_end));
end
end
iter = iter+1;
end
end
maxs(:,delj)=[]; mins(:,delj) = []; ranges(:,delj) = [];
if ~cnn
feature_matrix = [maxs, mins, ranges, lone_sig];
elseif cnn
feature_matrix = data;
end
% feature_matrix = [maxs(:,1:end-size(lone_sig,2)), mins(:,1:end-size(lone_sig,2)), ...
% ranges(:,1:end-size(lone_sig,2)), lone_sig];
% if size(feature_matrix,2)>30
% x = 'debug';
% end
% rperm = randperm(lenStrideList);
% randomized_feature_matrix = feature_matrix(rperm,:);
%
% labels_in = lab_foot(rperm);
end