%% PD Rest startup clear all; clc addpath('Y:\EEG_Data\PDDys\EEG\PD REST Scripts'); datalocation='Y:\EEG_Data\PDDys\EEG\Raw EEG Data\'; % Data are here cd(datalocation); savedir='Y:\EEG_Data\PDDys\EEG\Processed EEG Data\'; PDsx=[801 802 803 804 805 806 807 808 809 810 811 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 ]; % 803 S1 is garbage CTLsx=[894 908 890 891 892 893 895 896 897 898 899 900 901 902 903 904 905 906 907 909 910 911 912 913 914 8010 8060 8070 ]; for subj=[PDsx,CTLsx] for session=1:2 if (subj>850 && session==1) || subj<850 % If not ctl, do session 2 if ~(exist([savedir,num2str(subj),'_',num2str(session),'_PDDys_REST.mat'])==2) disp(['Do Rest --- Subno: ',num2str(subj),' Session: ',num2str(session)]); disp(' '); % 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),'_ODDBALL.vhdr']); % Get Locs locpath=('Y:\Programs\eeglab12_0_2_1b\plugins\dipfit2.2\standard_BESA\standard-10-5-cap385.elp'); EEG = pop_chanedit(EEG, 'lookup', locpath); EEG = eeg_checkset( EEG ); % 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 All_STIM={'S 1','S 3'}; % Open, Closed EEG = pop_epoch( EEG, All_STIM, [-2 2], '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='REST'; 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,EEG.bad_chans,EEG.bad_epochs,EEG.bad_ICAs]=APPLE_PDDys(EEG,eeg_chans,ref_chan,Do_ICA,subj,EEG.VEOG,session,TASK); % Save save([savedir,num2str(subj),'_',num2str(session),'_PDDys_REST.mat'],'EEG'); clear EEG bad* UNIQUE* TYPES TRIGGERS % ---------------------- end end end end