%% 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 bi4 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 % ---------------------- %%