Contributions:SigfriedSigProc

From BCI2000 Wiki

Jump to: navigation, search

Contents

Synopsis

The SigfriedSigProc is a BCI2000 signal processing and visualization module using SIGFRIED (SIGnal modelling For Realtime Identification and Event Detection) to provide the following functionality to investigators:

Passive Functional Brain Mapping
Map active/passive brain function in real-time without the need of post-hoc analysis.
Brain-Computer Interface Operation
Establish a real-time 1-dimensional Brain-Computer Interface within minutes.

Location

http://www.bci2000.org/svn/tags/BCI2000.v2.1/src/contrib/SignalProcessing/SigfriedSigProc/

Versioning

Author

Peter Brunner

Source Code Revisions

  • Initial development: --
  • Tested under: --
  • Known to compile under: --
  • Broken since: --

Parameters

AutoScaleChannelList

Optional list of channels that define which channels will be used to autoscale the visualization results. This list is either empty (all channels will be used) or contains more than one channel. The AutoScaleChannelList can be used for example to exclude a set of EMG electrodes from a greater set of ECoG electrodes.

CircleRadius

Maximum pixel radius of the circles in a maximized visualization.

ElectrodeCondition

Table that with each column defines a conditions that will be visualized.

The table is defined by the following rules:

  • The first column always defines the realtime condition.
  • Each column can can contain multiple logical conditions (operators <,>,=) that are logical conjuncted.
    • If the original expression is not in a pure conjuncted form it may be transformed to be so.
  • All columns must have the same number of logically conjuncted conditions.
    • Always true expressions such as "Running = 1" may be used to fill in and to achieve the same number of logically conjuncted conditions for all columns.
  • Each row can be referenced to another row.
    • -1 disables the reference feature which will enable the averaging instead of the statistics selected in StatisticDisplayType.
  • Each column must define the min/max value of the visualization.
  • Each column can use operators from the set of < (smaller), > (larger) and = (equal) operators.
  • There is no limitation on the number of columns/rows of the ElectrodeCondition.
ElectrodeCondition conceptional design.
Name Reference DispMin DispMax State Operator Value State Operator Value ...
1 realtime -1 0 20 StimulusCode > -1 Feedback = 1 ...
2 average -1 0 20 StimulusCode 0 0 Feedback = 0 ...
3 tongue 2 0 1 StimulusCode = 11 Feedback = 1 ...
4 hand 2 0 1 StimulusCode = 12 Feedback = 1 ...
5 ... ... ... ... ... ... ... ... ... ... ...
Example of a ElectrodeCondition table with four conditions (realtime, average, tongue, hand) each defined by one BCI2000 state (StimulusCode).
Example of a ElectrodeCondition table with four conditions (realtime, average, tongue, hand) each defined by one BCI2000 state (StimulusCode).
Example of a ElectrodeCondition table with five conditions (realtime, up, right, down, left) each defined by two BCI2000 states (StimulusCode, Feedback).
Example of a ElectrodeCondition table with five conditions (realtime, up, right, down, left) each defined by two BCI2000 states (StimulusCode, Feedback).

ElectrodeLocation

Table that contains a label and the relative position of each electrode used in the model:

label 
String that is displayed when the user moves the mouse over this electrode.
Horizontal position (from left to right)
Vertical position (from bottom to top)
Example electrode location for a 16-channel montage using a subset of the international 10-20 system electrode locations.
Example electrode location for a 16-channel montage using a subset of the international 10-20 system electrode locations.

FeedbackType

Defines the input signal for the next application in the BCI2000 filter chain:

log-score 
Uses the score defined in ScoreType.
real-time display 
Uses the values of the real-time display.
The two possible sources for the real-time feedback: log-score and real-time display
The two possible sources for the real-time feedback: log-score and real-time display

LearningRateAutoScale

Controls the how quickly the auto-scale feature reacts to changes in the min/max of the data. Implemented using a 1st-order IIR filter with the filter coefficient LearningRateAutoScale. Filter is applied to the min and max of all channels defined by the channels listed in AutoScaleChannelList.

LearningRateAverage

Controls the how quickly the real-time display reacts to changes in the average of the data. Implemented using a 1st-order IIR filter with the filter coefficient LearningRateAverage. Filter is applied to the histogram of all data for each electrode.

LearningRateHist

Controls the how quickly the real-time display reacts to changes in the histogram of the data. Implemented using a 1st-order IIR filter with the filter coefficient LearningRateHist. Filter is applied to the histogram of all data for each electrode.

MemWindows

Number of blocks of the size SampleBlockSize (samples per channel per digitized block) that are used for the maximum entropy method to estimate the spectra. For the example settings bellow the spectra will be estimated 30 times per second (1200 / 40) for 600 samples (15 * 40) each. It is recommended that the number of samples to estimate the spectra are exactly the same in the SigfriedSigProc and the model (spectral_size).

