-
Notifications
You must be signed in to change notification settings - Fork 3
/
dics_grandaverage.m
108 lines (86 loc) · 4.09 KB
/
dics_grandaverage.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
function [] = dics_grandaverage(sessions, vs)
% select subsets of trials that we'll look at and compare,
if ~exist('sessions', 'var'), sessions = 1:2; end
if ischar(sessions), sessions = str2double(sessions); end
freqs = dics_freqbands; % retrieve specifications
if ~exist('vs', 'var'), vs = 1:length(freqs); end
if ischar(vs), vs = str2double(vs); end
% define subjects
sjdat = subjectspecifics('GA');
subjects = sjdat.clean;
percchange = @(pow, bl) 100 .* (pow - bl) ./ bl;
% ==================================================================
% GRAND AVERAGE
% ==================================================================
for session = sessions,
for v = vs,
% ==================================================================
% GATHER AND BASELINE CORRECT
% ==================================================================
clear source
for sj = subjects,
subjectdata = subjectspecifics(sj);
file = sprintf('%s/P%02d-S%d_parcel_%s.mat', ...
subjectdata.roidir, sj, session, freqs(v).name);
if exist(file, 'file'),
load(file); disp(file);
% DO BASELINE CORRECTION WITHIN EACH REGION AND PARTICIPANT
% CONVERT TO PERCENT SIGNAL CHANGE
catbl = squeeze(mean(mean(parcel.pow(:, :, 5:10), 2), 3));
parcel.pow = bsxfun(percchange, parcel.pow, catbl);
% MANUALLY APPEND
if ~exist('source', 'var'),
source = parcel;
else
source.pow = cat(2, source.pow, parcel.pow);
source.trialinfo = cat(1, source.trialinfo, parcel.trialinfo);
end
end
end
% ==================================================================
% FOR MOTOR REGIONS, COMPUTE LATERALIZATION
% after baseline correction
% ==================================================================
regions = source.label;
left_regions = regions(~cellfun('isempty', regexp(regions, 'left', 'match')));
right_regions = regexprep(left_regions, 'left', 'right');
lateralization = regexprep(left_regions, 'left', 'lateralized');
disp('Computing lateralisation for motor regions...');
for r = 1:length(left_regions),
source.label(end+1) = lateralization(r);
leftidx = find(~cellfun(@isempty, regexp(regions, left_regions{r})));
rightidx = find(~cellfun(@isempty, regexp(regions, right_regions{r})));
source.pow(end+1, :, :) = source.pow(leftidx, :, :) - source.pow(rightidx, :, :);
end
% reshape the dims to be easier to work with
tic;
savefast(sprintf('%s/GA-S%d_parcel_%s.mat', sjdat.roidir, ...
session, freqs(v).name), 'source');
toc;
% ==================================================================
% REDO WITHOUT BASELINE CORRECTION
% ==================================================================
clear source
for sj = subjects,
subjectdata = subjectspecifics(sj);
file = sprintf('%s/P%02d-S%d_parcel_%s.mat', ...
subjectdata.roidir, sj, session, freqs(v).name);
if exist(file, 'file'),
load(file); disp(file);
% MANUALLY APPEND
if ~exist('source', 'var'),
source = parcel;
else
source.pow = cat(2, source.pow, parcel.pow);
source.trialinfo = cat(1, source.trialinfo, parcel.trialinfo);
end
end
end
% reshape the dims to be easier to work with
tic;
savefast(sprintf('%s/GA-S%d_parcel_noblcorr_%s.mat', sjdat.roidir, ...
session, freqs(v).name), 'source');
toc;
end
end
end