Epilepsy Tensors and Epileptic Focus Localization


Step1: Loading data

% Create dataset from X and assign pre-seizure(1)/seizure(2)/non-seizure(3) labels.
% Let a be # of pre-seizure samples.
% Let b be # of seizure samples.
% Let c be # of post-seizure samples.
class1=[ones(1,a) 2*ones(1,b) 3*ones(1,c)];
XX = X(id,:);
[XX_normalized, mx, stdx, msg]=auto(XX.data);

Step2: Construct an Epilepsy Tensor

WT = epilepsy_construct_tensor(XX_normalized, Fs, df);
WTp = permute(WT, [2 1 3]);
% Scaling in frequency/scales mode.
S2 = npreprocess(WTp, [0 0 0; 0 1 0]);

Step3: Artifact Extraction and Seizure Localization

model = parafac(S2,R);
%'elecloc_type1.txt' is the name of the file, which contains the localization of each
% electrode label on the scalp.
for i=1:R
    figure, topoplot(model.loads{3}(:,i), 'elecloc_type1.txt', 'electrodes', 'labels', 'style', 'fill', 'maplimits', [-1,1])

Step4: Artifact Removal

m_tucker = tucker(S2, [P Q R]);
% Identify N potential artifacts and use the components in the electrode mode
% to form the matrix A.
A = m_tucker.loads{3}(:,1:N);
%Remove artifacts from original tensor S2 and construct S2_new after
%artifact removal.
S2p = permute(S2, [3 1 2]);
S2pm = S2p.data(:,:);
S2_new = (eye(size(A,1))-A*pinv(A))*S2pm;
X = reshape(S2_new, [size(S2,3) size(S2,1) size(S2,2)]);
Xp = permute(X, [2 3 1]);
Xp = dataset(Xp);
mXp=parafac(Xp, R);
% Fit an R-component PARAFAC model
for i=1:R
    figure, topoplot(mXp.loads{3}(:,i), 'elecloc_type1.txt', 'electrodes', 'labels', 'style', 'fill', 'maplimits', [-1,1])


PLS_Toolbox, Wavelet Toolbox and EEGLab are needed to run the codes given above.