Example:

ModelFiles

ModelFiles Table for three models with predefined positions of their visualization.
ModelFiles Table for three models with predefined positions of their visualization.

Table that contains for each model file:

filename 
Absolute or relative path to the model file.
label 
String that is used as a title for all windows associated with this model.
x-pos (optional) 
Horizontal origin for the window that visualizes this model.
y-pos (optional) 
Vertical origin for the window that visualizes this model.
width (optional) 
Width of the window that visualizes this model.

If the optional x-pos, y-pos and width are not provided then each window will be scaled to fill the full screen width.

ScoreType

Two choices are provided to determine to score the likelihood of the task-related data:

Mahalanobis-Distance 
Simple score that provides smooth transition from task-related data to baseline data and vice versa.
Negative-Log-Likelihood 
More complex measure that provides steep discrimination between task-related and baseline data.
The two possible score types that can be used to visualize the difference between two conditions: mahalanobis-distance, neg-log-probablity
The two possible score types that can be used to visualize the difference between two conditions: mahalanobis-distance, neg-log-probablity

StatisticDisplayType

Defines the statistic that is used to visualize the difference between two conditions define in the ElectrodeCondition table:

z-score
difference-of-means
r-square
The three possible statistics that can be used to visualize the difference between two conditions: z-score, difference-of-mean, r-square
The three possible statistics that can be used to visualize the difference between two conditions: z-score, difference-of-mean, r-square

VisualizeSigfried

Checkbox that enables visualization of the SIGFRIED results in a seperate graph for each model.

States

None.

Methodology

Methodology Concept

The conceptional idea behind SIGFRIED is to detect task-related changes in brain signals. This for example can be the detection of changes in the sensorimotor rhythm associated with actual/imaged motor movement and thus the detection of actual/imaged hand movement. This is achieved in three steps:

  1. Baseline non-task related data is recorded.
  2. Features that capture the mainfestation of this changes in the frequency domain are extracted from the data using the Maximum Entropy Spectral Estimation Method. A multi-modal statistical model using Gaussian-Mixture Models and the CEM-algorithm is then build.
  3. The build model is used to calculate the likelihood of task-related data (see figure below).
2-dimensional feature space populated with features extracted from non-task related and task related activity. The non-task related activity is modeled using a Gaussian Distribution (A). The likelihood of any data point thus can be determined and thus signal changes that are manifested in these features are detected (C) without the necessity for a-priori knowledge. In a stark contrast the classification/regression approach discriminates/regresses non-task related and task related activity. (B). It thus needs a-priori knowledge about both classes and more importantly can only discriminate between these two classes (D).
2-dimensional feature space populated with features extracted from non-task related and task related activity. The non-task related activity is modeled using a Gaussian Distribution (A). The likelihood of any data point thus can be determined and thus signal changes that are manifested in these features are detected (C) without the necessity for a-priori knowledge. In a stark contrast the classification/regression approach discriminates/regresses non-task related and task related activity. (B). It thus needs a-priori knowledge about both classes and more importantly can only discriminate between these two classes (D).

Methodology Outline

The methodology can be outlined in three essential steps (see figure below):

Record Baseline Data 
5-10 minutes of non-task related data (e.g. while the subject is resting) is recorded.
Build Model 
A model describing the baseline data is build.
Apply Model 
The build model is applied to different active/passive task-related data (e.g. while the subject is performing multiple motor tasks).

Methodology Step By Step

Step 1: Record Baseline Data

The figure below illustrates the process of recording baseline data:

  1. For this recording the subject is instructed to relax and stay motionless for the period of 5-10 minutes while data is recorded.
  2. It is particularly important that the data is not poisoned by movement artifacts since this will affect the quality of the model and thus the detection sensitivity for task related changes in the brain-signals.
  3. Data is processed (amplified, bandpass filtered, digitized) and stored.
The three steps of SIGFRIED: 1. Record Baseline Data
The three steps of SIGFRIED: 1. Record Baseline Data

Step 2: Build Model

Feature Extraction

From both the task and the non-task related data the same features that capture the task-related changes are extracted using the Maximum Entropy Spectral Estimation Method. This method has the following parameters:

start 
Minimum frequency in Hz.
stop 
Maximum frequency in Hz.
delta
Up-sampling resolution in Hz for the intermediate spectral estimate.
bandwidth 
Frequency resolution in Hz for the final spectral estimate.
detrend 
Detrending the signal with : (0) no detrend, (1) linear detrend (2) second order detrend.
modelorder 
Number of autoregressive (AR) coefficients.
spectral_size 
Number of samples for each spectral estimation.
spectral_stepping 
Number of samples between each spectral estimation.
bins2use 
List of bins from 1 to [(stop-start) / bandwidth - 1] that shall be used for the final spectral estimate.

