Singh2020 / scripts /FASTER /component_properties.m
jalauer's picture
Add files using upload-large-folder tool
03a0748 verified
function list_properties = component_properties(EEG,blink_chans,lpf_band)
% Copyright (C) 2010 Hugh Nolan, Robert Whelan and Richard Reilly, Trinity College Dublin,
% Ireland
% nolanhu@tcd.ie, robert.whelan@tcd.ie
%
% 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
list_properties = [];
%
if isempty(EEG.icaweights)
fprintf('No ICA data.\n');
return;
end
if ~exist('lpf_band','var') || length(lpf_band)~=2 || ~any(lpf_band)
ignore_lpf=1;
else
ignore_lpf=0;
end
delete_activations_after=0;
if ~isfield(EEG,'icaact') || isempty(EEG.icaact)
delete_activations_after=1;
EEG.icaact = eeg_getica(EEG);
end
for u = 1:size(EEG.icaact,1)
[spectra(u,:) freqs] = pwelch(EEG.icaact(u,:),[],[],(EEG.srate),EEG.srate);
end
list_properties = zeros(size(EEG.icaact,1),5); %This 5 corresponds to number of measurements made.
for u=1:size(EEG.icaact,1)
measure = 1;
% TEMPORAL PROPERTIES
% 1 Median gradient value, for high frequency stuff
list_properties(u,measure) = median(diff(EEG.icaact(u,:)));
measure = measure + 1;
% 2 Mean slope around the LPF band (spectral)
if ignore_lpf
list_properties(u,measure) = 0;
else
list_properties(u,measure) = mean(diff(10*log10(spectra(u,find(freqs>=lpf_band(1),1):find(freqs<=lpf_band(2),1,'last')))));
end
measure = measure + 1;
% SPATIAL PROPERTIES
% 3 Kurtosis of spatial map (if v peaky, i.e. one or two points high
% and everywhere else low, then it's probably noise on a single
% channel)
list_properties(u,measure) = kurt(EEG.icawinv(:,u));
measure = measure + 1;
% OTHER PROPERTIES
% 4 Hurst exponent
list_properties(u,measure) = hurst_exponent(EEG.icaact(u,:));
measure = measure + 1;
% 10 Eyeblink correlations
if (exist('blink_chans','var') && ~isempty(blink_chans))
for v = 1:length(blink_chans)
if ~(max(EEG.data(blink_chans(v),:))==0 && min(EEG.data(blink_chans(v),:))==0);
f = corrcoef(EEG.icaact(u,:),EEG.data(blink_chans(v),:));
x(v) = abs(f(1,2));
else
x(v) = v;
end
end
list_properties(u,measure) = max(x);
measure = measure + 1;
end
end
for u = 1:size(list_properties,2)
list_properties(isnan(list_properties(:,u)),u)=nanmean(list_properties(:,u));
list_properties(:,u) = list_properties(:,u) - median(list_properties(:,u));
end
if delete_activations_after
EEG.icaact=[];
end