-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctf_jtfa_comp.m
163 lines (131 loc) · 5.21 KB
/
ctf_jtfa_comp.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
158
159
160
161
162
163
% ctfcomp
% EEGLAB script for joint time-frequency analysis for MEG data
% Reads one channel at a time to minimize memory requirements
% Saves all single-channel ERSP figures including ITC
% Saves all numerical results in .mat file
% Thomas Ferree @ UCSF
% Revised 2/16/2004
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
% set machine: 1 = TiBoard, 2 = Glutamate/Acetylcholine/Brainmap, Corby
machine = 3;
% set CTF parameters
ctftrials = 'all';
%ctftrials = [1:10];
ctftime = 'all';
% set JTFA parameters
winsize = 128; % time window width (->256, Scott 4/21/2004)
padratio = 4; % frequency resolution (->2?, Scott 4/21/2004)
bootalpha = 0.05; % two-tailed p-value
bootnaccu = 2000; % 200-20000
% user-defined paths
if machine == 1
pathdata = '/Users/tferree/Documents/Data/Attention/HighN/';
pathtemp = '/Users/tferree/Documents/Research/Attention/HighN/Temp/';
end
if machine >= 2
addpath /home/tferree/EEGLAB42/;
addpath /home/tferree/Attention/HighN/ctf2eeglab/;
pathdata = '/home/cdale/HighN/';
end
if machine == 2
pathtemp = '/home/tferree/Attention/HighN/Temp/';
elseif machine == 3
pathtemp = '/home/cdale/Temp/';
end
% toggle saving eeglab .set, 0 = no, 1 = yes
saveSet = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%subject = 'HM'
%date = '20040126';
%subject = 'GN'
%date = '20040109';
subject = 'CJ'
date = '20040116';
% loop on cues
for icue = 1:2
% define cue condition
if icue == 1
cue = 'CueL'
else icue == 2
cue = 'CueR'
end
% loop on channels
for ichan = 1:275
% initialize data vector
datavector = [];
ntrials = 0;
% loop over four targets with correct response + one for concatination
for itarget = 1:4
% define target condition
if itarget == 1
target = 'InvNT'
elseif itarget == 2
target = 'InvTarg'
elseif itarget == 3
target = 'ValNT'
elseif itarget == 4
target = 'ValTarg'
else
error('Invalid index for target condition.')
end
% create output folders
if ~exist([pathtemp 'ERSP_' subject(1:2) '_' cue])
mkdir(pathtemp,['ERSP_' subject(1:2) '_' cue]);
end
% if ~exist([pathtemp subject(1:2) '_' cue filesep 'ERP'])
% mkdir(pathtemp, [subject(1:2) '_' cue filesep 'ERP']);
% end
%
% if ~exist([pathtemp subject(1:2) '_' cue filesep 'JTF'])
% mkdir(pathtemp, [subject(1:2) '_' cue filesep 'JTF']);
% end
% load CTF data
ctffolder = [pathdata subject '_epoch' filesep 'processed' filesep subject '_DNL_' date '_HiN_' cue target '-fEOG.ds'];
ctf = ctf_read_res4(ctffolder);
ctfchannels = ctf.sensor.index.meg;
ctf = ctf_read(ctffolder,ctfchannels(ichan),ctftime,ctftrials);
ctf2eeglab;
% concatinate trials over target conditions
ntrials = ntrials + EEG.trials;
for trial = 1:EEG.trials
datavector = [datavector EEG.data(1,:,trial)];
end
end % end loop over targets
% scale data upward to order unity
datavector = datavector * 10^12;
% channel string for saving figures to files with sequential file names
if ichan < 10
chanstring = ['00' num2str(ichan)];
end
if ichan > 9 & ichan < 100
chanstring = ['0' num2str(ichan)];
end
if ichan > 99
chanstring = num2str(ichan);
end
% % make single-channel ERP image
% h1 = figure(1000+ichan);
% avewidth = 1;
% decimate = 1;
% pop_erpimage(EEG,1, [ichan],[],['Channel ' num2str(ichan)],avewidth,decimate,{},[],'' ,'erp','cbar','yerplabel','pT');
% saveas(h1,[pathtemp subject '_' cue filesep 'Ch' chanstring '.jpg'],'jpg');
% close(h1);
% make single-channel JTF image
h2 = figure(2000+ichan);
%[ersp,itc,powbase,times,freqs,erspboot,itcboot] = pop_timef( EEG, 1, ichan, [-1200 2000], 0 ,'type', 'phasecoher','baseline',-300, 'title',['Channel ' num2str(ichan)],'padratio', padratio, 'plotphase', 'off','winsize',winsize,'alpha',bootalpha,'naccu',bootnaccu);
[ersp,itc,powbase,times,freqs,erspboot,itcboot] = timef(datavector, EEG.pnts, [-1200 2000], EEG.srate, 0,'type', 'phasecoher','baseline',-300, 'title',['Channel ' num2str(ichan)],'padratio', padratio, 'plotphase', 'off','winsize',winsize,'alpha',bootalpha,'naccu',bootnaccu);
saveas(h2,[pathtemp 'ERSP_' subject '_' cue filesep 'Ch' chanstring '.jpg'],'jpg');
close(h2);
% store all timef results in 'all' arrays, referring to all channels
allersp(:,:,ichan) = ersp;
allitc(:,:,ichan) = itc;
allpowbase(:,:,ichan) = powbase;
alltimes(:,:,ichan) = times;
allfreqs(:,:,ichan) = freqs;
allerspboot(:,:,ichan) = erspboot;
allitcboot(:,:,ichan) = itcboot;
end % end loop over channels
folderpath = [pathtemp 'ERSP_' subject '_' cue '.mat'];
save(folderpath,'allersp','allitc','allpowbase','alltimes','allfreqs','allerspboot','allitcboot','ntrials');
end % end loop over cues