Commits (1)
......@@ -45,23 +45,6 @@
%
% Code written by James A. Desjardins, Allan Campopiano, and Andrew Lofts
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
function version = eegplugin_vised_marks(fig, try_strings, catch_strings)
......
......@@ -39,20 +39,6 @@
% Authors: Hilit Serby, Arnaud Delorme & Scott Makeig, SCCN/INC/UCSD, Sep 02, 2005
% Copyright (C) Hilit Serby, SCCN, INC, UCSD, Sep 02, 2005, hilit@sccn.ucsd.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function EEG = marks_eeg_regepochs(EEG, varargin)
......@@ -68,9 +54,9 @@ end;
% test input variables
% --------------------
if ~isstruct(EEG) || ~isfield(EEG,'event')
error('first argument must be an EEG structure')
error('first argument must be an EEG structure')
elseif EEG.trials > 1
error('input dataset must be continuous data (1 epoch)');
error('input dataset must be continuous data (1 epoch)');
end
if nargin > 1 && ~ischar(varargin{1})
......@@ -89,15 +75,15 @@ g = finputcheck(options, { 'recurrence' 'real' [] 1;
if ischar(g), error(g); end;
if g.recurrence < 0 || g.recurrence > EEG.xmax
error('recurrence_interval out of bounds');
error('recurrence_interval out of bounds');
end
if nargin < 3
g.limits = [0 g.recurrence];
g.limits = [0 g.recurrence];
end
if length(g.limits) ~= 2 || g.limits(2) <= g.limits(1)
error('epoch limits must be a 2-vector [minsec maxsec]')
error('epoch limits must be a 2-vector [minsec maxsec]')
end
% calculate number of events to add
......@@ -111,7 +97,7 @@ nu = floor(en / (g.recurrence * EEG.srate)); % number of type 'X' events to add
% nu = length((bg+g.recurrence):g.recurrence:(en-g.recurrence)); % number of 'X' events, one every 'g.recurrence' sec
if nu < 1
error('specified recurrence_interval too long')
error('specified recurrence_interval too long')
end
% print info on commandline
......@@ -131,14 +117,14 @@ end
nurevents = length(EEG.urevent);
for k = 1:nu
if rem(k, 40)
fprintf('.')
else
fprintf('%d',k)
end
if k == 40 || ( k > 40 && ~rem(k - 40, 70))
fprintf('\n');
end
if rem(k, 40)
fprintf('.')
else
fprintf('%d',k)
end
if k == 40 || ( k > 40 && ~rem(k - 40, 70))
fprintf('\n');
end
EEG.event(nevents + k).type = g.eventtype;
EEG.event(nevents + k).latency = round(g.recurrence * (k-1) * EEG.srate + 1);
......
......@@ -46,33 +46,19 @@
% began {default: 'yes'}
%
% Outputs:
% OUTEEG - output dataset
% OUTEEG - output dataset
% indices - indices of accepted events
%
% Authors: Arnaud Delorme and Hilit Serby, SCCN, INC, UCSD, 2001
%
% See also: eeglab, epoch
% See also: eeglab, epoch()
% deprecated
% 'timeunit' - Time unit ['seconds'|'points'] If 'seconds,' consider events
% times to be in seconds. If 'points,' consider events as
% indices into the data array. {default: 'points'}
% Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% Authors: Hilit Serby, Arnaud Delorme & Scott Makeig, SCCN/INC/UCSD, Sep 02, 2005
% Copyright (C) Hilit Serby, SCCN, INC, UCSD, Sep 02, 2005, hilit@sccn.ucsd.edu
% 01-25-02 reformated help & license -ad
% 02-13-02 introduction of 'key', val arguments -ad
......@@ -83,7 +69,7 @@
function [EEG, indices, com] = marks_pop_epoch( EEG, events, lim, varargin );
if nargin < 1
help pop_epoch;
help pop_epoch;
return;
end;
com = '';
......@@ -105,20 +91,20 @@ if isempty(EEG.event)
end;
if ~isfield(EEG.event, 'latency'),
disp( 'Absent latency field in event array/structure: must name one of the fields ''latency''');
beep; return;
beep; return;
end;
OLDEEG = EEG;
if nargin < 3
% popup window parameters
% -----------------------
promptstr = { strvcat('Time-locking event type(s) ([]=all):', ...
promptstr = { strvcat('Time-locking event type(s) ([]=all):', ...
'Select ''Edit > Event values'' to see type values.'), ...
'Epoch limits [start, end] in seconds:', ...
'Name for the new dataset:', ...
'Out-of-bounds EEG rejection limits ([min max], []=none):' };
cbevent = ['if ~isfield(EEG.event, ''type'')' ...
cbevent = ['if ~isfield(EEG.event, ''type'')' ...
' errordlg2(''No type field'');' ...
'else' ...
' tmpevent = EEG.event;' ...
......@@ -133,27 +119,27 @@ if nargin < 3
'end;' ...
'clear tmps tmpevent tmpv tmpstr tmpfieldnames;' ];
geometry = { [2 1 0.5] [2 1 0.5] [2 1.5] [2 1 0.5] };
uilist = { { 'style' 'text' 'string' 'Time-locking event type(s) ([]=all)' } ...
{ 'style' 'edit' 'string' '' 'tag' 'events' } ...
{ 'style' 'pushbutton' 'string' '...' 'callback' cbevent } ...
{ 'style' 'text' 'string' 'Epoch limits [start, end] in seconds' } ...
{ 'style' 'edit' 'string' '-1 2' } ...
{ } ...
{ 'style' 'text' 'string' 'Name for the new dataset' } ...
{ 'style' 'edit' 'string' fastif(isempty(EEG.setname), '', [ EEG.setname ' epochs' ]) } ...
{ 'style' 'text' 'string' 'Out-of-bounds EEG limits if any [min max]' } ...
{ 'style' 'edit' 'string' '' } { } };
geometry = { [2 1 0.5] [2 1 0.5] [2 1.5] [2 1 0.5] };
uilist = { { 'style' 'text' 'string' 'Time-locking event type(s) ([]=all)' } ...
{ 'style' 'edit' 'string' '' 'tag' 'events' } ...
{ 'style' 'pushbutton' 'string' '...' 'callback' cbevent } ...
{ 'style' 'text' 'string' 'Epoch limits [start, end] in seconds' } ...
{ 'style' 'edit' 'string' '-1 2' } ...
{ } ...
{ 'style' 'text' 'string' 'Name for the new dataset' } ...
{ 'style' 'edit' 'string' fastif(isempty(EEG.setname), '', [ EEG.setname ' epochs' ]) } ...
{ 'style' 'text' 'string' 'Out-of-bounds EEG limits if any [min max]' } ...
{ 'style' 'edit' 'string' '' } { } };
result = inputgui( geometry, uilist, 'pophelp(''pop_epoch'')', 'Extract data epochs - pop_epoch()');
if length(result) == 0 return; end;
result = inputgui( geometry, uilist, 'pophelp(''pop_epoch'')', 'Extract data epochs - pop_epoch()');
if length(result) == 0 return; end;
if strcmpi(result{1}, '[]'), result{1} = ''; end;
if ~isempty(result{1})
if strcmpi(result{1}(1),'''') % If event type appears to be in single-quotes, use comma
if strcmpi(result{1}, '[]'), result{1} = ''; end;
if ~isempty(result{1})
if strcmpi(result{1}(1),'''') % If event type appears to be in single-quotes, use comma
% and single-quote as delimiter between event types. toby 2.24.2006
% fixed Arnaud May 2006
events = eval( [ '{' result{1} '}' ] );
events = eval( [ '{' result{1} '}' ] );
else events = parsetxt( result{1});
end;
else events = {};
......@@ -172,8 +158,8 @@ end;
% create structure
% ----------------
if ~isempty(args)
try, g = struct(args{:});
catch, disp('pop_epoch(): wrong syntax in function arguments'); return; end;
try, g = struct(args{:});
catch, disp('pop_epoch(): wrong syntax in function arguments'); return; end;
else
g = [];
end;
......@@ -230,7 +216,7 @@ Ievent = sort(Ievent);
alllatencies = tmpeventlatency(Ievent);
if isempty(alllatencies)
error('pop_epoch(): empty epoch range (no epochs were found).'); return;
error('pop_epoch(): empty epoch range (no epochs were found).'); return;
end;
fprintf('pop_epoch():%d epochs selected\n', length(alllatencies));
......@@ -252,7 +238,6 @@ try
return;
else
disp('AMICA probabilities not compatible with size of data, model probabilities cannot be epoched...')
end
end
end
......@@ -266,45 +251,45 @@ end
% ------------------------------------------------------------------------------
tmpevents = EEG.event;
if lim(1) > 0 && ischar(EEG.event(1).type)
% go through all onset latencies
for Z1 = length(alllatencies):-1:1
% if there is any event in between trigger and epoch onset which are boundary events
selEvt = find([tmpevents.latency] > alllatencies(Z1) & [tmpevents.latency] < alllatencies(Z1) + lim(1) * EEG.srate);
selEvt = selEvt(strcmp({tmpevents(selEvt).type}, 'boundary'));
if any(selEvt)
if sum([tmpevents(selEvt).duration]) > lim(1) * EEG.srate
alllatencies(Z1) = [];
else
% correct the latencies by the duration of the data that were cutout
alllatencies(Z1) = alllatencies(Z1) - sum([tmpevents(selEvt).duration]);
end;
end
end
% go through all onset latencies
for Z1 = length(alllatencies):-1:1
% if there is any event in between trigger and epoch onset which are boundary events
selEvt = find([tmpevents.latency] > alllatencies(Z1) & [tmpevents.latency] < alllatencies(Z1) + lim(1) * EEG.srate);
selEvt = selEvt(strcmp({tmpevents(selEvt).type}, 'boundary'));
if any(selEvt)
if sum([tmpevents(selEvt).duration]) > lim(1) * EEG.srate
alllatencies(Z1) = [];
else
% correct the latencies by the duration of the data that were cutout
alllatencies(Z1) = alllatencies(Z1) - sum([tmpevents(selEvt).duration]);
end;
end
end
end
if lim(2) < 0 && ischar(EEG.event(1).type)
% go through all onset latencies
for Z1 = length(alllatencies):-1:1
% if there is any event in between trigger and epoch onset which are boundary events
selEvt = find([tmpevents.latency] < alllatencies(Z1) & [tmpevents.latency] > alllatencies(Z1) + lim(2) * EEG.srate);
selEvt = selEvt(strcmp({tmpevents(selEvt).type}, 'boundary'));
if any(selEvt)
if sum([tmpevents(selEvt).duration]) > -lim(2) * EEG.srate
alllatencies(Z1) = [];
else
% correct the latencies by the duration of the data that were cutout
alllatencies(Z1) = alllatencies(Z1) + sum([tmpevents(selEvt).duration]);
end;
end
end
% go through all onset latencies
for Z1 = length(alllatencies):-1:1
% if there is any event in between trigger and epoch onset which are boundary events
selEvt = find([tmpevents.latency] < alllatencies(Z1) & [tmpevents.latency] > alllatencies(Z1) + lim(2) * EEG.srate);
selEvt = selEvt(strcmp({tmpevents(selEvt).type}, 'boundary'));
if any(selEvt)
if sum([tmpevents(selEvt).duration]) > -lim(2) * EEG.srate
alllatencies(Z1) = [];
else
% correct the latencies by the duration of the data that were cutout
alllatencies(Z1) = alllatencies(Z1) + sum([tmpevents(selEvt).duration]);
end;
end
end
end
% select event time format and epoch
% ----------------------------------
switch lower( g.timeunit )
case 'points', [EEG.data tmptime indices epochevent tmp reallim]= epoch(EEG.data, alllatencies, [lim(1) lim(2)]*EEG.srate, ...
case 'points', [EEG.data tmptime indices epochevent tmp reallim]= epoch(EEG.data, alllatencies, [lim(1) lim(2)]*EEG.srate, ...
'valuelim', g.valuelim, 'allevents', tmpeventlatency);
tmptime = tmptime/EEG.srate;
case 'seconds', [EEG.data tmptime indices epochevent tmp reallim]= epoch(EEG.data, alllatencies, lim, 'valuelim', g.valuelim, ...
tmptime = tmptime/EEG.srate;
case 'seconds', [EEG.data tmptime indices epochevent tmp reallim]= epoch(EEG.data, alllatencies, lim, 'valuelim', g.valuelim, ...
'srate', EEG.srate, 'allevents', tmpeventlatency);
otherwise, disp('pop_epoch(): invalid event time format'); beep; return;
end;
......
% marks_add_label() - Add a new mark for the specified mark info type.
%
% Usage:
% >> EEGout = marks_add_label(EEG.marks,'time_info',{'new_time_flag',[1,0,0],time_flags});
%
% Required input:
% EEG.marks - EEG marks structure.
% info_type - type of mark ('time_info', 'chan_info', or 'comp_info')
% mark_prop - cell array of {label,color,flags}
%
% Outputs:
% EEG.marks - the updated EEG.marks structure.
%
% See also: marks_init();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function marks_struct = marks_add_label(marks_struct,info_type,mark_prop)
if isempty(marks_struct)
......@@ -79,4 +103,4 @@ switch info_type
otherwise
disp('check field string...');
end
\ No newline at end of file
end
% marks_init() - Initialize the EEG.marks structure if it doesn't exist yet. It creates a
% field for time_info, chan_info, and comp_info with nothing initially flagged.
%
% Usage:
% >> EEGout = marks_init(size(EEG.data)); % default if no ICA has been performed on the data
% >> EEGout = marks_init(size(EEG.data),min(size(EEG.icaweights))); % if ICA had been performed
%
% Required input:
% datasize - the size of EEG.data.
%
% Optional input:
% 'ncomps' - the number of components extracted by the ICA decomposition.
%
% Outputs:
% EEG.marks - the newly created EEG.marks structure.
%
% See also: marks_add_label();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function marks_struct = marks_init(datasize,ncomps)
disp('Building initial marks structure...');
......@@ -16,4 +44,4 @@ marks_struct=[];
marks_struct=marks_add_label(marks_struct,'comp_info',{'manual',[.7,.7,.7],[.7,.7,.7],-1,[]});
end
%end
\ No newline at end of file
% ADAPTED FROM eeg_regepochs()
% See also: pop_editeventvals(), pop_epoch(), rmbase();
%
% Authors: Hilit Serby, Arnaud Delorme & Scott Makeig, SCCN/INC/UCSD, Sep 02, 2005
% Copyright (C) Hilit Serby, SCCN, INC, UCSD, Sep 02, 2005, hilit@sccn.ucsd.edu
% marks_continuous2epochs() - Convert a continuous dataset into consecutive epochs of
% a specified regular length by adding dummy events of type
% and epoch the data around these events. Alternatively
% only insert events for extracting these epochs.
% May be used to split up continuous data for
% artifact rejection followed by ICA decomposition.
% The computed EEG.icaweights and EEG.icasphere matrices
% may then be exported to the continuous dataset and/or
% to its epoched descendents.
% Usage:
% >> EEGout = marks_continuous2epochs(EEG); % use defaults
% >> EEGout = marks_continuous2epochs(EEG, 'key', val, ...);
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% Optional inputs:
% 'recurrence' - [in s] the regular recurrence interval of the dummy
% events used as time-locking events for the
% consecutive epochs {default: 1 s}
% 'limits' - [minsec maxsec] latencies relative to the time-locking
% events to use as epoch boundaries. Stated epoch length
% will be reduced by one data point to avoid overlaps
% {default: [0 recurrence_interval]}
% 'rmbase' - [NaN|latency] remove baseline (s). NaN does not remove
% baseline. 0 remove the pre-0 baseline. To
% remove the full epoch baseline, enter a value
% larger than the upper epoch limit. Default is 0.
% 'eventtype' - [string] name for the event type. Default is 'X'
% 'extractepochs' - ['on'|'off'] extract data epochs ('on') or simply
% insert events ('off'). Default is 'on'.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% Outputs:
% EEGout - the input EEG structure separated into consecutive epochs.
%
% See also: pop_editeventvals(), pop_epoch(), rmbase();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function [EEG] = marks_continuous2epochs(EEG, varargin)
......
% marks_epochs2continuous() - Concatenate a windowed dataset (EEG.trials > 1) back into a continuous dataset.
%
% Usage:
% >> EEGout = marks_epochs2continuous(EEG);
%
% Required input:
% EEG - EEG windowed data structure (EEG.trials > 1)
%
% Outputs:
% EEGout - the input EEG structure concatenated back into a single continuous epoch.
%
% See also: pop_editeventvals(), pop_epoch(), rmbase();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function EEG=marks_epochs2continuous(EEG)
evtcount=0;
......@@ -166,4 +190,4 @@ if isfield(EEG,'marks');
EEG=marks_moveflags(EEG,2);
end
EEG=eeg_checkset(EEG);
\ No newline at end of file
EEG=eeg_checkset(EEG);
% chan_neighbour_r() - Find channels with an unusually high correlation (bridged)
% or an unusually low correlation (low_r) to a specified number
% of neighbouring channels, given a specific set of criteria.
%
% Usage:
% >> [EEG,m_neighbr_r,chandist,y,chan_win_sd] = chan_neighbour_r(EEG, ...
% [n_nbr_ch],'max', ...
% 'chan_inds',chan_inds, ...
% 'epoch_inds',epoch_inds, ...
% 'plot_figs','off');
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
% nneigbr - number of neighbouring channels to correlate to.
% method - ['max'|'mean'|'trimmean']
%
% Optional inputs:
% 'chan_inds' - the indices of the channels on which to calculate the variance.
% The default is all the channels or components.
% 'epoch inds' - the indices of the time points on which to calculate the variance.
% The default is all the time points.
% 'plot_figs' - Set to 'on' to plot a figure representing the channel variance (default: 'off').
%
% Outputs:
% EEG - the updated EEG data structure.
% m_neighbr_r - nearest neighbor r values depending on method specified as input.
% chandist - X,Y,Z distances from each neighbouring channel.
% y - indices of sorted channel distances.
% chan_win_sd - array of channel standard deviations.
%
% See also: marks_array2flags(), chan_neighbour_r(), fisherz();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function [EEG,m_neigbr_r,chandist,y,chan_win_sd]=chan_neighbour_r(EEG,nneigbr,method,varargin)
g=struct(varargin{:});
......@@ -83,4 +126,4 @@ switch(method);
m_neigbr_r=trimmean(abs(c_neigbr_r),20,3);
end
chan_win_sd=squeeze(std(EEG.data,[],2));
\ No newline at end of file
chan_win_sd=squeeze(std(EEG.data,[],2));
% chan_variance() - Returns an array of variance values for each channel. The variance
% measure could be the standard deviation (default), the absolute distance
% from the mean, or the deviation from the mean of the spectral distribution.
%
% Usage:
% >> [EEG,data_sd]=chan_variance(EEG,'data_field','data','chan_inds',chan_inds,'epoch_inds',epoch_inds,'plot_figs','off');
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
%
% Optional inputs:
% 'data_field' - this is either 'data' (default) or 'icaact', depending on
% whether we want the variance of the scalp channels or the
% the variance of the independent components.
% 'chan_inds' - the indices of the channels on which to calculate the variance.
% The default is all the channels or components.
% 'epoch inds' - the indices of the time points on which to calculate the variance.
% The default is all the time points.
% 'plot_figs' - Set to 'on' to plot a figure representing the channel variance (default: 'off').
% 'varmeasure' - The variance measure to use. This can be either 'sd', 'absmean', or 'spect' (default: 'sd')
% 'detrend' - Detrend the data before calculating the variance (default: 'off').
% 'spectrange' - The frequency range of the spectrum to be considered if 'spect' option chosen as the varmeasure.
%
% Outputs:
% data_sd - the resulting array of variance values.
%
% See also: marks_array2flags(), chan_neighbour_r(), fisherz();
%
% Authors: Hilit Serby, Arnaud Delorme & Scott Makeig, SCCN/INC/UCSD, Sep 02, 2005
% Copyright (C) Hilit Serby, SCCN, INC, UCSD, Sep 02, 2005, hilit@sccn.ucsd.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function [EEG,data_sd]=chan_variance(EEG,varargin)
g=struct(varargin{:});
......@@ -51,4 +98,4 @@ if strcmp(g.plot_figs,'on');
figure;surf(double(data_sd),'LineStyle','none');
axis('tight');
view(0,90);
end
\ No newline at end of file
end
% marks_array2flags() - Takes an array of values corresponding to the size of one of the dimensions of the EEG.data
% array as input, and adds marks to the EEG.marks structure based on a specified set of criteria
% applied to the input array. If the criteria is met for a given time point or channel,
% the corresponding index is flagged.
% Usage:
% >> [~,flag_sd_ch_inds]=marks_array2flags(data_sd_ch, ...
% 'flag_dim','row', ...
% 'init_method','[sd_ch_meth]', ...
% 'init_vals',[sd_ch_vals], ...
% 'init_crit',[sd_ch_o], ...
% 'flag_method','[sd_ch_f_meth]', ...
% 'flag_vals',[ [sd_ch_f_vals] ], ...
% 'flag_crit',[sd_ch_f_o], ...
% 'plot_figs','off');
%
% Required input:
% inarray - an array of values (could be standard deviations of one dimension of the EEG.data array).
%
% Optional inputs:
% 'flag_dim' - row = return column of row flags, col = return row of column flags
% 'init_method' - 'q' = quantile outlier classification, 'z' = zscore outlier, 'fixed' = fixed criteria
% 'init_vals' - distribution values for flagging by flag_crit = 'q' or 'fixed'
% 'init_dir' - ['pos'|'neg'|'both']
% 'init_crit' - outlier distance classification
% 'flag_method' - ['fixed'|'z_score'|'q']
% 'flag_vals' - distribution values for flagging by flag_crit = 'q' or 'fixed'
% 'trim' - percentage of trim to use for ve_trimmean or ve_trimstd, if trim is desired (default = 0)
% 'plot_figs' - Set to 'on' to plot a figure representing the flagging criteria. (default = 'off')
% 'title_prefix' - If plot_figs is set to 'on', this adds a prefix to the plot titles.
%
% Outputs:
% outarray - array of outlying values.
% outind - indices of the outlying values.
% out_dist - distances from the mean, median, or fixed value.
%
% See also: chan_variance(), fisherz(), ve_trimmean(), ve_trimstd();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function [outarray,outind,out_dist]=marks_array2flags(inarray,varargin)
%% handle varargin
......@@ -5,7 +52,7 @@ g=struct(varargin{:});
try g.flag_dim; catch, g.flag_dim='row'; end; %row = return column of row flags, col = return row of column flags
try g.init_method; catch, g.init_method='q'; end; %q = quantile outlier classification, z = zscore outlier classification, fixed = outlier cutoffs.
try g.init_method; catch, g.init_method='q'; end; %q = quantile outlier classification, z = zscore outlier, or fixed classification, fixed = outlier cutoffs.
try g.init_vals; catch, g.init_vals=[]; end; %distribution values for flagging by flag_crit = 'q' or 'fixed'
try g.init_dir; catch, g.init_dir='both'; end; %pos, neg, both
......@@ -14,7 +61,7 @@ try g.init_crit; catch, g.init_crit=[]; end; %outlier distance classification
try g.flag_method; catch, g.flag_method='z_score'; end; %fixed, dist
try g.flag_vals; catch, g.flag_vals=[]; end; %distribution values for flagging by flag_crit = 'q' or 'fixed'
% flag_val is deprecated... trated synonymous with flag_crit for
% flag_val is deprecated... treated synonymous with flag_crit for
% flag_method "z_score" and "fixed".
try
g.flag_val;
......
% marks_bound2flag() - Change all flag values within specified bounds to 1 for a given flag array.
%
% Usage:
% >> EEG.marks.time_info(1).flags = marks_bound2flag(bounds,EEG.marks.time_info(1).flags);
%
% Required input:
% bounds - An array specifying the indices of flags to change to 1.
% flags - One of the time_info(:).flags arrays.
%
% Outputs:
% flags - the updated flags array with the specified flags set to 1.
%
% See also: marks_label2index(), marks_moveflags();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function flags=marks_bound2flag(bounds,flags)
for i=1:size(bounds,1);
flags(bounds(i,1):bounds(i,2))=1;
end
\ No newline at end of file
end
% marks_label2index() - Returns an array of either the flag values for a particular label type,
% or the indices of the flag values that are equal to 1 (or greater than zero
% in the case of a continuous mark), or the indices of the boundaries between
% where the specified mark changes from 0 to 1.
%
% Usage:
% >> chan_inds = marks_label2index(EEG.marks.chan_info,{'manual'},'indexes','invert','on'); % return good channels
% >> epoch_inds = marks_label2index(EEG.marks.time_info,{'manual'},'indexes','invert','off'); % return bad time points
%
% Required input:
% EEG.marks.xxxx_info - EEG marks structure for time, channels, or components.
%
% Optional inputs:
% 'exact' - set to 'off' to apply the function to any label containing
% the substring specified in labels. Otherwise, use the exact
% string(s) specified in labels (default = 'on').
% 'invert' - set to 'on' to find indices with the value of 0 instead of
% the value of 1 (default = 'off').
%
% Outputs:
% out_array - the array representing the flag values, indices, or boundary indices.
%
% See also: pop_editeventvals(), pop_epoch(), rmbase();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function out_array=marks_label2index(marks_struct,labels,out_type,varargin)
%% INITIATE VARARGIN STRUCTURES...
......@@ -109,4 +142,4 @@ switch out_type
if flags(length(flags))==1;bounds=[bounds,length(flags)];end
out_array=reshape(bounds,2,length(bounds)/2)';
out_array(:,1)=out_array(:,1)+1;
end
\ No newline at end of file
end
% marks_match_label() - Find all label names that contain a specified sub-label.
%
% Usage:
% >> labels=marks_match_label(sublabels,{EEG.marks.xxxx_info.label});
%
% Required input:
% sub_labels - a string or cell array of substrings to find in the array of all labels.
% all_labels - the list of all labels in which to search for the specified sublabel(s).
%
% Outputs:
% new_labels - the resulting cell array of label names from the all_labels array that matched sub_labels.
%
% See also: marks_label2index(), pop_marks_flag_gap(), pop_marks_select_data();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function new_labels=marks_match_label(sub_labels,all_labels)
if ischar(sub_labels);
......
% movetype 1=append marks structure to the data array.
% 2=take appended marks from data array back to marks structure.
% marks_moveflags() - Add a set of new non-data channels to the EEG.data array that reflect
% the EEG.marks.time_info flags, or move a set of non-data channels that
% reflect the time_info flags back into the EEG.marks.time_info structure.
%
% Usage:
% >> EEG=marks_moveflags(EEG,1); % 1=append marks structure to the data array.
% >> EEG=marks_moveflags(EEG,2); % 2=take appended marks from data array back to marks structure.
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
% movetype - [1|2] 1=marks struct to data array, 2=data array to marks structure.
%
% Outputs:
% EEG - the updated EEG structure with an updated EEG.data array and EEG.marks structure.
%
% See also: marks_continuous2epochs(), marks_epochs2continuous(), marks_bound2flag();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function EEG=marks_moveflags(EEG,movetype)
......
% padflags() - Add extra padding of a specified number of time points around
% specified time marks. This padding can be given any value
% (usually 0.5, but can also be 1).
%
% Usage:
% >> chsd_epoch_flags=padflags(EEG,chsd_epoch_flags,1,'value',.5);
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
% flags - array of time_info flags.
% npad - number of seconds to pad around each side of the specified time_info flag.
%
% Optional input:
% 'value' - the alpha transparency value of the colour for the flag mark (default=1)
%
% Outputs:
% flags - the updated flags array from the input, but now with extra padded time periods.
%
% See also: marks_init(), marks_array2flags(), pop_marks_flag_gap();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function flags=padflags(EEG,flags,npad,varargin)
g=struct(varargin{:});
......
% reject2marks() - Transfer the flags from the native eeglab's EEG.reject
% structure into the vised_marks EEG.marks structure.
%
% Usage:
% >> EEG=reject2marks(EEG);
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
%
% Outputs:
% EEG - the resulting EEG structure with EEG.marks synchronized with the EEG.reject structure.
%
% See also: eegplugin_vised_marks(), marks_epochs2continuous();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function EEG=reject2marks(EEG)
if ~isfield(EEG,'marks');
......
% ve_trimmean() - Calculate the trimmed mean across time points or
% channels for the EEG.data array.
%
% Usage:
% >> m_dist(coli)=ve_trimmean(inarray(:,coli),g.trim);
%
% Required input:
% data - data array of a specific row or column of data.
% ptrim - percentage of outlying data to exclude from the mean from both sides. (decimal or percentage)
%
% Optional input
% dim - dimension of EEG.data array on which to perform the trimmed mean. 1 = returns the
% trimmed mean for the time dimension. 2= returns the trimmed mean of each channel.
%
% Outputs:
% trm_m - the trimmed mean value for either time points or channels.
%
% See also: marks_array2flags(), ve_trimstd();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function trm_m = ve_trimmean(data,ptrim,dim)
%
% if ptrim > 1;
......@@ -41,4 +69,4 @@ if dim==1;
else
data_srt = sort(data,2);
trm_m = mean(data_srt(1:size(data_srt,1),ntrim+1:ntotal-ntrim),2);
end
\ No newline at end of file
end
function trim_std = ve_trimstd(data,ptrim,dim)
% ve_trimstd() - Calculate the trimmed standard deviation across time points or
% channels for the EEG.data array.
%
% Function based off of ve_trimmean
%
% Usage:
% >> srrow(coli)=ve_trimstd(inmeasure(:,coli),g.trim);
%
% Required input:
% data - data array of a specific row or column of data.
% ptrim - percentage of outlying data to exclude from the std from both sides. (decimal or percentage)
%
% Optional input
% dim - dimension of EEG.data array on which to perform the trimmed std. 1 = returns the
% trimmed std for the time dimension. 2= returns the trimmed std of each channel.
%
% Outputs:
% trim_std - the trimmed std value for either time points or channels.
%
% See also: marks_array2flags(), ve_trimmean();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function trim_std = ve_trimstd(data,ptrim,dim)
if dim > 2;
disp('ERROR: dim must be 1 or 2');
......@@ -31,4 +59,4 @@ if dim==1;
else
data_srt = sort(data,2);
trim_std = std(data_srt(1:size(data_srt,1),ntrim+1:ntotal-ntrim),0,2);
end
\ No newline at end of file
end
% pop_continuous2epochs() - This function calls marks_continuous2epochs(),
% but with a popup menu to help set up the input arguments.
% Usage:
% >> EEGout = pop_continuous2epochs(EEG); % use defaults
% >> EEGout = pop_continuous2epochs(EEG, 'key', val, ...);
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
%
% Optional inputs:
% 'recurrence' - [in s] the regular recurrence interval of the dummy
% events used as time-locking events for the
% consecutive epochs {default: 1 s}
% 'limits' - [minsec maxsec] latencies relative to the time-locking
% events to use as epoch boundaries. Stated epoch length
% will be reduced by one data point to avoid overlaps
% {default: [0 recurrence_interval]}
% 'keep_boundaries' - leave in any boundary events present in the data
% (set to 'off' to remove the boundary events.
% 'rm_baseline'- [NaN|latency] remove baseline (s). NaN does not remove
% baseline. 0 remove the pre-0 baseline. To
% remove the full epoch baseline, enter a value
% larger than the upper epoch limit. Default is 0.
% 'evt_label' - [string] name for the event type. Default is 'X'
% 'extractepochs' - ['on'|'off'] extract data epochs ('on') or simply
% insert events ('off'). Default is 'on'.
%
% Outputs:
% EEG - the input EEG structure separated into consecutive epochs.
% com - string representing the marks_continuous2epochs() function called upon pressing
% - |OK| in the menu.
%
% See also: marks_continuous2epochs(), pop_epochs2continuous(), rmbase();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function [EEG,com]=pop_continuous2epochs(EEG,varargin)
com = ''; % this initialization ensure that the function will return something
......@@ -72,4 +117,4 @@ end
% -------------------------
com = ['EEG = pop_continuous2epochs(EEG',options,');'];
exec_com = ['EEG = marks_continuous2epochs(EEG',options,');'];
eval(exec_com)
\ No newline at end of file
eval(exec_com)
% pop_epochs2continuous() - This function calls marks_epochs2continuous() when the
% user selects the option through the drop-down menu in
% Tools->Marks->epoch/concatenate data->Concatenate epochs into continuous data.
% Usage:
% >> EEGout = pop_epochs2continuous(EEG); % use defaults
%
% Required input:
% EEG - EEG continuous data structure (EEG.trials = 1)
%
% Outputs:
% EEG - the input EEG structure separated into consecutive epochs.
% com - string representing the marks_epochs2continuous() function called upon pressing
% - |OK| in the menu.
%
% See also: marks_continuous2epochs(), pop_epochs2continuous(), rmbase();
%
% Code initially designed and written by James A. Desjardins (SHARCNET) with contributions from
% Andrew Lofts, Allan Campopiano, Brad Kennedy, Mike Cichonski, Tyler K. Collins, and Sara Stephenson
% supported by NSERC to Sidney J. Segalowitz at the Jack and Nora Walker Centre
% for Lifespan Development Research (Brock University),
% Brain Canada funding to Alan C. Evans at the Montreal Neurological Institute and Hospital (McGill University),
% and a Dedicated Programming award from SHARCNET, Compute Ontario.
% Copyright (C) 2017 James Desjardins
function [EEG,com]=pop_epochs2continuous(EEG)
com = ''; % this initialization ensure that the function will return something
......@@ -16,4 +42,4 @@ end;
% -------------------------
com = ['EEG = pop_epochs2continuous(EEG);'];
exec_com = ['EEG = marks_epochs2continuous(EEG);'];
eval(exec_com)
\ No newline at end of file
eval(exec_com)