Bad channels detection

This article introduces an additional feature of the ImaGIN toolbox: the automatic detection of bad channels in SEEG recordings, based on a classifier trained on hundreds of datasets.


The detection method described in this tutorial is published in this article:
Tuyisenge V, Trebaul L, Bhattacharjee M, Chanteloup-Forêt B, Saubat-Guigui C, Mîndruţă I, Rheims S, Maillard L, Kahane P, Taussig D, David O
Automatic bad channel detection in intracranial electroencephalographic recordings using ensemble machine learning.
Clin Neurophysiol. 2017 Dec 24;129(3):548-554.


In order to use this feature from the ImaGIN interface or from a Matlab script, you need the following programs installed on your computer:

Convert and epoch recordings

  • Start ImaGIN: Go to the ImaGIN installation folder and execute ImaGIN.m
  • Convert the recordings to SPM .mat/.dat format: Select menu Import > Convert and select the file to import.
  • Run any other preparation step you need: Set or import event markers, set SEEG contact positions… See tutorial #3.
  • Epoch the recordings: Use the button [Epoch] to extract one or more segments of data from the continuous file.

Detect bad channels

Select menu Import > Detect bad channels:

The first time you execute the algorithm, it will run for a long time (several minutes), because the classifier has to be trained.

  • Some features of the SEEG signals you selected are computed (ImaGIN_FeatureSEEG.m) and compared to a database of features distributed with the software (ImaGIN_trainBaseFeatures.mat).
  • In this large training set, the good/bad channels have been selected manually. A classifier is trained using Matlab's Statistics and Machine Learning toolbox to detect good/bad channels based on this information (ImaGIN_trainBaseUpdate.m, ImaGIN_trainClassifier.m).
  • The trained classifier is saved in a new file (ImaGIN_trainedClassifier.mat) and will be used directly the next time you select the menu "Detect bad channels". After the first initial training, this process will run much faster.

In output, two types of information are saved:

  • The list of bad channels is updated in the file you selected in input.
  • A set of images representing the signals are saved in the sub-folder ScreenShot: good channels in black, bad channels in red.

Method description

SEEG features

To summarize the SEEG recordings, we used features that quantify signals variances, spatial–temporal correlation and nonlinear properties:

  • Average of correlation coefficients of each channel with respect to its neighbors,
  • Variance normalized by the median of variances of neighboring channels,
  • Deviation measures how an amplitude of a channel diverges from the amplitude of local channels,
  • Amplitude range normalized by the median of amplitudes of local channels,
  • Normalized mean gradient that detects high-frequency activity in a channel,
  • Channel kurtosis that measures the presence of signal outliers,
  • Hurst exponent index that measures the channel normality.


We have chosen an ensemble bagging classifier to separate bad and good channel classes. This classification approach  helps to cope with imbalances between these two classes.
The training set was built on one part of SEEG datasets whose bad channels have been labeled by experts and test set on the remaining part.

The algorithm takes an array of data: channels in rows x 8 columns (the first 7 feature columns and the last column for class labels). After training, the prediction is done by applying the trained classifier on new SEEG datasets. The input of the trained model is of the same form as the training dataset (table or matrix) and the trained model returns predictions.

Execute from a script

You can execute this bad channels detection from the ImaGIN interface, or directly from Matlab script. Note that using directly the script ImaGIN_BadChannel requires ImaGIN and SPM to be available on the Matlab path at the execution, and the Statistics and Machine Learning toolbox must be installed on your computer. Example script:

clear S;
S.dataset = '/full/path/to/input/file';
S.FileOut = '/full/path/to/output/FOLDER/;  % If ommited, the input file will be updated, no copy of the file will be created
S.trainBase = '/full/path/to/training_set/FOLDER/';   % Directory where ImaGIN_trainBaseFeatures.mat is located
D = ImaGIN_BadChannel(S);