-
Notifications
You must be signed in to change notification settings - Fork 0
/
readepochs.m
116 lines (78 loc) · 2.72 KB
/
readepochs.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
function [data,ctf] = readepochs(folder,varargin);
%
%
%
% <>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% < >
% < DISCLAIMER: >
% < >
% < THIS PROGRAM IS INTENDED FOR RESEARCH PURPOSES ONLY. >
% < THIS PROGRAM IS IN NO WAY INTENDED FOR CLINICAL OR >
% < OFFICIAL USE. >
% < >
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>
%
% function to read set time windows (epochs) around event markers.
%
[marker_info] = readmarkerfile(folder);
ctf = ctf_read_res4(folder,1);
CHAN = ctf.sensor.index.megsens;
trials = [1:ctf.setup.number_trials];
win = 'alltimes';
for i = 1:size(varargin,2)
if ~iscell(varargin{i})
switch num2str(varargin{i})
case 'megsens',
CHAN = ctf.sensor.index.megsens(varargin{i+1});
case 'refsens',
CHAN = ctf.sensor.index.refsens(varargin{i+1});
case 'eegsens',
CHAN = ctf.sensor.index.eegsens(varargin{i+1});
case 'othersens',
CHAN = ctf.sensor.index.othersens(varargin{i+1});
case 'vc',
CHAN = ctf.sensor.index.vc(varargin{i+1});
case 'allchans',
CHAN = [1:ctf.setup.number_channels];
case 'trials',
trials = varargin{i+1};
case 'markers',
marks = varargin{i+1};
case 'window',
win = varargin{i+1};
end
end
end
if ~exist('marks','var'),
ctf = ctf_read_meg4(folder,ctf,CHAN,win,trials);
epochs = cell(1,1);
epochs{1} = zeros(size(ctf.data{1},1),size(ctf.data{1},2),size(ctf.data,1));
for i = 1:size(ctf.data,1),
epochs{1}(:,:,i) = ctf.data{i};
end
else
nm = size(marks,2);
epochs = cell(1,nm);
for mkr = 1:nm,
mk=ismember(marker_info.marker_names,marks(mkr));
marker_info.marker_names(mk);
nsamp=marker_info.number_samples(mk)
nss=0;
for ns=1:nsamp
tr = marker_info.trial_times{mk}(ns,1);
if ismember(tr,trials)
nss=nss+1;
tim=marker_info.trial_times{mk}(ns,2);
times=win+tim;
ctf = ctf_read_ds(folder,ctf,CHAN,times,tr);
temp=ctf.data{1};
if nss==1,
epochs{mkr}=zeros(size(temp,1),size(temp,2),1);
end
epochs{mkr}(:,:,nss)=temp;
end
end
end
end
data = struct('epochs',{epochs},'setup',{ctf.setup},'sensor',{ctf.sensor});
return