-
Notifications
You must be signed in to change notification settings - Fork 2
/
segSignals.m
37 lines (26 loc) · 962 Bytes
/
segSignals.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
function [signalsOut, labelsOut] = segSignals(signalsIn,labelsIn,targetLength,channels)
signalsOut = {};
labelsOut = {};
for idx_ch = channels
for idx = 1:numel(signalsIn)
x = signalsIn{idx};
y = labelsIn(idx);
% Column to vector conversion
x = x(idx_ch,:)';
% Calculate the number of targetLength samples in the signal
numSigs = floor(length(x)/targetLength);
if numSigs == 0
continue;
end
x = x(1:numSigs*targetLength);
% Create a matrix of as many columns as there are targetLength signals
M = reshape(x,targetLength,numSigs);
% Repeat the numSigs tag
y = repmat(y,[numSigs,1]);
% Vertically spliced into cell arrays
signalsOut = [signalsOut; mat2cell(M.',ones(numSigs,1))];
labelsOut = [labelsOut; cellstr(y)];
end
end
labelsOut = categorical(labelsOut);
end