[Eeglablist] interpolating bad electrodes
nkovacev at rotman-baycrest.on.ca
nkovacev at rotman-baycrest.on.ca
Thu Jan 19 20:27:18 PST 2006
Dear eeglablist users,
Here is a quick hack at interpolation of bad electrode data - see
bellow. It creates a temporary data set with bad electrodes removed. It
calls topoplot to get interpolated values at locations of bad electrodes
(thanks to Arno for the tip) and it does this for the entire time
course.
If anyone can suggest better/faster solution - that would be great. This
is bit of a hack because it calls topolot for each timepoint so it can
be very slow for long time courses.
Such a function would be extremely useful, because in practice, it is
quite common to have a single bad electrode - it is always a shame to
either have to remove that electrode from all subjects in the study, or
drop the subject, or find another workaround. Interpolation would allow
much more elegant preservation of group data without loss of spatial
resolution.
Cheers,
Natasha
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function eeg = interpolate_bad_electrodes(eeg, bad_electrodes)
% Inputs:
% eeg - eeglab dataset
% bad_electrodes - channels with bad data
% Output: eeg - data set with bad electrode data replaced by
interpolated
% data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n = numel(bad_electrodes);
% get theta, rad of bad electrodes
theta = zeros(1,n); rad = zeros(1,n);
for i=1:n
be = bad_electrodes(i);
theta(i) = eeg.chanlocs(be).theta;
rad(i)= eeg.chanlocs(be).radius;
end
% create temporary set with bad electrodes removed
tmp_eeg = pop_select(eeg,'nochannel',bad_electrodes);
tmp_eeg = eeg_checkset(tmp_eeg);
% for each timept obtain interpolated value
data = reshape(tmp_eeg.data, tmp_eeg.nbchan, eeg.pnts*eeg.trials); %2D
% allocate matrix that will receive interpolated data
interp_data = zeros(n, eeg.pnts*eeg.trials);
for t=1:size(data,2)
tmp_data = squeeze(data(:,t));
for i=1:n
[h val]= topoplot(tmp_data,tmp_eeg.chanlocs,'noplot',[rad(i)
theta(i)]);
interp_data(i,t) = val;
end
end
% return eeg with bad electrode data replaced by interpolated data
eeg.data = reshape(eeg.data, eeg.nbchan, eeg.pnts*eeg.trials); %2D
eeg.data(bad_electrodes,:) = interp_data;
eeg = eeg_checkset(eeg); %3D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
Natasa Kovacevic, PhD
Rotman Research Institute
Baycrest Centre for Geriatric Care
Toronto
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the eeglablist
mailing list