File size: 9,138 Bytes
b0cc889 |
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
%% Step 1 - load Flankers data from OCD II Study
clear all; clc
addpath('Y:\EEG_Data\Flankers OCDII\');
datalocation='Y:\EEG_Data\Flankers OCDII\Raw Data\'; % Data are here
savedir='Y:\EEG_Data\Flankers OCDII\Processed Data\'; % Save processed data here
appledir='Y:\EEG_Data\Flankers OCDII\Processed Data\APPLE Outputs\';
erpdir='Y:\EEG_Data\Flankers OCDII\Processed Data\ERPs\';
locpath=('Y:\Programs\eeglab12_0_2_1b\plugins\dipfit2.2\standard_BESA\standard-10-5-cap385.elp'); % Generic EEGlab locs
cd(datalocation);
% Data are 67 chans. 1:64 are EEG, incl. M1/2 and CB1/2. 65=HEOG 66=VEOG 67=EKG
FILZ=dir('*.cnt');
for si=[21,32,45] %1:length(FILZ)
subname=FILZ(si).name;
subno=str2num(subname(1:3));
% Load .cnt file and import channel locations
EEG = pop_loadcnt([datalocation,subname], 'dataformat', 'int32', 'keystroke', 'on');
% Get Locs
EEG = pop_chanedit(EEG, 'lookup', locpath);
EEG = eeg_checkset( EEG );
NUMSTIM=121:168;
for ai=1:length(NUMSTIM)
ALLSTIM{ai}=num2str(NUMSTIM(ai));
end
% Epoch
EEG = pop_epoch( EEG, ALLSTIM, [-2 2], 'newname', 'Epochs', 'epochinfo', 'yes');
EEG = eeg_checkset( EEG );
% Remove mean
EEG = pop_rmbase(EEG,[],[]);
% Extract peripherals
EEG.VEOG=squeeze(EEG.data(65,:,:)) ;
EEG.HEOG=squeeze(EEG.data(66,:,:)) ;
% EEG.EKG=squeeze(EEG.data(67,:,:)) ;
EEG.MASTOIDS=squeeze(mean(cat(1,EEG.data(33,:,:),EEG.data(43,:,:)),1));
% reref!
EEG = pop_reref(EEG,[find(strcmpi('M1',{EEG.chanlocs.labels})) find(strcmpi('M2',{EEG.chanlocs.labels}))]);
% Strip to 60: 33=M1, 43=M2, 60=CB1, 64=CB2, 65=HEOG, 66=VEOG
EEG = pop_select(EEG,'nochannel',[find(strcmpi('CB1',{EEG.chanlocs.labels})) find(strcmpi('CB2',{EEG.chanlocs.labels})) ...
find(strcmpi('HEOG',{EEG.chanlocs.labels})) find(strcmpi('EKG',{EEG.chanlocs.labels})) find(strcmpi('VEOG',{EEG.chanlocs.labels}))]);
CONGRU=[121, 124, 125, 128, 131, 134, 135, 138, 141, 144, 145, 148, 151, 154, 155, 158, 161, 164, 165, 168];
INCONGRU=[122, 123, 126, 127, 132, 133, 136, 137, 142, 143, 146, 147, 152, 153, 156, 157, 162, 163, 166, 167];
NeedLeft=[121,123,126,128,131,133,136,138,141,143,146,148,151,153,156,158,161,163,166,168];
NeedRight=[122,124,125,127,132,134,135,137,142,144,145,147,152,154,155,157,162,164,165,167];
% Get the good info out of the epochs
for ai=1:size(EEG.epoch,2)
EEG.epoch(ai).STIM=NaN; EEG.epoch(ai).CONGRU=NaN; EEG.epoch(ai).RightLeft=NaN;
EEG.epoch(ai).RT=NaN; EEG.epoch(ai).ACC=NaN; EEG.epoch(ai).BlockStart=0;
EEG.epoch(ai).TRIALNUM=NaN;
BEH_VECTOR(ai,1:8)=NaN;
for bi=1:size(EEG.epoch(ai).eventlatency,2)
% Get STIMTYPE
if EEG.epoch(ai).eventlatency{bi}==0 % If this bi is the event
EEG.epoch(ai).TRIALNUM=ai;
% ID what stimtype it was
temp=str2num(EEG.epoch(ai).eventtype{bi});
EEG.epoch(ai).STIM=temp;
% And if it was congruent (1) or conflict (0)
if any(temp==CONGRU)
EEG.epoch(ai).CONGRU=1;
elseif any(temp==INCONGRU);
EEG.epoch(ai).CONGRU=0;
end
clear temp;
% --- Now, find out what their next response was
if bi<size(EEG.epoch(ai).eventlatency,2) && length(EEG.epoch(ai).eventtype{bi+1})==7 % IF something is next && it was a response
if strmatch(EEG.epoch(ai).eventtype{bi+1}(1:6),'keypad') % another verification
% ID what stimtype it was [Right=1, Left=2]
EEG.epoch(ai).RightLeft=str2num(EEG.epoch(ai).eventtype{bi+1}(7));
% And what the RT was
EEG.epoch(ai).RT=EEG.epoch(ai).eventlatency{bi+1};
% And if it was correct
temp=str2num(EEG.epoch(ai).eventtype{bi+1}(7));
if any(EEG.epoch(ai).STIM==NeedRight)
if temp==1, EEG.epoch(ai).ACC=1;
elseif temp==2, EEG.epoch(ai).ACC=0;
end
elseif any(EEG.epoch(ai).STIM==NeedLeft);
if temp==2, EEG.epoch(ai).ACC=1;
elseif temp==1, EEG.epoch(ai).ACC=0;
end
end
clear temp
end
end
end
BEH_VECTOR(ai,1)=EEG.epoch(ai).TRIALNUM;
BEH_VECTOR(ai,2)=EEG.epoch(ai).STIM;
BEH_VECTOR(ai,3)=EEG.epoch(ai).CONGRU;
BEH_VECTOR(ai,4)=EEG.epoch(ai).RightLeft;
BEH_VECTOR(ai,5)=EEG.epoch(ai).RT;
BEH_VECTOR(ai,6)=EEG.epoch(ai).ACC;
end
% Determine beginning of new blocks
if ai==1, EEG.epoch(ai).BlockStart=1; toggle=1;
else
temp=num2str(EEG.epoch(ai).STIM); temp2=str2num(temp(3));
if temp2<5
newtoggle=1;
elseif temp2>4
newtoggle=2;
end
if newtoggle~=toggle
EEG.epoch(ai).BlockStart=1;
toggle=newtoggle;
end
clear temp temp2 newtoggle;
end
BEH_VECTOR(ai,7)=EEG.epoch(ai).BlockStart;
% Determine if pre or post error
if ai>1
EEG.epoch(ai).PREVTRIAL.TRIALNUM=EEG.epoch(ai-1).TRIALNUM;
EEG.epoch(ai).PREVTRIAL.STIM=EEG.epoch(ai-1).STIM;
EEG.epoch(ai).PREVTRIAL.CONGRU=EEG.epoch(ai-1).CONGRU;
EEG.epoch(ai).PREVTRIAL.RightLeft=EEG.epoch(ai-1).RightLeft;
EEG.epoch(ai).PREVTRIAL.RT=EEG.epoch(ai-1).RT;
EEG.epoch(ai).PREVTRIAL.ACC=EEG.epoch(ai-1).ACC;
EEG.epoch(ai).PREVTRIAL.BlockStart=EEG.epoch(ai-1).BlockStart;
end
end
% ----------------------
% Setup APPLE to interp chans, reject epochs, & ID bad ICs. Output will be Avg ref'd and ICA'd.
eeg_chans=1:60;
Do_ICA=1;
ref_chan=19; % Re-Ref to FCz [WEIRD STEP, BUT THIS IS FOR FASTER, which is a part of APPLE]
% % EEG = pop_reref(EEG,ref_chan,'keepref','on');
% Run APPLE
[EEG,EEG.bad_chans,EEG.bad_epochs,EEG.bad_ICAs]=APPLE_OCDII(EEG,eeg_chans,ref_chan,Do_ICA,subno,EEG.VEOG,appledir);
% Save
save([savedir,num2str(subno),'_FLANKERS.mat'],'EEG');
save([savedir,num2str(subno),'_BEH_VECTOR.mat'],'BEH_VECTOR');
% Let's just do this for display
dims=size(EEG.data);
EEG.data=eegfilt(EEG.data,500,[],20);
EEG.data=reshape(EEG.data,dims(1),dims(2),dims(3));
% Set Params
tx=-2000:2:1998;
b1=find(tx==-200); b2=find(tx==0);
t1=find(tx==-500); t2=find(tx==1000);
N2topo1=find(tx==200); N2topo2=find(tx==350); N2toporangetot=200:2:350;
P3topo1=find(tx==400); P3topo2=find(tx==600); P3toporangetot=400:2:600;
tx2disp=-500:2:1000;
% Basecor your ERPs here so they are pretty.
BASE=squeeze( mean(EEG.data(:,b1:b2,:),2) );
for ai=1:dims(1)
EEG.data(ai,:,:)=squeeze(EEG.data(ai,:,:))-repmat( BASE(ai,:),dims(2),1 );
end
% --------------
for ai=1:length(EEG.epoch)
CONDIS(ai)=EEG.epoch(ai).CONGRU;
end
% ------------------
figure;
subplot(2,4,1:3); hold on
site=19; % FCz
ERP4topo=mean(EEG.data(site,N2topo1:N2topo2,:),3);
topomax_N2=N2toporangetot(find(ERP4topo==min(ERP4topo)));
topotoplot_N2=find(tx==topomax_N2);
plot(tx2disp,mean(EEG.data(site,t1:t2,CONDIS==1),3),'b');
plot(tx2disp,mean(EEG.data(site,t1:t2,CONDIS==0),3),'r');
plot([topomax_N2 topomax_N2],[-4 4],'m');
title(['FCz Subno: ',num2str(subno)]);
subplot(2,4,4); hold on
TOPLOT=mean(EEG.data(:,topotoplot_N2,CONDIS==0),3) - mean(EEG.data(:,topotoplot_N2,CONDIS==1),3);
topoplot( TOPLOT, EEG.chanlocs); cbar
% ------------------
subplot(2,4,5:7); hold on
site=46; % Pz
ERP4topo=mean(EEG.data(site,P3topo1:P3topo2,:),3);
topomax_P3=P3toporangetot(find(ERP4topo==max(ERP4topo)));
topotoplot_P3=find(tx==topomax_P3);
plot(tx2disp,mean(EEG.data(site,t1:t2,CONDIS==1),3),'b');
plot(tx2disp,mean(EEG.data(site,t1:t2,CONDIS==0),3),'r');
plot([topomax_P3 topomax_P3],[-4 4],'m');
title(['Pz Subno: ',num2str(subno)]);
subplot(2,4,8); hold on
TOPLOT=mean(EEG.data(:,topotoplot_P3,CONDIS==0),3) - mean(EEG.data(:,topotoplot_P3,CONDIS==1),3);
topoplot( TOPLOT, EEG.chanlocs); cbar
saveas(gcf, [erpdir,num2str(subno),'_ERPs.png'],'png');
close all;
clear BEH_VECTOR EEG ai bi subno toggle CONDIS TOPLOT topomax_P3 topotoplot_P3 topomax_N2 topotoplot_N2 ERP4topo;
end
% ----------------------
%%
|