The concept of his method is outlined int the figure below were for data recorded at 160 Hz the parameters start = 10 Hz, stop = 40 Hz, delta = 0.5 Hz, detrend = 1, modelorder = 16, spectral_size = 64, spectral_stepping = 32 are used to extract a spectral estimate.

Concept of the Maximum Entropy Spectral Estimation Method. The signal is divided into segments of the size spectral_size in steps of spectral_stepping. For data segment the forward and backward prediction is determined in the time domain using an autoregressive model of the order model_order. The average of the forward and backward prediction is transformed into the frequency domain (see pole/zero graph) and up-sampled in steps of delta Hz to represent the spectral estimate. This estimate is further averaged into bins of bandwidth Hz from start to stop Hz representing the final features.
Concept of the Maximum Entropy Spectral Estimation Method. The signal is divided into segments of the size spectral_size in steps of spectral_stepping. For data segment the forward and backward prediction is determined in the time domain using an autoregressive model of the order model_order. The average of the forward and backward prediction is transformed into the frequency domain (see pole/zero graph) and up-sampled in steps of delta Hz to represent the spectral estimate. This estimate is further averaged into bins of bandwidth Hz from start to stop Hz representing the final features.
Model Estimation

The figure below illustrates the steps in building and applying a model for each channel:

  • Generate Model
  1. Stored signals are loaded from a BCI2000 data file.
  2. Spatial filters e.g. Common Average Reference Filter are applied.
  3. Feature samples are extracted using the Maximum Entropy Spectral Estimation Method.
  4. Each feature is normalized between 0 and 1.
  5. The feature space is populated with the feature samples.
  6. The model, i.e. the parameters of a Gaussian-Mixture Model are estimated for each channel using the CEM-algorithm.
  7. The model is stored in a file.
The three steps of SIGFRIED: 2. Build Modell
The three steps of SIGFRIED: 2. Build Modell

Step 3: Apply Model

The figure below illustrates the process of applying a model to either perform Passive Functional Brain Mapping or Brain-Computer Interface Operation:

  1. The subject is exposed to different active (e.g. imagined and actual motor movement) and passive (e.g. auditory or tactile stimulation) tasks.
  2. Data is processed the same way as for the baseline data.
  3. Features are extracted the same way as for the baseline data.
  4. The likelihood of the data is determined using the baseline data model.
  5. The estimated likelihood is visualized and/or used to operate a 1-dimensional Brain-Computer Interface.
The three steps of SIGFRIED: 3. Apply Model
The three steps of SIGFRIED: 3. Apply Model

Tutorial

Step 0: Compile BCI2000 with SigfriedSigProc

As SigfriedSigProc is a contribution to BCI2000, a few manual steps are necessary to compile and install SigfriedSigProc:

  • Open a console window in the BCI2000 src/ directory, and execute make prepare.
  • Locate the file /src/makefiles and navigate to the line ($PATHTOBCI2000$ will be the path of your BCI2000 installation)
#"$PATHTOBCI2000$\src\contrib\SignalProcessing\SigfriedSigProc\SigfriedSigProc.mak" 
  • remove the # character.
"$PATHTOBCI2000$\src\contrib\SignalProcessing\SigfriedSigProc\SigfriedSigProc.mak" 
make all
  • now you should have the following files in the /prog folder
    • SigfriedSigProc.exe
    • SIGFRIED.dll
    • sigfried.ini
  • create a batch file in the batch folder to use SigfriedSigProc (use your signal source to replace SignalGenerator.exe)
cd ..\prog\
start operat.exe 
start SignalGenerator.exe AUTOSTART 127.0.0.1
start SigfriedSigProc.exe AUTOSTART 127.0.0.1
start StimulusPresentation.exe AUTOSTART 127.0.0.1
  • create a batch file in the batch folder to record baseline data (use your signal source to replace SignalGenerator.exe)
cd ..\prog\
start SignalGenerator.exe AUTOSTART 127.0.0.1
start DummySignalProcessing.exe AUTOSTART 127.0.0.1
start StimulusPresentation.exe AUTOSTART 127.0.0.1
start operat.exe

Step 1: Baseline Recording

  • Start the batch file for baseline recording, setup the parameters for you signal source and data storage.
  • Record 5-15 minutes of baseline data (e.g 5 minutes for 5 of bins in the bins2use and 10 minutes for 10 bins).

Step 2: Build Model

Locate the data2model GUI in \src\contrib\Tools\Sigfried\data2model_gui.exe and create a batch file in batch:

cd ..\src\contrib\Tools\Sigfried\
start data2model_gui.exe -inicfg data2model_gui.ini -inisig sigfried.ini -input ../$pathtobaseline$/baseline.dat -output /$pathtomodel$/baseline.mdl

