Epilepsy Feature Tensors and Seizure Recognition


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)];

Step2: Filtering

Let Fs be the sampling frequency. If data are recorded in the US, then use apply_notchfilter_USA. If data are recorded in Europe, then use apply_notchfilter.

X_filtered = apply_notchfilter_USA(X,Fs);
X_filtered = apply_notchfilter(X,Fs);

Step3: Construct an Epilesy Feature Tensor

Construct an Epilepsy Feature Tensor for each seizure of a patient. The tensor is constructed by calling the functions needed to compute fractal dimension, complexity, activity, mobility, spectral entropy, spectral skewness, median frequency, mean absolute slope, relative energies in different frequency bands and spatial information.

EFT = construct_epilepsyfeaturetensor(X_filtered, Fs, epoch_size, nb_features, lag);

Step4: Patient-Specific Seizure Recognition

* By leaving out one seizure at a time, form a training test and build a
model on the training set.
* Determine the number of component numbers and select features using the training set.
* Use these parameters to build a model on the training set and test the model on the left-out seizure.
* Let P1_S1, P1_S2, P1_S3 be the first, second and third seizures of Patient1. The flag for feature selection should be set to 1 to enable
feature selection within the script.
[Acc, Sen, GM, PSF, PSE, Tclass_all, Pclass_all] = run_NPLSLDA_ps(P1_S1,P1_S2,P1_S3);

Step5- 8: Patient Non-Specific Seizure Recognition

Steps 5 through 8 are used to build a patient non-specific seizure recognition model.

Step5: Construct a Cell-array using All Seizures

Construct a cell array containing all seizures of all patients after editing the properties of each dataset corresponding to a seizure. For instance, let P1_S1 be the first seizure of Patient 1. Edit description field of the dataset P1_S1 and also create the class which indicates the patient id.

% Create class3 to indicate the patientid of a seizure
P1_S1 =create_class3(P1_S1,1);
% Similarly edit the fields of each seizure of each patient
% Let P2_S1 and P2_S2 be the first and second seizures of P2, respectively.
AllSeizures{1}= P1_S1;
AllSeizures{2}= P2_S1;
AllSeizures{3}= P2_S2;
% ... construct the cell array using the seizures of all patients.

Step6: Preprocess Data

Due to scale differences between patients, for patient non-specific seizure recognition, we use log-transform for Activity and SpatialInfo features.

AllSeizures_Prep = preprocess_Alldata(AllSeizures);

Step7: Construct Training and Test sets

Let Patientid be the patient whose seizures are in the test set while the seizures of other patients will be in the training set

[Train, Test, count_train, count_test] = construct_cell(AllSeizures_Prep,Patientid);

Step8: Build Seizure Recognition model

This function first uses cross-validation to determine the number of components to be used in NPLS. It can also select features using the training set (a flag should be set within the function to enable this functionality). Once the paramaters are determined, the model is built on the training set. Then classes of epochs in the test set are predicted using the model.

[Acc, Sen, GM, Tclass, Pclass, MPclass] = run_NPLSLDA(Train, Test, nb_epochs)


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