%% Step1: PreProcess CC Task clear; clc; close all; addpath('D:\Project_EEG_CC\CC_PD_Figures_Manuscript\CC_Manuscript\Manuscript_Scripts_PREDICT\Data\'); datalocation=('D:\Project_EEG_CC\CC_PD_Figures_Manuscript\CC_Manuscript\Manuscript_Scripts_PREDICT\Data\'); savedire = ('D:\Project_EEG_CC\CC_PD_Figures_Manuscript\CC_Manuscript\Manuscript_Scripts_PREDICT\Data\'); cd(datalocation); PDsx=[801:811,813:829]; % 824 S2 is bad EEG! CTLsx=[8010,8070,8060,890:914]; %% ########################## TRN = training; TST = testing; FB = Reward and punishment for subj=[PDsx,CTLsx] for session=1:2 if (subj>850 && session==1) || subj<850 % If not ctl, do session 2 if exist([num2str(subj),'_Session_',num2str(session),'_PDDys_CC.mat'])~=2 disp(['Do CC --- Subno: ',num2str(subj),' Session: ',num2str(session)]); disp(' '); TRN_STIM={'S111','S112','S113','S114','S121','S122','S123','S124','S211','S212','S213','S214','S221','S222','S223','S224'}; TRN_RESP={'S101','S102','S103','S104'}; TRN_FB={'S 8','S 9'}; TST_STIM={'S 12','S 13','S 14','S 21','S 23','S 24','S 31','S 32','S 34','S 41','S 42','S 43'}; TST_RESP={'S 1','S 2','S 3','S 4'}; All_STIM={'S111','S112','S113','S114','S121','S122','S123','S124','S211','S212','S213','S214','S221','S222','S223','S224','S 8','S 9'... 'S 12','S 13','S 14','S 21','S 23','S 24','S 31','S 32','S 34','S 41','S 42','S 43'}; % Data are 68 chans: 1=63 is EEG, 64 is VEOG, 66-68 is XYZ. Ref'd to CPz - - will want to retrieve that during re-referencing % Load BrainVision data EEG = pop_loadbv(datalocation,[num2str(subj),'_',num2str(session),'_CC.vhdr']); % Get Locs locpath= ('D:\Matlab_Files\Matlab_toolbox\eeglab_current\eeglab14_1_1b\plugins\dipfit2.3\standard_BESA\standard-10-5-cap385.elp'); EEG = pop_chanedit(EEG, 'lookup', locpath); EEG = eeg_checkset( EEG ); %% get the epoch information from EEG.event % Get event types for ai=2:length(EEG.event); temp=EEG.event(ai).type; TYPES(ai)=str2num(temp(2:end)) ; clear temp; end UNIQUE_TYPES=unique(TYPES); for ai=1:length(UNIQUE_TYPES); UNIQUE_TYPES_COUNT(ai)=sum(TYPES==UNIQUE_TYPES(ai)); end clc; TRIGGERS=[UNIQUE_TYPES;UNIQUE_TYPES_COUNT]; % Trigger type, Frequency % Epoch ---To TRN stim, TRN FB, and TST stim..NO RESPONSE EEG = pop_epoch( EEG, All_STIM, [-1.5 5], 'newname', 'Epochs', 'epochinfo', 'yes'); EEG = eeg_checkset( EEG ); % Remove X,Y,Z & VEOG EEG.VEOG=squeeze(EEG.data(64,:,:)); EEG.X=squeeze(EEG.data(65,:,:)); EEG.Y=squeeze(EEG.data(66,:,:)); EEG.Z=squeeze(EEG.data(67,:,:)); EEG.data=EEG.data(1:63,:,:); EEG.nbchan=63; EEG.chanlocs(67)=[]; EEG.chanlocs(66)=[]; EEG.chanlocs(65)=[]; EEG.chanlocs(64)=[]; % Fix BV-specific issue - - - only needed for APPLE for ai=1:size(EEG.urevent,2), EEG.urevent(ai).bvtime=EEG.urevent(ai).bvmknum; end for ai=1:size(EEG.event,2), EEG.event(ai).bvtime=EEG.event(ai).bvmknum; end for ai=1:size(EEG.epoch,2), EEG.epoch(ai).eventbvtime=EEG.epoch(ai).eventbvmknum; end % Add CPz EEG = pop_chanedit(EEG,'append',63,'changefield',{64 'labels' 'CPz'}); EEG = pop_chanedit(EEG,'lookup', locpath); % Re-Ref to Average Ref and recover CPz EEG = pop_reref(EEG,[],'refloc',struct('labels',{'CPz'},'type',{''},'theta',{180},'radius',{0.12662},'X',{-32.9279},'Y',{-4.0325e-15},'Z',{78.363},... 'sph_theta',{-180},'sph_phi',{67.208},'sph_radius',{85},'urchan',{64},'ref',{''}),'keepref','on'); % Remove everything else NOW that CPz has been reconstructed from the total EEG.MASTOIDS = squeeze(mean(EEG.data([10,21],:,:),1)); EEG.data = EEG.data([1:4,6:9,11:20,22:26,28:64],:,:); EEG.nbchan=60; EEG.chanlocs(27)=[]; EEG.chanlocs(21)=[]; EEG.chanlocs(10)=[]; EEG.chanlocs(5)=[]; % Have to be in this order! % Should probably re-ref to average again now that the contaminated channels are gone EEG = pop_reref(EEG,[]); % Remove mean EEG = pop_rmbase(EEG,[],[]); %%%%%%%%%%%%%%%%%%%%%%% ---------------------- % Setup APPLE to interp chans, reject epochs, & ID bad ICs. Output will be Avg ref'd and ICA'd. TASK='CC'; eeg_chans=1:60; Do_ICA=1; ref_chan=36; % 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 (will re-ref data to avg ref) [EEG,bad_chans,bad_epochs,bad_ICAs]=APPLE_PDDys_CC(EEG,eeg_chans,ref_chan,Do_ICA,subj,EEG.VEOG,session,TASK); % Save save([savedire,num2str(subj),'_Session_',num2str(session),'_PDDys_CC.mat'],'EEG','bad_chans','bad_epochs','bad_ICAs'); % ----------------------------------------------------------------- clearvars -except subj session datalocation; end end end end