Edit the data2model_gui.ini such that it suites your needs. The example below reflects settings for 16 channels recorded at 1000 Hz. Features are extracted from linearly detrended (detrend = 1) and common average referenced filtered (filter_car = 1) segments of 480 samples (spectral_size = 480)in steps of 480 samples from 8 to 40 Hz in 3 Hz steps using the bins 1 to 8. I.e. The frequency bins are 8-11 Hz, 11-14 Hz, 14-17 Hz, 17-20 Hz, 20-23 Hz, 23-26 Hz, 26-29 Hz, 29-32 Hz covering the mu and beta range of the EEG.

Detailed description of the parameters:

SpectralSettings 
Explained in the methodology section.
ModelSettings 
Explained in the methodology section.
SpatialSettings 
Allows to not only use the frequency features them self but also use the same features with a spatial derivative i.e. the difference between one feature from different channels at each time. To enable that add further lines with spatial1, spatial2 a.s.o that define the difference relative to the spatial0 channels. Each parameter has to have the same length as spatial0. Each the channels of each parameter must be a subset of spatial0.
SpatialSettings 
Allows to not only use the frequency features them self but also use the same features with a temporal derivative i.e. the difference between one feature from the same channel at different points in time. The lowest temporal derivative is 1.
FilterSettings 
The parameter filter_car can be:
  • 0 for no common average reference filtering.
  • 1 for common average reference filtering using all channels.
  • 2 for common average reference filtering using only the channels in channels
[SpectralSettings]
start = 8
stop = 40
delta = 0.2
bandwidth = 3
detrend = 1
modelorder = 40
samplefreq = 1000

[ModelSettings]
spectral_stepping = 480
spectral_size = 480
bins2use = 1 2 3 4 5 6 7 8
channels = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 

[SpatialSettings]
spatial0 = 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 

[TemporalSettings]
temporal = 

[FilterSettings]
filter_car = 1

Starting the data2model_gui using the created batch file and the custom data2model_gui will provide a visual interface that allows to review and verify the settings. For that reason the data2model_gui has a color coded scheme:

  • settings ok : The setting and all dependencies are valid.
  • settings mismatch : The settings may be valid but there is a mismatch with another parameter.
  • settings error : The settings is invalid.

The model can be build by pressing the "Build Model" button, which becomes available when all settings are valid and green. The model building can take a few second to many minutes depending on the amount of data. The progress is indicated by progress bars and no changes can be made until the process is finished.

Data panel: Shows that all settings are valid, i.e. that the input file is a valid BCI2000 data files, the ini files are valid and that the outfile can be written.
Enlarge
Data panel: Shows that all settings are valid, i.e. that the input file is a valid BCI2000 data files, the ini files are valid and that the outfile can be written.
Feature Extraction panel: Shows that all settings and their dependencies are valid.
Enlarge
Feature Extraction panel: Shows that all settings and their dependencies are valid.


Core Parameters panel: Shows that all settings and their dependencies are valid.
Enlarge
Core Parameters panel: Shows that all settings and their dependencies are valid.
Details Pannel: Shows detailed information about the BCI2000 input data file as well as which and how many features will be extracted.
Enlarge
Details Pannel: Shows detailed information about the BCI2000 input data file as well as which and how many features will be extracted.


Data panel showing an error: This indicates that the BCI2000 input data file either does not exist or is not a valid BCI2000 data file.
Enlarge
Data panel showing an error: This indicates that the BCI2000 input data file either does not exist or is not a valid BCI2000 data file.
Feature extraction panel showing an error: This indicates that their is a mismatch between the parameters start, stop, bandwidth and bins2use. A closer look shows that the number of bins defined in bins2use exceeds the range defined by start, stop, bandwidth.
Enlarge
Feature extraction panel showing an error: This indicates that their is a mismatch between the parameters start, stop, bandwidth and bins2use. A closer look shows that the number of bins defined in bins2use exceeds the range defined by start, stop, bandwidth.


Step 3: Run SigfriedSigProc

To run SigfriedSigProc the following steps have to be performed:

  • Use the batch file created in step 0 to start BCI2000 v2.0 with the SigfriedSigProc module.
  • Configure the parameters as described in the parameters section to either perform Passive Functional Brain Mapping or Brain-Computer Interface Operation.
  • Instruct the subject to perform the configured tasks (e.g. multiple cued motor movements or passive listening to a auditory task).
  • Start the task.

The functionality of the visualization is illustrated in the following to figures. In general the visualization allows to:

  • Turn a condition on or off.
  • Set the display range, e.g. to only display significant activity.
  • Use the auto range feature to set the display range.
  • Display the active condition.
SigfriedSigProc visualization window for one model (mu/beta).
Enlarge
SigfriedSigProc visualization window for one model (mu/beta).
Functionality of the scale trackbar.
Enlarge
Functionality of the scale trackbar.

See also

Personal tools