forked from davidjuliancaldwell/touchProbeValidation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEpochSignal.m
More file actions
66 lines (61 loc) · 1.92 KB
/
Copy pathgetEpochSignal.m
File metadata and controls
66 lines (61 loc) · 1.92 KB
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
%% getEpochSignal.m
% jdw - 19JUN2011
%
% Changelog:
% 19JUN2011 - originally written
% 11NOV2013 - added cell functionality
%
% This function breaks signal in to epoch based chunks as specified by
% starts and ends.
%
% Parameters:
% signal - a vector length M containing the signal to break in to epochs.
% starts - a vector containing the start offsets of each epoch
% ends - a vector containing the end offsets of each epoch
%
% Return Values:
% epochSignal - a matrix containing the signal, divided in to epochs.
% OR
% epochSignal - a cell array containing the signal, divided in to epochs.
%
% in the case that all of the epochs are not of equal length, this function
% will return a cell array as opposed to a matrix.
%
function epochSignal = getEpochSignal(signal, starts, ends)
% if (size(signal,2) ~= 1)
% warning('2(+)-D matrix passed for signal, ignoring all but first column');
% while (size(signal, 2) ~= 1)
% signal = squeeze(signal(:, 1));
% end
% end
if(length(starts) ~= length(ends))
error('starts and ends must be of same length');
end
if (max(ends-starts) ~= min(ends-starts))
returnMatrix = false;
else
returnMatrix = true;
end
if (isempty(starts))
if (returnMatrix == true)
epochSignal = [];
else
epochSignal = {};
end
return;
end
if (returnMatrix == true)
epochSignal = zeros(ends(1)-starts(1), size(signal,2), length(starts));
else
epochSignal = cell(size(signal, 2), length(starts));
end
for c = 1:length(starts)
if (returnMatrix == true)
epochSignal(:,:,c) = signal(starts(c):ends(c)-1,:);
else
for chan = 1:size(signal, 2)
epochSignal{chan, c} = signal(starts(c):ends(c)-1, chan);
end; clear chan;
end
end; clear c;
end