Neonatal brain activity across sleep states: Evidence from resting EEG and auditory event-related potentials.
The 3 matches · 1 of them tie a paragraph to a whole file, not to given lines: a weak match, whose lines are not tinted
- [1] § Methods › EEG preprocessing ↔ SA-MADE_pipeline_multiple_participants.m, lines 1–137 · score 0.91 · low pass filtered, high pass filtered, EEGLAB toolbox, voltage threshold, Developmental EEG, pipeline
- [2] § Methods › EEG preprocessing ↔ SA-MADE_pipeline_multiple_participants.m, lines 1–137 · score 0.61 · Missing channels, pipeline, millisecond, thresholding, voltages, segments
- [3] § Methods › Data acquisition ↔ Labeling_MMN_multi_participant.m, the whole file · a weak match · score 0.59 · standard tones, novel tone, blocks, deviant
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
MATLAB · 1,672 lines · 101 KB · no license · 2 matches
- % ************************************************************************
- % The Maryland Analysis of Developmental EEG (UMADE) Pipeline
- % Version 1.0
- % Developed at the Child Development Lab, University of Maryland, College Park
- % Contributors to MADE pipeline:
- % Ranjan Debnath ([email hidden])
- % George A. Buzzell ([email hidden])
- % Santiago Morales Pamplona ([email hidden])
- % Stephanie Leach ([email hidden])
- % Maureen Elizabeth Bowers ([email hidden])
- % Nathan A. Fox ([email hidden])
- % MADE uses EEGLAB toolbox and some of its plugins. Before running the pipeline, you have to install the following:
- % EEGLab: https://sccn.ucsd.edu/eeglab/downloadtoolbox.php/download.php
- % You also need to download the following plugins/extensions from here: https://sccn.ucsd.edu/wiki/EEGLAB_Extensions
- % Specifically, download:
- % MFFMatlabIO: https://github.com/arnodelorme/mffmatlabio/blob/master/README.txt
- % FASTER: https://sourceforge.net/projects/faster/
- % ADJUST: https://www.nitrc.org/projects/adjust/
- % Adjusted ADJUST (included in this pipeline): https://github.com/ChildDevLab/MADE-EEG-preprocessing-pipeline
- % After downloading these plugins (as zip files), you need to place it in the eeglab/plugins folder.
- % For instance, for FASTER, you uncompress the downloaded extension file (e.g., 'FASTER.zip') and place it in the main EEGLAB "plugins" sub-directory/sub-folder.
- % After placing all the required plugins, add the EEGLAB folder to your path by using the following code:
- % addpath(genpath(('...')) % Enter the path of the EEGLAB folder in this line
- % Please cite the following references for in any manuscripts produced utilizing MADE pipeline:
- % EEGLAB: A Delorme & S Makeig (2004) EEGLAB: an open source toolbox for
- % analysis of single-trial EEG dynamics. Journal of Neuroscience Methods, 134, 9?21.
- % firfilt (filter plugin): developed by Andreas Widmann (https://home.uni-leipzig.de/biocog/content/de/mitarbeiter/widmann/eeglab-plugins/)
- % FASTER: Nolan, H., Whelan, R., Reilly, R.B., 2010. FASTER: Fully Automated Statistical
- % Thresholding for EEG artifact Rejection. Journal of Neuroscience Methods, 192, 152?162.
- % ADJUST: Mognon, A., Jovicich, J., Bruzzone, L., Buiatti, M., 2011. ADJUST: An automatic EEG
- % artifact detector based on the joint use of spatial and temporal features. Psychophysiology, 48, 229?240.
- % Our group has modified ADJUST plugin to improve selection of ICA components containing artifacts
- % This pipeline is released under the GNU General Public License version 3.
- % ************************************************************************
- % User input: user provide relevant information to be used for data processing
- % Preprocessing of EEG data involves using some common parameters for
- % every subject. This part of the script initializes the common parameters.
- clear % clear matlab workspace
- clc % clear matlab command window
- eeglab % restart eeglab
- % 1. Enter the path of the folder that has the raw data to be analyzed
- rawdata_location = 'lorem ipsum';
- % 2. Enter the path of the folder where you want to save the processed data
- output_location = 'lorem ipsum';
- scripts_location = 'lorem ipsum';
- % 3. Enter the path of the folder that has the individual sleep state spreadsheets
- event_location = 'lorem ipsum';
- % 3. Enter the path of the channel location.sfp file
- channel_locations = 'lorem ipsum';
- % 4. Do your data need correction for anti-aliasing filter and/or task related time offset?
- adjust_time_offset = 0; % 0 = NO (no correction), 1 = YES (correct time offset)
- % If your data need correction for time offset, initialize the offset time (in milliseconds)
- filter_timeoffset = 0; % anti-aliasing time offset (in milliseconds). 0 = No time offset
- stimulus_timeoffset = 0; % stimulus related time offset (in milliseconds). 0 = No time offset
- response_timeoffset = 0; % response related time offset (in milliseconds). 0 = No time offset
- stimulus_markers = {}; % enter the stimulus makers that need to be adjusted for time offset
- respose_markers = {}; % enter the response makers that need to be adjusted for time offset
- % 5. Do you want to down sample the data?
- down_sample = 1; % 0 = NO (no down sampling), 1 = YES (down sampling)
- sampling_rate = 500; % set sampling rate (in Hz), if you want to down sample
- % 6. Do you want to delete the outer layer of the channels? (Rationale has been described in MADE manuscript)
- % This fnction can also be used to down sample electrodes. For example, if EEG was recorded with 128 channels but you would
- % like to analyse only 64 channels, you can assign the list of channnels to be excluded in the 'outerlayer_channel' variable.
- delete_outerlayer = 1; % 0 = NO (do not delete outer layer), 1 = YES (delete outerlayer);
- % If you want to delete outer layer, make a list of channels to be deleted
- outerlayer_channel = {'E17' 'E38' 'E43' 'E44' 'E48' 'E49' 'E113' 'E114' 'E119' 'E120' 'E121' 'E125' 'E126' 'E127' 'E128' 'E56' 'E63' 'E68' 'E73' 'E81' 'E88' 'E94' 'E99' 'E107'}; % list of channels
- % recommended list for EGI 128 chanenl net: {'E17' 'E38' 'E43' 'E44' 'E48' 'E49' 'E113' 'E114' 'E119' 'E120' 'E121' 'E125' 'E126' 'E127' 'E128' 'E56' 'E63' 'E68' 'E73' 'E81' 'E88' 'E94' 'E99' 'E107'}
- % 7. Initialize the filters
- highpass = 0.3; % High-pass frequency
- lowpass = 50; % Low-pass frequency. We recommend low-pass filter at/below line noise frequency (see manuscript for detail)
- % 8. Are you processing task-related or resting-state EEG data?
- %task_eeg = 0; % 0 = resting, 1 = task
- task_event_markers_cell = {{'QS','AS','I','W'},{'QS','AS','I','W'},{'1','2','3'},{'DIN1'}}; % enter all the event/condition markers
- % 9. Do you want to epoch/segment your data?
- %epoch_data = 0; % 0 = NO (do not epoch), 1 = YES (epoch data)
- task_epoch_length_cell = {[0 2]; [0 2]; [-0.1 0.5]; [-0.2 0.4]}; % epoch length in second
- %rest_epoch_length = 2; % for resting EEG continuous data will be segmented into consecutive epochs of a specified length (here 2 second) by adding dummy events
- %overlap_epoch = 1; % 0 = NO (do not create overlapping epoch), 1 = YES (50% overlapping epoch)
- %dummy_events ={'rest'}; % enter dummy events name
- % 10. Do you want to remove/correct baseline?
- %remove_baseline = 0; % 0 = NO (no baseline correction), 1 = YES (baseline correction)
- %baseline_window = [xx xx]; % baseline period in milliseconds (MS) [] = entire epoch
- % 11. Do you want to remove artifact laden epoch based on voltage threshold?
- voltthres_rejection = 1; % 0 = NO, 1 = YES
- volt_threshold = [-150 150]; % lower and upper threshold (in ?V)
- % 12. Do you want to perform epoch level channel interpolation for artifact laden epoch? (see manuscript for detail)
- interp_epoch = 1; % 0 = NO, 1 = YES.
- frontal_channels = {'E1', 'E8', 'E14', 'E21', 'E25', 'E32', 'E17'}; % If you set interp_epoch = 1, enter the list of frontal channels to check (see manuscript for detail)
- % recommended list for EGI 128 channel net: {'E1', 'E8', 'E14', 'E21', 'E25', 'E32', 'E17'}
- %13. Do you want to interpolate the bad channels that were removed from data?
- interp_channels = 1; % 0 = NO (Do not interpolate), 1 = YES (interpolate missing channels)
- % 14. Do you want to rereference your data?
- %rerefer_data = 0; % 0 = NO, 1 = YES
- %reref=[]; % Enter electrode name/s or number/s to be used for rereferencing
- % For channel name/s enter, reref = {'channel_name', 'channel_name'};
- % For channel number/s enter, reref = [channel_number, channel_number];
- % For average rereference enter, reref = []; default is average rereference
- % 15. Do you want to save interim results?
- save_interim_result = 1; % 0 = NO (Do not save) 1 = YES (save interim results)
- % 16. How do you want to save your data? .set or .mat
- output_format = 1; % 1 = .set (EEGLAB data structure), 2 = .mat (Matlab data structure)
- % ********* no need to edit beyond this point for EGI .mff data **********
- % ********* for non-.mff data format edit data import function ***********
- % ********* below using relevant data import plugin from EEGLAB **********
- %% Read files to analyses
- datafile_names=dir(rawdata_location);
- datafile_names=datafile_names(~ismember({datafile_names.name},{'.', '..', '.DS_Store'}));
- datafile_names={datafile_names.name};
- ext = '.set'
- %% Check whether EEGLAB and all necessary plugins are in Matlab path.
- if exist('eeglab','file')==0
- error(['Please make sure EEGLAB is on your Matlab path. Please see EEGLAB' ...
- 'wiki page for download and instalation instructions']);
- end
- if strcmp(ext, '.mff')==1
- if exist('mff_import', 'file')==0
- error(['Please make sure "mffmatlabio" plugin is in EEGLAB plugin folder and on Matlab path.' ...
- ' Please see EEGLAB wiki page for download and instalation instructions of plugins.' ...
- ' If you are not analysing EGI .mff data, edit the data import function below.']);
- end
- else
- warning('Your data are not EGI .mff files. Make sure you edit data import function before using this script');
- end
- if exist('pop_firws', 'file')==0
- error(['Please make sure "firfilt" plugin is in EEGLAB plugin folder and on Matlab path.' ...
- ' Please see EEGLAB wiki page for download and instalation instructions of plugins.']);
- end
- if exist('channel_properties', 'file')==0
- error(['Please make sure "FASTER" plugin is in EEGLAB plugin folder and on Matlab path.' ...
- ' Please see EEGLAB wiki page for download and instalation instructions of plugins.']);
- end
- if exist('ADJUST', 'file')==0
- error(['Please make sure you download modified "ADJUST" plugin from GitHub (link is in MADE manuscript)' ...
- ' and ADJUST is in EEGLAB plugin folder and on Matlab path.']);
- end
- %% Create output folders to save data
- if save_interim_result ==1
- if exist([output_location filesep 'filtered_data'], 'dir') == 0
- mkdir([output_location filesep 'filtered_data'])
- end
- if exist([output_location filesep 'ica_data'], 'dir') == 0
- mkdir([output_location filesep 'ica_data'])
- end
- end
- if exist([output_location filesep 'processed_data'], 'dir') == 0
- mkdir([output_location filesep 'processed_data'])
- end
- %% Initialize output variables
- reference_used_for_faster=[]; % reference channel used for running faster to identify bad channel/s
- faster_bad_channels=[]; % number of bad channel/s identified by faster
- ica_preparation_bad_channels=[]; % number of bad channel/s due to channel/s exceeding xx% of artifacted epochs
- length_ica_data=[]; % length of data (in second) fed into ICA decomposition
- total_ICs=[]; % total independent components (ICs)
- ICs_removed=[]; % number of artifacted ICs
- total_epochs_before_artifact_rejection=[]; % number of total MMN trials before artifact rejection
- total_epochs_after_artifact_rejection=[]; % number of total MMN trials after artifact rejection
- total_channels_interpolated=[]; % total_channels_interpolated=faster_bad_channels+ica_preparation_bad_channels
- total_standard=[]; % number of MMN standard trials before artifact rejection
- total_standard_AS=[]; % number of MMN standard trials during AS before artifact rejection
- total_standard_QS=[]; % number of MMN standard trials during QS before artifact rejection
- total_standard_W=[]; % number of MMN standard trials during W before artifact rejection
- total_standard_I=[]; % number of MMN standard trials during I before artifact rejection
- total_standard_after_artifact_rejection=[]; % number of MMN standard trials after artifact rejection
- total_standard_AS_after_artifact_rejection=[]; % number of MMN standard trials during AS after artifact rejection
- total_standard_QS_after_artifact_rejection=[]; % number of MMN standard trials during QS after artifact rejection
- total_standard_W_after_artifact_rejection=[]; % number of MMN standard trials during W after artifact rejection
- total_standard_I_after_artifact_rejection=[]; % number of MMN standard trials during I after artifact rejection
- total_deviant=[]; % number of MMN deviant trials before artifact rejection
- total_deviant_AS=[]; % number of MMN deviant trials during AS before artifact rejection
- total_deviant_QS=[]; % number of MMN deviant trials during QS before artifact rejection
- total_deviant_W=[]; % number of MMN deviant trials during W before artifact rejection
- total_deviant_I=[]; % number of MMN deviant trials during I before artifact rejection
- total_deviant_after_artifact_rejection=[]; % number of MMN deviant trials after artifact rejection
- total_deviant_AS_after_artifact_rejection=[]; % number of MMN deviant trials during AS after artifact rejection
- total_deviant_QS_after_artifact_rejection=[]; % number of MMN deviant trials during QS after artifact rejection
- total_deviant_W_after_artifact_rejection=[]; % number of MMN deviant trials during W after artifact rejection
- total_deviant_I_after_artifact_rejection=[]; % number of MMN deviant trials during I after artifact rejection
- total_novel=[]; % number of MMN novel trials before artifact rejection
- total_novel_AS=[]; % number of MMN novel trials during AS before artifact rejection
- total_novel_QS=[]; % number of MMN novel trials during QS before artifact rejection
- total_novel_W=[]; % number of MMN novel trials during W before artifact rejection
- total_novel_I=[]; % number of MMN novel trials during I before artifact rejection
- total_novel_after_artifact_rejection=[]; % number of MMN novel trials after artifact rejection
- total_novel_AS_after_artifact_rejection=[]; % number of MMN novel trials during AS after artifact rejection
- total_novel_QS_after_artifact_rejection=[]; % number of MMN novel trials during QS after artifact rejection
- total_novel_W_after_artifact_rejection=[]; % number of MMN novel trials during W after artifact rejection
- total_novel_I_after_artifact_rejection=[]; % number of MMN novel trials during I after artifact rejection
- total_AS=[]; % number of Resting epochs during AS before artifact rejection
- total_QS=[]; % number of Resting epochs during QS before artifact rejection
- total_W=[]; % number of Resting epochs during W before artifact rejection
- total_I=[]; % number of Resting epochs during I before artifact rejection
- total_AS_after_artifact_rejection=[]; % number of Resting epochs during AS after artifact rejection
- total_QS_after_artifact_rejection=[]; % number of Resting epochs during QS after artifact rejection
- total_W_after_artifact_rejection=[]; % number of Resting epochs during W after artifact rejection
- total_I_after_artifact_rejection=[]; % number of Resting epochs during I after artifact rejection
- total_vep=[]; % number of vep total before artifact rejection
- total_AS_vep=[]; % number of vep AS trials before artifaction rejection
- total_QS_vep=[]; % number of vep QS trials before artifaction rejection
- total_I_vep=[]; % number of vep I trials before artifaction rejection
- total_W_vep=[]; % number of vep W trials before artifaction rejection\\
- total_vep_after_artifact_rejection=[]; % number of total vep after artifact rejection
- total_AS_vep_artifact_rejection=[]; % number of vep AS trials after artifaction rejection
- total_QS_vep_artifact_rejection=[]; % number of vep QS trials after artifaction rejection
- total_I_vep_artifact_rejection=[]; % number of vep I trials after artifaction rejection
- total_W_vep_artifact_rejection=[]; % number of vep W trials after artifaction rejection
- %% Loop over all data files
- for s=1:length(datafile_names)
- fprintf('\n\n\n*** Processing subject %d (%s) ***\n\n\n', s, datafile_names{s});
- ALLEEG=[];
- % get the current subject folder name and go into that folder
- subject = datafile_names{s};
- subject_folder = [rawdata_location subject filesep subject];
- cd (subject_folder);
- %Make a list of the EEG files in that subject's folder
- sub_file_list=dir('*.set');
- sub_file_list={sub_file_list.name};
- %grab the current task file name
- for c=1:length(sub_file_list) %1:NumberOfTasks;
- %Filename example: F1572_MMN_1mo_20201104_045409.mff
- currentTaskFilename = sub_file_list{c};
- subfields = strsplit(currentTaskFilename,'_');
- sCon = subfields{2};
- %check which task this file is
- if strcmp(sCon,'arm')
- task=1;
- elseif strcmp(sCon,'sResting')
- task=2;
- elseif strcmp(sCon, 'MMN')
- task=3;
- elseif strcmp(sCon, 'VEP')
- task=4;
- else
- task=0;
- error('Current task name does not match either task!')
- end
- %% STEP 1: Import EGI data file and relevant information
- cd (subject_folder);
- EEG = pop_loadset('filename', sub_file_list{c}, 'filepath', subject_folder);
- EEG = eeg_checkset(EEG);
- % Edit this data import function and use appropriate plugin from EEGLAB
- % for non-.mff data. For example, to import biosemi data, use biosig plugin.
- % The example codes for 64 channels biosemi data:
- % EEG = pop_biosig([rawdata_location, filesep, datafile_names{subject}]);
- % EEG = eeg_checkset(EEG);
- % EEG = pop_select( EEG,'nochannel', 65:72); % delete redundant channels
- %% STEP 2: Import channel locations
- EEG=pop_chanedit(EEG, 'load',{channel_locations 'filetype' 'autodetect'});
- EEG = eeg_checkset( EEG );
- % Check whether the channel locations were properly imported. The EEG signals and channel numbers should be same.
- if size(EEG.data, 1) ~= length(EEG.chanlocs)
- error('The size of the data does not match with channel numbers.');
- end
- %% STEP 3: Adjust anti-aliasing and task related time offset
- if adjust_time_offset==1
- % adjust anti-aliasing filter time offset
- if filter_timeoffset~=0
- for aafto=1:length(EEG.event)
- EEG.event(aafto).latency=EEG.event(aafto).latency+(filter_timeoffset/1000)*EEG.srate;
- end
- end
- % adjust stimulus time offset
- if stimulus_timeoffset~=0
- for sto=1:length(EEG.event)
- for sm=1:length(stimulus_markers)
- if strcmp(EEG.event(sto).type, stimulus_markers{sm})
- EEG.event(sto).latency=EEG.event(sto).latency+(stimulus_timeoffset/1000)*EEG.srate;
- end
- end
- end
- end
- % adjust response time offset
- if response_timeoffset~=0
- for rto=1:length(EEG.event)
- for rm=1:length(response_markers)
- if strcmp(EEG.event(rto).type, response_markers{rm})
- EEG.event(rto).latency=EEG.event(rto).latency-(response_timeoffset/1000)*EEG.srate;
- end
- end
- end
- end
- end
- %% STEP 4: Change sampling rate
- if down_sample==1
- if floor(sampling_rate) > EEG.srate
- error ('Sampling rate cannot be higher than recorded sampling rate');
- elseif floor(sampling_rate) ~= EEG.srate
- EEG = pop_resample( EEG, sampling_rate);
- EEG = eeg_checkset( EEG );
- end
- end
- %% STEP 5: Delete outer layer of channels
- chans_labels=cell(1,EEG.nbchan);
- for i=1:EEG.nbchan
- chans_labels{i}= EEG.chanlocs(i).labels;
- end
- [chans,chansidx] = ismember(outerlayer_channel, chans_labels);
- outerlayer_channel_idx = chansidx(chansidx ~= 0);
- if delete_outerlayer==1
- if isempty(outerlayer_channel_idx)==1
- error(['None of the outer layer channels present in channel locations of data.'...
- ' Make sure outer layer channels are present in channel labels of data (EEG.chanlocs.labels).']);
- else
- EEG = pop_select( EEG,'nochannel', outerlayer_channel_idx);
- EEG = eeg_checkset( EEG );
- end
- end
- %% STEP 5.5: Lable the task events
- task_epoch_length = task_epoch_length_cell{task};
- % Creating task, type, and latency lables
- if task == 1 % sResting in arm
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'Task',task); % Creating an event field "Task" and put 1 for Resting
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'type',NaN); % Creating an event filed "type" for inserting sleep state flags
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'latency',1); % Creating an event filed "latency" for inserting sleep state flags
- EEG = eeg_checkset( EEG );
- % insert sleep state flags to resting
- EEG = pop_importevent( EEG, 'event',[event_location '/' subject '_sResting_arm.csv'] ,'fields',{'latency' 'type'},'timeunit',1,'align',0);
- EEG = eeg_checkset( EEG );
- % Add sleep state flags every second
- current_cond = {'QS','AS', 'W','I'};
- for cc=1:length(current_cond)
- startEventNums=[]; endEventNums=[]; startLats=[]; endLats=[];
- startEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'start']));
- endEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'end']));
- if isempty(startEventNums)
- % condition not present... can't epoch
- else
- for ll=1:length(startEventNums)
- startLats(ll) = (EEG.event(startEventNums(ll)).latency)/EEG.srate; % latency of the start point of each state in seconds
- end
- for ll=1:length(endEventNums)
- endLats(ll) = (EEG.event(endEventNums(ll)).latency)/EEG.srate; % latency of the end point of each state in seconds
- end
- for b=1:length(startEventNums)
- conditionleg = endLats(b)- startLats(b);
- for t=1:floor(conditionleg)-task_epoch_length(end)+2 % +2 because the second between two states is included in the prvious state
- latency = startLats(b) + t-1;
- EEG = pop_editeventvals(EEG,'insert',{1 [] [] []},'changefield',{1 'type' current_cond{cc}}, 'changefield',{1 'latency' latency},'changefield',{1,'Task',task});
- end
- EEG = eeg_checkset(EEG);
- end
- end
- end
- elseif task == 2 % sResting in bassinet
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'Task',task); % Creating an event field "Task" and put 1 for Resting
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'type',NaN); % Creating an event filed "type" for inserting sleep state flags
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'latency',1); % Creating an event filed "latency" for inserting sleep state flags
- EEG = eeg_checkset( EEG );
- % insert sleep state flags to resting
- EEG = pop_importevent( EEG, 'event',[event_location '/' subject '_sResting.csv'] ,'fields',{'latency' 'type'},'timeunit',1,'align',0);
- EEG = eeg_checkset( EEG );
- % Add sleep state flags every second
- current_cond = {'QS','AS', 'W','I'};
- for cc=1:length(current_cond)
- startEventNums=[]; endEventNums=[]; startLats=[]; endLats=[];
- startEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'start']));
- endEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'end']));
- if isempty(startEventNums)
- % condition not present... can't epoch
- else
- for ll=1:length(startEventNums)
- startLats(ll) = (EEG.event(startEventNums(ll)).latency)/EEG.srate; % latency of the start point of each state in seconds
- end
- for ll=1:length(endEventNums)
- endLats(ll) = (EEG.event(endEventNums(ll)).latency)/EEG.srate; % latency of the end point of each state in seconds
- end
- for b=1:length(startEventNums)
- conditionleg = endLats(b)- startLats(b);
- for t=1:floor(conditionleg)-task_epoch_length(end)+2 % +2 because the second between two states is included in the prvious state
- latency = startLats(b) + t-1;
- EEG = pop_editeventvals(EEG,'insert',{1 [] [] []},'changefield',{1 'type' current_cond{cc}}, 'changefield',{1 'latency' latency},'changefield',{1,'Task',task});
- end
- EEG = eeg_checkset(EEG);
- end
- end
- end
- elseif task == 3 % MMN
- % Creating a task Label
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'Task',task); % Creating an event field "Task" and put 2 for MMN
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'State','I'); % Creating an event filed "State" for mark the sleep state for each stimulus
- EEG = eeg_checkset( EEG );
- % insert sleep state flags to MMN
- EEG = pop_importevent( EEG, 'event',[event_location '/' subject '_MMN.csv'] ,'fields',{'latency' 'type'},'timeunit',1,'align',0); % 0 in the sleep state file corresponds to "boundary" in EEG
- EEG = eeg_checkset( EEG );
- % Mark sleep stat flag for MMN ERP markers
- current_cond = {'QS','AS', 'W','I'};
- for cc=1:length(current_cond)
- startEventNums=[]; endEventNums=[]; DINSEventNums=[]; startLats=[]; endLats=[]; DIN2Lats=[];
- startEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'start']));
- endEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'end']));
- DINSEventNums=find(strcmp({EEG.event.type},'DIN2'));
- if isempty(startEventNums)
- % condition not present... can't epoch
- else
- for ll=1:length(startEventNums)
- startLats(ll) = (EEG.event(startEventNums(ll)).latency)/EEG.srate;
- end
- for ll=1:length(endEventNums)
- endLats(ll) = (EEG.event(endEventNums(ll)).latency)/EEG.srate;
- end
- for ll=1:length(DINSEventNums)
- DIN2Lats(ll)= (EEG.event(DINSEventNums(ll)).latency)/EEG.srate;
- end
- for b=1:length(startEventNums)
- for dl = 1: length(DINSEventNums)
- if DIN2Lats(dl) >= startLats(b)-task_epoch_length(1) && DIN2Lats(dl)<= endLats(b)+1-task_epoch_length(2) % select trials that fall into just one sleep state
- EEG.event(DINSEventNums(dl)).State=current_cond{cc};
- end
- end
- end
- end
- end
- % lable MMN
- cd(scripts_location);
- Labeling_MMN_multi();
- % remove data after last trps
- trsp = find(strcmp({EEG.event.type},'TRSP'));
- EEG = eeg_eegrej( EEG, [(EEG.event(trsp(end)).latency+(1.5*EEG.srate)) EEG.pnts] );
- EEG = eeg_checkset( EEG );
- cd(rawdata_location);
- elseif task == 4 % VEP
- % Creating a task Label
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'Task',task); % Creating an event field "Task" and put 2 for MMN
- EEG = pop_editeventfield( EEG, 'indices', strcat('1:', int2str(length(EEG.event))), 'State','I'); % Creating an event filed "State" for mark the sleep state for each stimulus
- EEG = eeg_checkset( EEG );
- % insert sleep state flags to VEP
- EEG = pop_importevent( EEG, 'event',[event_location '/' subject '_VEP.csv'] ,'fields',{'latency' 'type'},'timeunit',1,'align',0);
- EEG = eeg_checkset( EEG );
- % Mark sleep stat flag for VEP ERP markers
- current_cond = {'QS','AS', 'W','I'};
- for cc=1:length(current_cond)
- startEventNums=[]; endEventNums=[]; DINSEventNums=[]; startLats=[]; endLats=[]; DIN1Lats=[];
- startEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'start']));
- endEventNums = find(strcmp({EEG.event.type},[current_cond{cc} 'end']));
- DINSEventNums=find(strcmp({EEG.event.type},'DIN1'));
- if isempty(startEventNums)
- % condition not present... can't epoch
- else
- for ll=1:length(startEventNums)
- startLats(ll) = (EEG.event(startEventNums(ll)).latency)/EEG.srate;
- end
- for ll=1:length(endEventNums)
- endLats(ll) = (EEG.event(endEventNums(ll)).latency)/EEG.srate;
- end
- for ll=1:length(DINSEventNums)
- DIN1Lats(ll)= (EEG.event(DINSEventNums(ll)).latency)/EEG.srate;
- end
- for b=1:length(startEventNums)
- for dl = 1: length(DINSEventNums)
- if DIN1Lats(dl) >= startLats(b)-task_epoch_length(1) && DIN1Lats(dl)<= endLats(b)+1-task_epoch_length(2) % select trials that fall into just one sleep state
- EEG.event(DINSEventNums(dl)).State=current_cond{cc};
- end
- end
- end
- end
- end
- end
- %% STEP 6: Filter data
- % Calculate filter order using the formula: m = dF / (df / fs), where m = filter order,
- % df = transition band width, dF = normalized transition width, fs = sampling rate
- % dF is specific for the window type. Hamming window dF = 3.3
- high_transband = highpass; % high pass transition band
- low_transband = 10; % low pass transition band
- hp_fl_order = 3.3 / (high_transband / EEG.srate);
- lp_fl_order = 3.3 / (low_transband / EEG.srate);
- % Round filter order to next higher even integer. Filter order is always even integer.
- if mod(floor(hp_fl_order),2) == 0
- hp_fl_order=floor(hp_fl_order);
- elseif mod(floor(hp_fl_order),2) == 1
- hp_fl_order=floor(hp_fl_order)+1;
- end
- if mod(floor(lp_fl_order),2) == 0
- lp_fl_order=floor(lp_fl_order)+2;
- elseif mod(floor(lp_fl_order),2) == 1
- lp_fl_order=floor(lp_fl_order)+1;
- end
- % Calculate cutoff frequency
- high_cutoff = highpass/2;
- low_cutoff = lowpass + (low_transband/2);
- % Performing high pass filtering
- EEG = eeg_checkset( EEG );
- EEG = pop_firws(EEG, 'fcutoff', high_cutoff, 'ftype', 'highpass', 'wtype', 'hamming', 'forder', hp_fl_order, 'minphase', 0);
- EEG = eeg_checkset( EEG );
- % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
- % pop_firws() - filter window type hamming ('wtype', 'hamming')
- % pop_firws() - applying zero-phase (non-causal) filter ('minphase', 0)
- % Performing low pass filtering
- EEG = eeg_checkset( EEG );
- EEG = pop_firws(EEG, 'fcutoff', low_cutoff, 'ftype', 'lowpass', 'wtype', 'hamming', 'forder', lp_fl_order, 'minphase', 0);
- EEG = eeg_checkset( EEG );
- % pop_firws() - transition band width: 10 Hz
- % pop_firws() - filter window type hamming ('wtype', 'hamming')
- % pop_firws() - applying zero-phase (non-causal) filter ('minphase', 0)
- % save current task in ALLEEG structure (we'll use this to merge)
- [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, task);
- EEG_idx(task)=1; % save out index of current task
- end % end loop through subject task files
- %% STEP 6.5 Merge the datasets
- % EEG = []; % Saving over EEG
- EEG2Merge = find(EEG_idx==1);
- if length(EEG2Merge) >=2
- EEG = pop_mergeset(ALLEEG,EEG2Merge);
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_Merged']);
- end
- %% STEP 7: Run faster to find bad channels
- % First check whether reference channel (i.e. zeroed channels) is present in data
- % reference channel is needed to run faster
- ref_chan=[]; FASTbadChans=[]; all_chan_bad_FAST=0;
- ref_chan=find(any(EEG.data, 2)==0);
- if numel(ref_chan)>1
- error(['There are more than 1 zeroed channel (i.e. zero value throughout recording) in data.'...
- ' Only reference channel should be zeroed channel. Delete the zeroed channel/s which is not reference channel.']);
- elseif numel(ref_chan)==1
- list_properties = channel_properties(EEG, 1:EEG.nbchan, ref_chan); % run faster
- FASTbadIdx=min_z(list_properties);
- FASTbadChans=find(FASTbadIdx==1);
- FASTbadChans=FASTbadChans(FASTbadChans~=ref_chan);
- reference_used_for_faster{s}={EEG.chanlocs(ref_chan).labels};
- EEG = pop_select( EEG,'nochannel', ref_chan);
- EEG = eeg_checkset(EEG);
- channels_analysed=EEG.chanlocs; % keep full channel locations to use later for interpolation of bad channels
- elseif numel(ref_chan)==0
- warning('Reference channel is not present in data. Cz channel will be used as reference channel.');
- ref_chan=find(strcmp({EEG.chanlocs.labels}, 'Cz')); % find Cz channel index
- EEG_copy=[];
- EEG_copy=EEG; % make a copy of the dataset
- EEG_copy = pop_reref( EEG_copy, ref_chan,'keepref','on'); % rerefer to Cz in copied dataset
- EEG_copy = eeg_checkset(EEG_copy);
- list_properties = channel_properties(EEG_copy, 1:EEG_copy.nbchan, ref_chan); % run faster on copied dataset
- FASTbadIdx=min_z(list_properties);
- FASTbadChans=find(FASTbadIdx==1);
- channels_analysed=EEG.chanlocs;
- reference_used_for_faster{s}={EEG.chanlocs(ref_chan).labels};
- end
- % If FASTER identifies all channels as bad channels, save the dataset
- % at this stage and ignore the remaining of the preprocessing.
- if numel(FASTbadChans)==EEG.nbchan || numel(FASTbadChans)+1==EEG.nbchan
- all_chan_bad_FAST=1;
- warning(['No usable data for datafile', datafile_names{s}]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_Merged_no_usable_data_all_bad_channels']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_Merged_no_usable_data_all_bad_channels.set'],'filepath', [output_location filesep 'filtered_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_Merged_no_usable_data_all_bad_channels.mat']], 'EEG'); % save .mat format
- end
- else
- % Reject channels that are bad as identified by Faster
- EEG = pop_select( EEG,'nochannel', FASTbadChans);
- EEG = eeg_checkset(EEG);
- end
- if numel(FASTbadChans)==0
- faster_bad_channels{s}='0';
- else
- faster_bad_channels{s}=num2str(FASTbadChans');
- end
- if all_chan_bad_FAST==1
- faster_bad_channels{s}='0';
- ica_preparation_bad_channels{s}='0';
- length_ica_data(s)=0;
- total_ICs(s)=0;
- ICs_removed{s}='0';
- total_epochs_before_artifact_rejection(s)=0;
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next subject folder
- end
- %% Save data after running filter and FASTER function, if saving interim results was preferred
- if save_interim_result ==1
- if output_format==1
- EEG = eeg_checkset( EEG );
- EEG = pop_editset(EEG, 'setname', strrep(datafile_names{s}, ext, '_filtered_data'));
- EEG = pop_saveset( EEG,'filename',strrep(datafile_names{s}, ext, '_filtered_data.set'),'filepath', [output_location filesep 'filtered_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'filtered_data' filesep ] strrep(datafile_names{s}, ext, '_filtered_data.mat')], 'EEG'); % save .mat format
- end
- end
- %% STEP 8: Prepare data for ICA
- EEG_copy=[];
- EEG_copy=EEG; % make a copy of the dataset
- EEG_copy = eeg_checkset(EEG_copy);
- % Perform 1Hz high pass filter on copied dataset
- transband = 1;
- fl_cutoff = transband/2;
- fl_order = 3.3 / (transband / EEG.srate);
- if mod(floor(fl_order),2) == 0
- fl_order=floor(fl_order);
- elseif mod(floor(fl_order),2) == 1
- fl_order=floor(fl_order)+1;
- end
- EEG_copy = pop_firws(EEG_copy, 'fcutoff', fl_cutoff, 'ftype', 'highpass', 'wtype', 'hamming', 'forder', fl_order, 'minphase', 0);
- EEG_copy = eeg_checkset(EEG_copy);
- % Create 1 second epoch
- EEG_copy=eeg_regepochs(EEG_copy,'recurrence', 1, 'limits',[0 1], 'rmbase', [NaN], 'eventtype', '999'); % insert temporary marker 1 second apart and create epochs
- EEG_copy = eeg_checkset(EEG_copy);
- % Find bad epochs and delete them from dataset
- vol_thrs = [-1000 1000]; % [lower upper] threshold limit(s) in mV.
- emg_thrs = [-100 30]; % [lower upper] threshold limit(s) in dB.
- emg_freqs_limit = [20 40]; % [lower upper] frequency limit(s) in Hz.
- % Find channel/s with xx% of artifacted 1-second epochs and delete them
- chanCounter = 1; ica_prep_badChans = [];
- numEpochs =EEG_copy.trials; % find the number of epochs
- all_bad_channels=0;
- for ch=1:EEG_copy.nbchan
- % Find artifaceted epochs by detecting outlier voltage
- EEG_copy = pop_eegthresh(EEG_copy,1, ch, vol_thrs(1), vol_thrs(2), EEG_copy.xmin, EEG_copy.xmax, 0, 0);
- EEG_copy = eeg_checkset( EEG_copy );
- % 1 : data type (1: electrode, 0: component)
- % 0 : display with previously marked rejections? (0: no, 1: yes)
- % 0 : reject marked trials? (0: no (but store the marks), 1:yes)
- % Find artifaceted epochs by using thresholding of frequencies in the data.
- % this method mainly rejects muscle movement (EMG) artifacts
- EEG_copy = pop_rejspec( EEG_copy, 1,'elecrange',ch ,'method','fft','threshold', emg_thrs, 'freqlimits', emg_freqs_limit, 'eegplotplotallrej', 0, 'eegplotreject', 0);
- % method : method to compute spectrum (fft)
- % threshold : [lower upper] threshold limit(s) in dB.
- % freqlimits : [lower upper] frequency limit(s) in Hz.
- % eegplotplotallrej : 0 = Do not superpose rejection marks on previous marks stored in the dataset.
- % eegplotreject : 0 = Do not reject marked trials (but store the marks).
- % Find number of artifacted epochs
- EEG_copy = eeg_checkset( EEG_copy );
- EEG_copy = eeg_rejsuperpose( EEG_copy, 1, 1, 1, 1, 1, 1, 1, 1);
- artifacted_epochs=EEG_copy.reject.rejglobal;
- % Find bad channel / channel with more than 20% artifacted epochs
- if sum(artifacted_epochs) > (numEpochs*20/100)
- ica_prep_badChans(chanCounter) = ch;
- chanCounter=chanCounter+1;
- end
- end
- % If all channels are bad, save the dataset at this stage and ignore the remaining of the preprocessing.
- if numel(ica_prep_badChans)==EEG.nbchan || numel(ica_prep_badChans)+1==EEG.nbchan
- all_bad_channels=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_Merged_no_usable_data_all_bad_channels']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_Merged_no_usable_data_all_bad_channels.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_Merged_no_usable_data_all_bad_channels.mat']], 'EEG'); % save .mat format
- end
- else
- % Reject bad channel - channel with more than xx% artifacted epochs
- EEG_copy = pop_select( EEG_copy,'nochannel', ica_prep_badChans);
- EEG_copy = eeg_checkset(EEG_copy);
- end
- if numel(ica_prep_badChans)==0
- ica_preparation_bad_channels{s}='0';
- else
- ica_preparation_bad_channels{s}=num2str(ica_prep_badChans);
- end
- if all_bad_channels == 1
- length_ica_data(s)=0;
- total_ICs(s)=0;
- ICs_removed{s}='0';
- total_epochs_before_artifact_rejection(s)=0;
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- end
- % Find the artifacted epochs across all channels and reject them before doing ICA.
- EEG_copy = pop_eegthresh(EEG_copy,1, 1:EEG_copy.nbchan, vol_thrs(1), vol_thrs(2), EEG_copy.xmin, EEG_copy.xmax,0,0);
- EEG_copy = eeg_checkset(EEG_copy);
- % 1 : data type (1: electrode, 0: component)
- % 0 : display with previously marked rejections? (0: no, 1: yes)
- % 0 : reject marked trials? (0: no (but store the marks), 1:yes)
- % Find artifaceted epochs by using power threshold in 20-40Hz frequency band.
- % This method mainly rejects muscle movement (EMG) artifacts.
- EEG_copy = pop_rejspec(EEG_copy, 1,'elecrange', 1:EEG_copy.nbchan, 'method', 'fft', 'threshold', emg_thrs ,'freqlimits', emg_freqs_limit, 'eegplotplotallrej', 0, 'eegplotreject', 0);
- % method : method to compute spectrum (fft)
- % threshold : [lower upper] threshold limit(s) in dB.
- % freqlimits : [lower upper] frequency limit(s) in Hz.
- % eegplotplotallrej : 0 = Do not superpose rejection marks on previous marks stored in the dataset.
- % eegplotreject : 0 = Do not reject marked trials (but store the marks).
- % Find the number of artifacted epochs and reject them
- EEG_copy = eeg_checkset(EEG_copy);
- EEG_copy = eeg_rejsuperpose(EEG_copy, 1, 1, 1, 1, 1, 1, 1, 1);
- reject_artifacted_epochs=EEG_copy.reject.rejglobal;
- EEG_copy = pop_rejepoch(EEG_copy, reject_artifacted_epochs, 0);
- %% STEP 9: Run ICA
- length_ica_data(s)=EEG_copy.trials; % length of data (in second) fed into ICA
- EEG_copy = eeg_checkset(EEG_copy);
- EEG_copy = pop_runica(EEG_copy, 'icatype', 'runica', 'extended', 1, 'stop', 1E-7, 'interupt','off');
- % Find the ICA weights that would be transferred to the original dataset
- ICA_WINV=EEG_copy.icawinv;
- ICA_SPHERE=EEG_copy.icasphere;
- ICA_WEIGHTS=EEG_copy.icaweights;
- ICA_CHANSIND=EEG_copy.icachansind;
- % If channels were removed from copied dataset during preparation of ica, then remove
- % those channels from original dataset as well before transferring ica weights.
- EEG = eeg_checkset(EEG);
- EEG = pop_select(EEG,'nochannel', ica_prep_badChans);
- % Transfer the ICA weights of the copied dataset to the original dataset
- EEG.icawinv=ICA_WINV;
- EEG.icasphere=ICA_SPHERE;
- EEG.icaweights=ICA_WEIGHTS;
- EEG.icachansind=ICA_CHANSIND;
- EEG = eeg_checkset(EEG);
- %% STEP 10: Run adjust to find artifacted ICA components
- badICs=[]; EEG_copy =[];
- EEG_copy = EEG;
- EEG_copy =eeg_regepochs(EEG_copy,'recurrence', 1, 'limits',[0 1], 'rmbase', [NaN], 'eventtype', '999'); % insert temporary marker 1 second apart and create epochs
- EEG_copy = eeg_checkset(EEG_copy);
- if save_interim_result==1
- badICs = adjusted_ADJUST(EEG_copy, [[output_location filesep 'ica_data' filesep] [datafile_names{s} '_Merged_ica_adjust_report']]);
- else
- badICs = adjusted_ADJUST(EEG_copy, [[output_location filesep 'processed_data' filesep] [datafile_names{s} '_Merged_ica_adjust_report']]);
- end
- close all;
- % Mark the bad ICs found by ADJUST
- for ic=1:length(badICs)
- EEG.reject.gcompreject(1, badICs(ic))=1;
- EEG = eeg_checkset(EEG);
- end
- total_ICs(s)=size(EEG.icasphere, 1);
- if numel(badICs)==0
- ICs_removed{s}='0';
- else
- ICs_removed{s}=num2str(double(badICs));
- end
- %% Save dataset after ICA, if saving interim results was preferred
- if save_interim_result==1
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_Merged_ica_data']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_Merged_ica_data.set'],'filepath', [output_location filesep 'ica_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'ica_data' filesep] [datafile_names{s} '_Merged_ica_data.mat']], 'EEG'); % save .mat format
- end
- end
- %% STEP 11: Remove artifacted ICA components from data
- all_bad_ICs=0;
- ICs2remove=find(EEG.reject.gcompreject); % find ICs to remove
- % If all ICs and bad, save data at this stage and ignore rest of the preprocessing for this subject.
- if numel(ICs2remove)==total_ICs(s)
- all_bad_ICs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_Merged_no_usable_data_all_bad_ICs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_Merged_no_usable_data_all_bad_ICs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_Merged_no_usable_data_all_bad_ICs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = eeg_checkset( EEG );
- EEG = pop_subcomp( EEG, ICs2remove, 0); % remove ICs from dataset
- end
- if all_bad_ICs==1
- total_epochs_before_artifact_rejection(s)=0;
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- end
- %% Keep only the time locking event markers and delete all other event markers
- EEG = eeg_checkset(EEG);
- EEG3 = pop_selectevent(EEG,'type',{'QS' 'AS' 'I' 'W' '1' '2' '3' 'DIN1'},'deleteevents','on');
- %loop through the tasks in the merged dataset
- for task = unique([EEG3.event.Task])
- EEG=[];
- task_event_markers = task_event_markers_cell{task};
- task_epoch_length = task_epoch_length_cell{task};
- if task == 1 % sResting in arms
- % Select events specific to sResting
- EEG = pop_selectevent(EEG3, 'Task', [task],'deleteevents','on'); % just delete other flags/markers, but will NOT delte the EEG data
- %% STEP 12: Segment data into fixed length epochs
- EEG = eeg_checkset(EEG);
- EEG = pop_epoch(EEG, task_event_markers, task_epoch_length, 'epochinfo', 'yes');
- EEG = pop_selectevent( EEG, 'latency','-.1 <= .1','deleteevents','on');
- total_epochs_before_artifact_rejection(s)=EEG.trials;
- total_AS(s) = length(find(strcmp({EEG.event.type},'AS')));
- total_QS(s) = length(find(strcmp({EEG.event.type}, 'QS')));
- total_W(s) = length(find(strcmp({EEG.event.type}, 'W')));
- total_I(s) = length(find(strcmp({EEG.event.type}, 'I')));
- %% STEP 13: Remove baseline
- %if remove_baseline==1
- %EEG = eeg_checkset( EEG );
- %EEG = pop_rmbase( EEG, baseline_window);
- %end
- %% STEP 14: Artifact rejection
- all_bad_epochs=0;
- if voltthres_rejection==1 % check voltage threshold rejection
- if interp_epoch==1 % check epoch level channel interpolation
- chans=[]; chansidx=[];chans_labels2=[];
- chans_labels2=cell(1,EEG.nbchan);
- for i=1:EEG.nbchan
- chans_labels2{i}= EEG.chanlocs(i).labels;
- end
- [chans,chansidx] = ismember(frontal_channels, chans_labels2);
- frontal_channels_idx = chansidx(chansidx ~= 0);
- badChans = zeros(EEG.nbchan, EEG.trials);
- badepoch=zeros(1, EEG.trials);
- if isempty(frontal_channels_idx)==1 % check whether there is any frontal channel in dataset to check
- warning('No frontal channels from the list present in the data. Only epoch interpolation will be performed.');
- else
- % find artifaceted epochs by detecting outlier voltage in the specified channels list and remove epoch if artifacted in those channels
- for ch =1:length(frontal_channels_idx)
- EEG = pop_eegthresh(EEG,1, frontal_channels_idx(ch), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset( EEG );
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- for ii=1:size(badChans, 2)
- badepoch(ii)=sum(badChans(:,ii));
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch( EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- if all_bad_epochs==1
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- else
- % Interpolate artifacted data for all reaming channels
- badChans = zeros(EEG.nbchan, EEG.trials);
- % Find artifacted epochs by detecting outlier voltage but don't remove
- for ch=1:EEG.nbchan
- EEG = pop_eegthresh(EEG,1, ch, volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose(EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- tmpData = zeros(EEG.nbchan, EEG.pnts, EEG.trials);
- for e = 1:EEG.trials
- % Initialize variables EEGe and EEGe_interp;
- EEGe = []; EEGe_interp = []; badChanNum = [];
- % Select only this epoch (e)
- EEGe = pop_selectevent( EEG, 'epoch', e, 'deleteevents', 'off', 'deleteepochs', 'on', 'invertepochs', 'off');
- badChanNum = find(badChans(:,e)==1); % find which channels are bad for this epoch
- EEGe_interp = eeg_interp(EEGe,badChanNum); %interpolate the bad channels for this epoch
- tmpData(:,:,e) = EEGe_interp.data; % store interpolated data into matrix
- end
- EEG.data = tmpData; % now that all of the epochs have been interpolated, write the data back to the main file
- % If more than 10% of channels in an epoch were interpolated, reject that epoch
- badepoch=zeros(1, EEG.trials);
- for ei=1:EEG.trials
- NumbadChan = badChans(:,ei); % find how many channels are bad in an epoch
- if sum(NumbadChan) > round((10/100)*EEG.nbchan)% check if more than 10% are bad
- badepoch (ei)= sum(NumbadChan);
- end
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- else % if no epoch level channel interpolation
- EEG = pop_eegthresh(EEG, 1, (1:EEG.nbchan), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax, 0, 0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- end % end of epoch level channel interpolation if statement
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(EEG.reject.rejthresh)==EEG.trials || sum(EEG.reject.rejthresh)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_arm_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG,(EEG.reject.rejthresh), 0);
- EEG = eeg_checkset(EEG);
- end
- end % end of voltage threshold rejection if statement
- % if all epochs are found bad during artifact rejection
- if all_bad_epochs==1
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- else
- total_epochs_after_artifact_rejection(s)=EEG.trials;
- total_AS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'AS')));
- total_QS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'QS')));
- total_W_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'W')));
- total_I_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'I')));
- end
- %% STEP 15: Interpolate deleted channels
- if interp_channels==1
- EEG = eeg_interp(EEG, channels_analysed);
- EEG = eeg_checkset(EEG);
- end
- if numel(FASTbadChans)==0 && numel(ica_prep_badChans)==0
- total_channels_interpolated(s)=0;
- else
- total_channels_interpolated(s)=numel(FASTbadChans)+ numel(ica_prep_badChans);
- end
- %% STEP 16: Rereference data
- EEG = eeg_checkset(EEG);
- reref = [];
- EEG = pop_reref(EEG, reref);
- %% Save processed data
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_arm_processed_data']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_arm_processed_data.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_arm_processed_data.mat']], 'EEG'); % save .mat format
- end
- %% Create the report table for all the data files with relevant preprocessing outputs.
- report_table=table(datafile_names(s)', reference_used_for_faster(s)', faster_bad_channels(s)', ica_preparation_bad_channels(s)', length_ica_data(s)', ...
- total_ICs(s)', ICs_removed(s)', total_epochs_before_artifact_rejection(s)', total_AS(s)', total_QS(s)', total_W(s)', total_I(s)', ...
- total_epochs_after_artifact_rejection(s)', total_AS_after_artifact_rejection(s)', total_QS_after_artifact_rejection(s)', ...
- total_W_after_artifact_rejection(s)', total_I_after_artifact_rejection(s)', total_channels_interpolated(s)');
- report_table.Properties.VariableNames={'folder_list_Resting', 'reference_used_for_faster', 'faster_bad_channels', ...
- 'ica_preparation_bad_channels', 'length_ica_data', 'total_ICs', 'ICs_removed', 'total_epochs_before_artifact_rejection', ...
- 'total_AS', 'total_QS', 'total_W', 'total_I', 'total_epochs_after_artifact_rejection', 'total_AS_after_artifact_rejection', 'total_QS_after_artifact_rejection',...
- 'total_W_after_artifact_rejection', 'total_I_after_artifact_rejection','total_channels_interpolated'};
- writetable(report_table, ['/Volumes/BEHAVEBB/Amy/ADVANCES/EEG/Processed/Report/1m/', subject '_1m_arm_MADE_report_', datestr(now,'dd-mm-yyyy'),'.csv']);
- elseif task == 2 % sResting in bassinet
- % Select events specific to sResting
- EEG = pop_selectevent(EEG3, 'Task', [task],'deleteevents','on'); % just delete other flags/markers, but will NOT delte the EEG data
- %% STEP 12: Segment data into fixed length epochs
- EEG = eeg_checkset(EEG);
- EEG = pop_epoch(EEG, task_event_markers, task_epoch_length, 'epochinfo', 'yes');
- EEG = pop_selectevent( EEG, 'latency','-.1 <= .1','deleteevents','on');
- total_epochs_before_artifact_rejection(s)=EEG.trials;
- total_AS(s) = length(find(strcmp({EEG.event.type},'AS')));
- total_QS(s) = length(find(strcmp({EEG.event.type}, 'QS')));
- total_W(s) = length(find(strcmp({EEG.event.type}, 'W')));
- total_I(s) = length(find(strcmp({EEG.event.type}, 'I')));
- %% STEP 13: Remove baseline
- %if remove_baseline==1
- %EEG = eeg_checkset( EEG );
- %EEG = pop_rmbase( EEG, baseline_window);
- %end
- %% STEP 14: Artifact rejection
- all_bad_epochs=0;
- if voltthres_rejection==1 % check voltage threshold rejection
- if interp_epoch==1 % check epoch level channel interpolation
- chans=[]; chansidx=[];chans_labels2=[];
- chans_labels2=cell(1,EEG.nbchan);
- for i=1:EEG.nbchan
- chans_labels2{i}= EEG.chanlocs(i).labels;
- end
- [chans,chansidx] = ismember(frontal_channels, chans_labels2);
- frontal_channels_idx = chansidx(chansidx ~= 0);
- badChans = zeros(EEG.nbchan, EEG.trials);
- badepoch=zeros(1, EEG.trials);
- if isempty(frontal_channels_idx)==1 % check whether there is any frontal channel in dataset to check
- warning('No frontal channels from the list present in the data. Only epoch interpolation will be performed.');
- else
- % find artifaceted epochs by detecting outlier voltage in the specified channels list and remove epoch if artifacted in those channels
- for ch =1:length(frontal_channels_idx)
- EEG = pop_eegthresh(EEG,1, frontal_channels_idx(ch), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset( EEG );
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- for ii=1:size(badChans, 2)
- badepoch(ii)=sum(badChans(:,ii));
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch( EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- if all_bad_epochs==1
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- else
- % Interpolate artifacted data for all reaming channels
- badChans = zeros(EEG.nbchan, EEG.trials);
- % Find artifacted epochs by detecting outlier voltage but don't remove
- for ch=1:EEG.nbchan
- EEG = pop_eegthresh(EEG,1, ch, volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose(EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- tmpData = zeros(EEG.nbchan, EEG.pnts, EEG.trials);
- for e = 1:EEG.trials
- % Initialize variables EEGe and EEGe_interp;
- EEGe = []; EEGe_interp = []; badChanNum = [];
- % Select only this epoch (e)
- EEGe = pop_selectevent( EEG, 'epoch', e, 'deleteevents', 'off', 'deleteepochs', 'on', 'invertepochs', 'off');
- badChanNum = find(badChans(:,e)==1); % find which channels are bad for this epoch
- EEGe_interp = eeg_interp(EEGe,badChanNum); %interpolate the bad channels for this epoch
- tmpData(:,:,e) = EEGe_interp.data; % store interpolated data into matrix
- end
- EEG.data = tmpData; % now that all of the epochs have been interpolated, write the data back to the main file
- % If more than 10% of channels in an epoch were interpolated, reject that epoch
- badepoch=zeros(1, EEG.trials);
- for ei=1:EEG.trials
- NumbadChan = badChans(:,ei); % find how many channels are bad in an epoch
- if sum(NumbadChan) > round((10/100)*EEG.nbchan)% check if more than 10% are bad
- badepoch (ei)= sum(NumbadChan);
- end
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- else % if no epoch level channel interpolation
- EEG = pop_eegthresh(EEG, 1, (1:EEG.nbchan), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax, 0, 0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- end % end of epoch level channel interpolation if statement
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(EEG.reject.rejthresh)==EEG.trials || sum(EEG.reject.rejthresh)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_sResting_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG,(EEG.reject.rejthresh), 0);
- EEG = eeg_checkset(EEG);
- end
- end % end of voltage threshold rejection if statement
- % if all epochs are found bad during artifact rejection
- if all_bad_epochs==1
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- else
- total_epochs_after_artifact_rejection(s)=EEG.trials;
- total_AS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'AS')));
- total_QS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'QS')));
- total_W_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'W')));
- total_I_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type}, 'I')));
- end
- %% STEP 15: Interpolate deleted channels
- if interp_channels==1
- EEG = eeg_interp(EEG, channels_analysed);
- EEG = eeg_checkset(EEG);
- end
- if numel(FASTbadChans)==0 && numel(ica_prep_badChans)==0
- total_channels_interpolated(s)=0;
- else
- total_channels_interpolated(s)=numel(FASTbadChans)+ numel(ica_prep_badChans);
- end
- %% STEP 16: Rereference data
- EEG = eeg_checkset(EEG);
- reref = [];
- EEG = pop_reref(EEG, reref);
- %% Save processed data
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_sResting_processed_data']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_sResting_processed_data.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_sResting_processed_data.mat']], 'EEG'); % save .mat format
- end
- %% Create the report table for all the data files with relevant preprocessing outputs.
- report_table=table(datafile_names(s)', reference_used_for_faster(s)', faster_bad_channels(s)', ica_preparation_bad_channels(s)', length_ica_data(s)', ...
- total_ICs(s)', ICs_removed(s)', total_epochs_before_artifact_rejection(s)', total_AS(s)', total_QS(s)', total_W(s)', total_I(s)', ...
- total_epochs_after_artifact_rejection(s)', total_AS_after_artifact_rejection(s)', total_QS_after_artifact_rejection(s)', ...
- total_W_after_artifact_rejection(s)', total_I_after_artifact_rejection(s)', total_channels_interpolated(s)');
- report_table.Properties.VariableNames={'folder_list_Resting', 'reference_used_for_faster', 'faster_bad_channels', ...
- 'ica_preparation_bad_channels', 'length_ica_data', 'total_ICs', 'ICs_removed', 'total_epochs_before_artifact_rejection', ...
- 'total_AS', 'total_QS', 'total_W', 'total_I', 'total_epochs_after_artifact_rejection', 'total_AS_after_artifact_rejection', 'total_QS_after_artifact_rejection',...
- 'total_W_after_artifact_rejection', 'total_I_after_artifact_rejection','total_channels_interpolated'};
- writetable(report_table, ['/Volumes/BEHAVEBB/Amy/ADVANCES/EEG/Processed/Report/1m/', subject '_1m_sResting_MADE_report_', datestr(now,'dd-mm-yyyy'),'.csv']);
- elseif task == 3 % MMN
- % Select events specific to MMN
- EEG = pop_selectevent(EEG3, 'Task', [task],'deleteevents','on');
- %% STEP 12: Segment data into fixed length epochs
- EEG = eeg_checkset(EEG);
- EEG = pop_epoch(EEG, task_event_markers, task_epoch_length, 'epochinfo', 'yes');
- EEG = pop_selectevent( EEG, 'latency','-.1 <= .1','deleteevents','on');
- total_epochs_before_artifact_rejection(s)=EEG.trials;
- total_standard(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 )); %need at least 3 standards preceeding to use
- total_deviant(s) = length(find(strcmp({EEG.event.type},'2')));
- total_novel(s) = length(find(strcmp({EEG.event.type},'3')));
- total_standard_AS(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State},'AS'))); %need at least 3 standards preceeding to use
- total_standard_QS(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'QS')));
- total_standard_W(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'W')));
- total_standard_I(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'I')));
- total_deviant_AS(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'AS')));
- total_deviant_QS(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'QS')));
- total_deviant_W(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'W')));
- total_deviant_I(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'I')));
- total_novel_AS(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'AS')));
- total_novel_QS(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'QS')));
- total_novel_W(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'W')));
- total_novel_I(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'I')));
- %% STEP 13: Remove baseline
- EEG = eeg_checkset( EEG );
- baseline_window = [-100,0];
- EEG = pop_rmbase( EEG, baseline_window);
- %% STEP 14: Artifact rejection
- all_bad_epochs=0;
- if voltthres_rejection==1 % check voltage threshold rejection
- if interp_epoch==1 % check epoch level channel interpolation
- chans=[]; chansidx=[];chans_labels2=[];
- chans_labels2=cell(1,EEG.nbchan);
- for i=1:EEG.nbchan
- chans_labels2{i}= EEG.chanlocs(i).labels;
- end
- [chans,chansidx] = ismember(frontal_channels, chans_labels2);
- frontal_channels_idx = chansidx(chansidx ~= 0);
- badChans = zeros(EEG.nbchan, EEG.trials);
- badepoch=zeros(1, EEG.trials);
- if isempty(frontal_channels_idx)==1 % check whether there is any frontal channel in dataset to check
- warning('No frontal channels from the list present in the data. Only epoch interpolation will be performed.');
- else
- % find artifaceted epochs by detecting outlier voltage in the specified channels list and remove epoch if artifacted in those channels
- for ch =1:length(frontal_channels_idx)
- EEG = pop_eegthresh(EEG,1, frontal_channels_idx(ch), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset( EEG );
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- for ii=1:size(badChans, 2)
- badepoch(ii)=sum(badChans(:,ii));
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_MMN_no_usable_data_all_bad_epoch']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_MMN_no_usable_data_all_bad_epoch.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch( EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- if all_bad_epochs==1
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- else
- % Interpolate artifacted data for all reaming channels
- badChans = zeros(EEG.nbchan, EEG.trials);
- % Find artifacted epochs by detecting outlier voltage but don't remove
- for ch=1:EEG.nbchan
- EEG = pop_eegthresh(EEG,1, ch, volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose(EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- tmpData = zeros(EEG.nbchan, EEG.pnts, EEG.trials);
- for e = 1:EEG.trials
- % Initialize variables EEGe and EEGe_interp;
- EEGe = []; EEGe_interp = []; badChanNum = [];
- % Select only this epoch (e)
- EEGe = pop_selectevent( EEG, 'epoch', e, 'deleteevents', 'off', 'deleteepochs', 'on', 'invertepochs', 'off');
- badChanNum = find(badChans(:,e)==1); % find which channels are bad for this epoch
- EEGe_interp = eeg_interp(EEGe,badChanNum); %interpolate the bad channels for this epoch
- tmpData(:,:,e) = EEGe_interp.data; % store interpolated data into matrix
- end
- EEG.data = tmpData; % now that all of the epochs have been interpolated, write the data back to the main file
- % If more than 10% of channels in an epoch were interpolated, reject that epoch
- badepoch=zeros(1, EEG.trials);
- for ei=1:EEG.trials
- NumbadChan = badChans(:,ei); % find how many channels are bad in an epoch
- if sum(NumbadChan) > round((10/100)*EEG.nbchan)% check if more than 10% are bad
- badepoch (ei)= sum(NumbadChan);
- end
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- else % if no epoch level channel interpolation
- EEG = pop_eegthresh(EEG, 1, (1:EEG.nbchan), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax, 0, 0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- end % end of epoch level channel interpolation if statement
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(EEG.reject.rejthresh)==EEG.trials || sum(EEG.reject.rejthresh)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_MMN_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG,(EEG.reject.rejthresh), 0);
- EEG = eeg_checkset(EEG);
- end
- end % end of voltage threshold rejection if statement
- % if all epochs are found bad during artifact rejection
- if all_bad_epochs==1
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- else
- total_epochs_after_artifact_rejection(s)=EEG.trials;
- total_standard_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2)); %need at least 3 standards preceeding to use
- total_deviant_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'2')));
- total_novel_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'3')));
- total_standard_AS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'AS'))); %need at least 3 standards preceeding to use
- total_standard_QS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'QS'))); %need at least 3 standards preceeding to use
- total_standard_W_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'W'))); %need at least 3 standards preceeding to use
- total_standard_I_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'1') & [EEG.event.NumOfPrevTone]>2 & strcmp({EEG.event.State}, 'I'))); %need at least 3 standards preceeding to use
- total_deviant_AS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'AS')));
- total_deviant_QS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'QS')));
- total_deviant_W_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'W')));
- total_deviant_I_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'2') & strcmp({EEG.event.State}, 'I')));
- total_novel_AS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'AS')));
- total_novel_QS_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'QS')));
- total_novel_W_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'W')));
- total_novel_I_after_artifact_rejection(s) = length(find(strcmp({EEG.event.type},'3') & strcmp({EEG.event.State}, 'I')));
- end
- %% STEP 15: Interpolate deleted channels
- if interp_channels==1
- EEG = eeg_interp(EEG, channels_analysed);
- EEG = eeg_checkset(EEG);
- end
- if numel(FASTbadChans)==0 && numel(ica_prep_badChans)==0
- total_channels_interpolated(s)=0;
- else
- total_channels_interpolated(s)=numel(FASTbadChans)+ numel(ica_prep_badChans);
- end
- %% STEP 16: Rereference data
- EEG = eeg_checkset(EEG);
- reref = {'E57','E100'};
- reref_idx=zeros(1, length(reref));
- for rr=1:length(reref)
- reref_idx(rr)=find(strcmp({EEG.chanlocs.labels}, reref{rr}));
- end
- EEG = eeg_checkset(EEG);
- EEG = pop_reref( EEG, reref_idx);
- %% Save processed data
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_MMN_processed_data']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_MMN_processed_data.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_MMN_processed_data.mat']], 'EEG'); % save .mat format
- end
- %% Create the report table for all the data files with relevant preprocessing outputs.
- report_table=table(datafile_names(s)', reference_used_for_faster(s)', faster_bad_channels(s)', ica_preparation_bad_channels(s)', length_ica_data(s)', ...
- total_ICs(s)', ICs_removed(s)', total_epochs_before_artifact_rejection(s)', total_standard(s)', total_deviant(s)', total_novel(s)', ...
- total_standard_AS(s)', total_standard_QS(s)', total_standard_W(s)', total_standard_I(s)', total_deviant_AS(s)', total_deviant_QS(s)', total_deviant_W(s)', total_deviant_I(s)', ...
- total_novel_AS(s)', total_novel_QS(s)', total_novel_W(s)', total_novel_I(s)', total_epochs_after_artifact_rejection(s)', total_standard_after_artifact_rejection(s)', total_deviant_after_artifact_rejection(s)', total_novel_after_artifact_rejection(s)', ...
- total_standard_AS_after_artifact_rejection(s)', total_standard_QS_after_artifact_rejection(s)', total_standard_W_after_artifact_rejection(s)', total_standard_I_after_artifact_rejection(s)', ...
- total_deviant_AS_after_artifact_rejection(s)', total_deviant_QS_after_artifact_rejection(s)', total_deviant_W_after_artifact_rejection(s)', total_deviant_I_after_artifact_rejection(s)', ...
- total_novel_AS_after_artifact_rejection(s)', total_novel_QS_after_artifact_rejection(s)', total_novel_W_after_artifact_rejection(s)', total_novel_I_after_artifact_rejection(s)', total_channels_interpolated(s)');
- report_table.Properties.VariableNames={'folder_list_MMN', 'reference_used_for_faster', 'faster_bad_channels', ...
- 'ica_preparation_bad_channels', 'length_ica_data', 'total_ICs', 'ICs_removed', 'total_epochs_before_artifact_rejection','total_standard', 'total_deviant', 'total_novel',...
- 'total_standard_AS', 'total_standard_QS', 'total_standard_W', 'total_standard_I', 'total_deviant_AS', 'total_deviant_QS', 'total_deviant_W', 'total_deviant_I', ...
- 'total_novel_AS', 'total_novel_QS', 'total_novel_W', 'total_novel_I', 'total_epochs_after_artifact_rejection','total_standard_after_artifact_rejection','total_deviant_after_artifact_rejection','total_novel_after_artifact_rejection', ...
- 'total_standard_AS_after_artifact_rejection', 'total_standard_QS_after_artifact_rejection', 'total_standard_W_after_artifact_rejection', 'total_standard_I_after_artifact_rejection', ...
- 'total_deviant_AS_after_artifact_rejection', 'total_deviant_QS_after_artifact_rejection', 'total_deviant_W_after_artifact_rejection', 'total_deviant_I_after_artifact_rejection', ...
- 'total_novel_AS_after_artifact_rejection', 'total_novel_QS_after_artifact_rejection', 'total_novel_W_after_artifact_rejection', 'total_novel_I_after_artifact_rejection','total_channels_interpolated'};
- writetable(report_table, ['/Volumes/BEHAVEBB/Amy/ADVANCES/EEG/Processed/Report/1m/', subject '_1m_MMN_MADE_report_', datestr(now,'dd-mm-yyyy'),'.csv']);
- elseif task == 4 % VEP
- % Select events specific to VEP
- EEG = pop_selectevent(EEG3, 'Task', [task],'deleteevents','on');
- %% STEP 12: Segment data into fixed length epochs
- EEG = eeg_checkset(EEG);
- EEG = pop_epoch(EEG, task_event_markers, task_epoch_length, 'epochinfo', 'yes');
- EEG = pop_selectevent( EEG, 'latency','-.1 <= .1','deleteevents','on');
- total_vep=EEG.trials;
- total_AS_vep=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'AS')));
- total_QS_vep=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'QS')));
- total_I_vep=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'I')));
- total_W_vep=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'W')));
- %% STEP 13: Remove baseline
- EEG = eeg_checkset( EEG );
- baseline_window = [-200,0];
- EEG = pop_rmbase( EEG, baseline_window);
- %% STEP 14: Artifact rejection
- all_bad_epochs=0;
- if voltthres_rejection==1 % check voltage threshold rejection
- if interp_epoch==1 % check epoch level channel interpolation
- chans=[]; chansidx=[];chans_labels2=[];
- chans_labels2=cell(1,EEG.nbchan);
- for i=1:EEG.nbchan
- chans_labels2{i}= EEG.chanlocs(i).labels;
- end
- [chans,chansidx] = ismember(frontal_channels, chans_labels2);
- frontal_channels_idx = chansidx(chansidx ~= 0);
- badChans = zeros(EEG.nbchan, EEG.trials);
- badepoch=zeros(1, EEG.trials);
- if isempty(frontal_channels_idx)==1 % check whether there is any frontal channel in dataset to check
- warning('No frontal channels from the list present in the data. Only epoch interpolation will be performed.');
- else
- % find artifaceted epochs by detecting outlier voltage in the specified channels list and remove epoch if artifacted in those channels
- for ch =1:length(frontal_channels_idx)
- EEG = pop_eegthresh(EEG,1, frontal_channels_idx(ch), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset( EEG );
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- for ii=1:size(badChans, 2)
- badepoch(ii)=sum(badChans(:,ii));
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_VEP_no_usable_data_all_bad_epoch']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_VEP_no_usable_data_all_bad_epoch.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch( EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- if all_bad_epochs==1
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- else
- % Interpolate artifacted data for all reaming channels
- badChans = zeros(EEG.nbchan, EEG.trials);
- % Find artifacted epochs by detecting outlier voltage but don't remove
- for ch=1:EEG.nbchan
- EEG = pop_eegthresh(EEG,1, ch, volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax,0,0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose(EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- badChans(ch,:) = EEG.reject.rejglobal;
- end
- tmpData = zeros(EEG.nbchan, EEG.pnts, EEG.trials);
- for e = 1:EEG.trials
- % Initialize variables EEGe and EEGe_interp;
- EEGe = []; EEGe_interp = []; badChanNum = [];
- % Select only this epoch (e)
- EEGe = pop_selectevent( EEG, 'epoch', e, 'deleteevents', 'off', 'deleteepochs', 'on', 'invertepochs', 'off');
- badChanNum = find(badChans(:,e)==1); % find which channels are bad for this epoch
- EEGe_interp = eeg_interp(EEGe,badChanNum); %interpolate the bad channels for this epoch
- tmpData(:,:,e) = EEGe_interp.data; % store interpolated data into matrix
- end
- EEG.data = tmpData; % now that all of the epochs have been interpolated, write the data back to the main file
- % If more than 10% of channels in an epoch were interpolated, reject that epoch
- badepoch=zeros(1, EEG.trials);
- for ei=1:EEG.trials
- NumbadChan = badChans(:,ei); % find how many channels are bad in an epoch
- if sum(NumbadChan) > round((10/100)*EEG.nbchan)% check if more than 10% are bad
- badepoch (ei)= sum(NumbadChan);
- end
- end
- badepoch=logical(badepoch);
- end
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(badepoch)==EEG.trials || sum(badepoch)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG, badepoch, 0);
- EEG = eeg_checkset(EEG);
- end
- else % if no epoch level channel interpolation
- EEG = pop_eegthresh(EEG, 1, (1:EEG.nbchan), volt_threshold(1), volt_threshold(2), EEG.xmin, EEG.xmax, 0, 0);
- EEG = eeg_checkset(EEG);
- EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);
- end % end of epoch level channel interpolation if statement
- % If all epochs are artifacted, save the dataset and ignore rest of the preprocessing for this subject.
- if sum(EEG.reject.rejthresh)==EEG.trials || sum(EEG.reject.rejthresh)+1==EEG.trials
- all_bad_epochs=1;
- warning(['No usable data for datafile', [datafile_names{s} '_Merged']]);
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_VEP_no_usable_data_all_bad_epochs.mat']], 'EEG'); % save .mat format
- end
- else
- EEG = pop_rejepoch(EEG,(EEG.reject.rejthresh), 0);
- EEG = eeg_checkset(EEG);
- end
- end % end of voltage threshold rejection if statement
- % if all epochs are found bad during artifact rejection
- if all_bad_epochs==1
- total_epochs_after_artifact_rejection(s)=0;
- total_channels_interpolated(s)=0;
- continue % ignore rest of the processing and go to next datafile
- else
- total_vep_after_artifact_rejection=EEG.trials;
- total_AS_vep_artifact_rejection=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'AS')));
- total_QS_vep_artifact_rejection=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'QS')));
- total_I_vep_artifact_rejection=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'I')));
- total_W_vep_artifact_rejection=length(find(strcmp({EEG.event.type},'DIN1') & strcmp({EEG.event.State}, 'W')));
- end
- %% STEP 15: Interpolate deleted channels
- if interp_channels==1
- EEG = eeg_interp(EEG, channels_analysed);
- EEG = eeg_checkset(EEG);
- end
- if numel(FASTbadChans)==0 && numel(ica_prep_badChans)==0
- total_channels_interpolated(s)=0;
- else
- total_channels_interpolated(s)=numel(FASTbadChans)+ numel(ica_prep_badChans);
- end
- %% STEP 16: Rereference data
- EEG = eeg_checkset(EEG);
- reref = [];
- reref_idx=zeros(1, length(reref));
- for rr=1:length(reref)
- reref_idx(rr)=find(strcmp({EEG.chanlocs.labels}, reref{rr}));
- end
- EEG = eeg_checkset(EEG);
- EEG = pop_reref( EEG, reref_idx);
- %% Save processed data
- if output_format==1
- EEG = eeg_checkset(EEG);
- EEG = pop_editset(EEG, 'setname', [datafile_names{s} '_VEP_processed_data']);
- EEG = pop_saveset(EEG, 'filename', [datafile_names{s} '_VEP_processed_data.set'],'filepath', [output_location filesep 'processed_data' filesep]); % save .set format
- elseif output_format==2
- save([[output_location filesep 'processed_data' filesep] [datafile_names{s} '_VEP_processed_data.mat']], 'EEG'); % save .mat format
- end
- %% Create the report table for all the data files with relevant preprocessing outputs.
- report_table=table(datafile_names(s)', reference_used_for_faster(s)', faster_bad_channels(s)', ica_preparation_bad_channels(s)', length_ica_data(s)', ...
- total_ICs(s)', ICs_removed(s)', total_vep(s)', total_AS_vep(s)',total_QS_vep(s)',total_I_vep(s)',total_W_vep(s)', total_vep_after_artifact_rejection(s)', ...
- total_AS_vep_artifact_rejection(s)', total_QS_vep_artifact_rejection(s)', total_I_vep_artifact_rejection(s)', total_W_vep_artifact_rejection(s)', total_channels_interpolated(s)');
- report_table.Properties.VariableNames={'folder_list_VEP', 'reference_used_for_faster', 'faster_bad_channels', ...
- 'ica_preparation_bad_channels', 'length_ica_data', 'total_ICs', 'ICs_removed', 'total_vep', 'total_AS_vep', 'total_QS_vep', 'total_I_vep', 'total_W_vep', 'total_vep_after_artifact_rejection', ...
- 'total_AS_vep_artifact_rejection', 'total_QS_vep_artifact_rejection', 'total_I_vep_artifact_rejection', 'total_W_vep_artifact_rejection','total_channels_interpolated'};
- writetable(report_table, ['/Volumes/BEHAVEBB/Amy/ADVANCES/EEG/Processed/Report/1m/', subject '_1m_VEP_MADE_report_', datestr(now,'dd-mm-yyyy'),'.csv']);
- end
- end
- end % end of loop
SA-MADE_pipeline_multiple_participants.m at commit 0f6dc49, no license · at the source
Overview
13 affiliations
- Department of Psychology, The Ohio State University, Columbus, OH, United States
- Institute of Developmental Psychology, Faculty of Psychology, Beijing Normal University, Beijing, China
- Department of Environmental Health Sciences, Mailman School of Public Health, Columbia University Irving Medical Center, New York, NY, United States
- Steinhardt School of Culture, Education, and Human Development, New York University, New York, NY, United States
- The Pew Charitable Trusts, Washington DC, United States
- Division of Developmental Neuroscience, New York State Psychiatric Institute, New York, NY, United States
- Department of Psychological & Brain Sciences, University of Iowa, IA, United States
- Department of Child and Adolescent Psychiatry, NYU Grossman School of Medicine, New York, NY, United States
- Columbia Center for Children’s Environmental Health, Department of Environmental Health Sciences, Mailman School of Public Health, Columbia University, New York, NY, United States
- Neuroscience and Cognitive Science Program, University of Maryland, College Park, MD, United States
- Department of Human Development and Quantitative Methodology, University of Maryland, College Park, MD, United States
- Department of Psychiatry and Behavioral Health and the Clinical and Translational Science Institute, The Ohio State University, Columbus, OH, United States
- The Child Mind Institute, New York, NY, United States
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repository
Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.
EBBLab/SA-MADE
0f6dc49bc1f48f7e90cb776498579865d9047cd8, 7 October 2025Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
4 files
- Labeling_MMN_multi_parti
cipant.m , MATLAB, 56 lines, 1 match - Reshaping.m, MATLAB, 89 lines
- SA-MADE_pipeline_multipl
e_participants.m , MATLAB, 1,672 lines, 2 matches - README.md, Text, 7 lines
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 3 scripts, each with its path and the digest of its content;
- 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it says that the data are available on request
Read it in the paper: doi.org/10.1016/j.dcn.2026.101727.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 29 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 13 authors, 5 keywords, 10 MeSH terms, 3 funders, 44 references.
Cite
This paper
Yang, H., Liu, R., Simon, K. R., Gimenez, L. A., Bowers, M. E., Pini, N., Leach, S. C., Salas, L., Shuffrey, L. C., Fifer, W. P., Herbstman, J., Fox, N. A., & Margolis, A. E. (2026). Neonatal brain activity across sleep states: Evidence from resting EEG and auditory event-related potentials. Developmental cognitive neuroscience, 79, 101727. https://
BibTeX
@article{yang2026neonata
author = {Yang, Huiyu and Liu, Ran and Simon, Katrina R and Gimenez, Lissete A and Bowers, Maureen E and Pini, Nicolò and Leach, Stephanie C and Salas, Leilani and Shuffrey, Lauren C and Fifer, William P and Herbstman, Julie and Fox, Nathan A and Margolis, Amy E},
title = {{Neonatal brain activity across sleep states: Evidence from resting EEG and auditory event-related potentials}},
journal = {Developmental cognitive neuroscience},
year = {2026},
month = apr,
volume = {79},
pages = {101727},
publisher = {Elsevier},
issn = {1878-9293},
doi = {10.1016/
url = {https://
pmid = {42054975},
pmcid = {PMC13141766}
}
RIS
TY - JOUR
AU - Yang, Huiyu
AU - Liu, Ran
AU - Simon, Katrina R
AU - Gimenez, Lissete A
AU - Bowers, Maureen E
AU - Pini, Nicolò
AU - Leach, Stephanie C
AU - Salas, Leilani
AU - Shuffrey, Lauren C
AU - Fifer, William P
AU - Herbstman, Julie
AU - Fox, Nathan A
AU - Margolis, Amy E
TI - Neonatal brain activity across sleep states: Evidence from resting EEG and auditory event-related potentials
T2 - Developmental cognitive neuroscience
J2 - Dev Cogn Neurosci
PY - 2026
DA - 2026/
VL - 79
SP - 101727
SN - 1878-9293
PB - Elsevier
DO - 10.1016/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1016/
"type": "article-journal",
"title": "Neonatal brain activity across sleep states: Evidence from resting EEG and auditory event-related potentials",
"container-title": "Developmental cognitive neuroscience",
"author": [
{
"family": "Yang",
"given": "Huiyu"
},
{
"family": "Liu",
"given": "Ran"
},
{
"family": "Simon",
"given": "Katrina R"
},
{
"family": "Gimenez",
"given": "Lissete A"
},
{
"family": "Bowers",
"given": "Maureen E"
},
{
"family": "Pini",
"given": "Nicolò"
},
{
"family": "Leach",
"given": "Stephanie C"
},
{
"family": "Salas",
"given": "Leilani"
},
{
"family": "Shuffrey",
"given": "Lauren C"
},
{
"family": "Fifer",
"given": "William P"
},
{
"family": "Herbstman",
"given": "Julie"
},
{
"family": "Fox",
"given": "Nathan A"
},
{
"family": "Margolis",
"given": "Amy E"
}
],
"container-title-short":
"volume": "79",
"page": "101727",
"DOI": "10.1016/
"PMID": "42054975",
"PMCID": "PMC13141766",
"ISSN": "1878-9293",
"publisher": "Elsevier",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
20
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1002/dev.70128 [code]
- Socioeconomic Status, the Home Language Environment, Noise Exposure, and the Mismatch Response in Infancy.Journal: Developmental psychobiologyIn common: developmental, EEG, 6 references, author Katrina R Simon
- [2] doi:10.1016/j.dcn.2026.101741
- Pediatric resting EEG collection, preprocessing, and analysis: A systematic review.Journal: Developmental cognitive neuroscienceIn common: developmental, EEG, 6 references
- [3] doi:10.1093/cercor/bhag077 [code]
- The longitudinal development of intrinsic timescales in infancy and their relation to alpha brain rhythm.Journal: Cerebral cortex (New York, N.Y. : 1991)In common: EEGLAB, developmental, EEG, 3 references
- [4] doi:10.3389/fneur.2026.1791834 [code]
- Minimum data requirements and automated preprocessing for reliable EEG biomarkers in Rett syndrome.Journal: Frontiers in neurologyIn common: EEGLAB, EEG, 3 references
- [5] doi:10.1111/ejn.70670 [code]
- Cross-Night Modulation of Change Detection ERPs to Foreign Speech Sound Features During N2 Sleep.Journal: The European journal of neuroscienceIn common: EEGLAB, EEG, 3 references
- [6] doi:10.1093/sleep/zsaf410 [code]
- Does twitch-spindle coupling differ between N2 and N3 sleep in 6-month-olds?Journal: SleepIn common: developmental, EEG, 3 references
- [7] doi:10.7554/elife.107081 [code]
- Cortical motor activity modulates respiration and reduces apnoea in neonates.Journal: eLifeIn common: EEGLAB, developmental, EEG, 1 reference
- [8] doi:10.1016/j.isci.2026.115878 [code]
- Twitching in sleeping premature infants provides a sensitive behavioral assay of early motor control.Journal: iScienceIn common: developmental, 2 references
- [9] doi:10.1038/s41562-026-02533-1 [code]
- Fluctuations in arousal reflect latent state transitions that facilitate behavioural optimization.Journal: Nature human behaviourIn common: EEGLAB, EEG, 2 references
- [10] doi:10.1038/s41598-026-47785-z [code]
- Modulations of the P3b effect as a function of bilingual language experience.Journal: Scientific reportsIn common: EEGLAB, EEG, 2 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 3 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:b9ec10f31a4353d9…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
