Jump to content

User Reference:SpatialFilter

From BCI2000 Wiki

Function

The SpatialFilter computes an instantaneous linear transformation of its input. Typically, the SpatialFilter's input is the unfiltered brain signal from the source module. The linear transformation that is applied by the spatial filter is described by a transformation matrix, and applied for each sample separately, not linking data across different points in time. This linear transformation can be parameterized in three different ways as described below.

Parameters

SpatialFilterType

This parameter defines the method that will be used to design the spatial filter. Choices are:

0 None
No spatial filtering is performed; the input signal is copied to the output signal, and the spatial filter matrix is ignored.
1 Full Matrix
The linear transformation applied to the input signal is defined by the SpatialFilter matrix parameter. This is the is also the default, and matches behavior in previous versions of BCI2000.
2 Sparse Matrix
The sparse matrix filter uses the SpatialFilter matrix parameter to define non-zero matrix entries. Each non-zero entry is given by an input channel, output channel, and weight for that channel.
3 Common Average Reference (CAR)
The common average reference spatial filter calculates the mean of every channel, and subtracts this value from selected output channels. This filter's output channels may be defined by the SpatialFilterCAROutput parameter.

SpatialFilter

Full Matrix Filter Type

The full matrix filter uses the SpatialFilter parameter to define the linear transformation applied to the filter's input signal. In this matrix, columns represent input channels, and rows represent output channels. Each matrix element defines a weight with which the respective input channel (column) enters into the respective output channel (row).

If the spatial filter is an identity filter -- not modifying its input --, then the SpatialFilter matrix is a unit matrix (square matrix with ones on the main diagonal, and all other elements zero).

In a typical EEG experiment with fixed montage, you might want column labels to reflect the respective electrode location, simplifying the task of further modifications to the spatial filter. Also, specifying row labels to identify output channels allows you to use those labels in configuration of further stages of processing, such as the LinearClassifier.

Sparse Matrix Filter Type

The sparse matrix filter uses the SpatialFilter parameter to define the relationship between input channels and output channels with a given weight. In this case, the SpatialFilter matrix must have 3 columns, and a row for each input/output relationship. The first column contains the input channel, the third column defines the weight that the input channel is multiplied by before being assigned to the output channel, which is defined in the second column.

When specifying input channels in the first column, you may use channel names. In order to assign labels to output channels in sparse representation, use arbitrary labels in the (third) output channel column.

See the example below for more information on how to use the sparse matrix.

SpatialFilterCAROutput

This parameter is a list of channels that define which channels should be output from the common average reference spatial filter, and the order in which they should appear. That is, the location of the channel in this list determines the output channel position. For example, if input channels 6, 7, 10, and 12 should be passed to the output of the spatial filter as channels 3, 4, 1, and 2, then this parameter should be set to:

10 12 6 7

Rather than numbers, channel names may be specified as defined in the ChannelNames parameter:

C3 C4 CP3 CP4 Cz

It is important to note that all channels passed to the spatial filter (typically defined in the TransmitChList parameter) are used in the CAR calculation, but only a subset of these channels are actually output and passed to the next step in the signal processing chain.

If this parameter is left blank, then all input channels are passed to the output, and the number of input channels equals the number of output channels.

States

None.

Examples

Linked Mastoids (Full Matrix)

Physical reference is to the left mastoid (A1). The right mastoid (A2) is recorded vs A1 on channel 1. All other electrodes are recorded vs A1 as well, and use the remaining channels. In your spatial filter, you will want to re-reference all channels against "linked mastoids", i.e. against the mean of A1 and A2.

In the spatial filter matrix, you want to subtract half of the A2 channel from each of the remaining channels:

Linked Mastoids
  A2 Fz Cz Pz ...
Fz' -1/2 1 0 0 ...
Cz' -1/2 0 1 0
Pz' -1/2 0 0 1
  ...


Sparse Matrix

In this example, the mean of channels 1-4 are passed to output channel 1, and the negative mean of channels 10-14 are passed to output channel 2. The SpatialFilter matrix definition is given below.

Sparse Matrix
  In Out Wt
1 1 1 .25
2 2 1 .25
3 3 1 .25
4 4 1 .25
5 10 2 -.2
6 11 2 -.2
7 12 2 -.2
8 13 2 -.2
9 14 2 -.2

This results in:
OutCh(1) = 0.25*InCh(1) + 0.25*InCh(2) + 0.25*InCh(3) + 0.25*InCh(4)
OutCh(2) = (-0.25)*InCh(10) + (-0.25)*InCh(11) + (-0.25)*InCh(12) + (-0.25)*InCh(13)

Large Laplacian (Sparse Matrix)

In this example, the spatial filter computes Large-Laplacian filtered versions of channels C3 and C4 by re-referencing them to the mean of their mid-range neighbors Cz, P3/4, T7/8, and F3/4:

C3'=C3-(Cz+P3+T7+F3)/4
C4'=C4-(Cz+P4+T8+F4)/4

Using channel names, the filter specification will be independent of the order and exact set of input channels, provided that all required channels are available and labeled correctly.

Sparse Matrix
  In Out Wt
1 C3 C3 1
2 Cz C3 -.25
3 P3 C3 -.25
4 T7 C3 -.25
5 F3 C3 -.25
6 C4 C4 1
7 Cz C4 -.25
8 P4 C4 -.25
9 T8 C4 -.25
10 F4 C4 -.25

Performance Notes

Each spatial filter uses a different algorithm to compute the linear transformation, and can therefore have implications on CPU load and performance.

None

In general, use the "none" option has the best performance, since no computations are actually done.

CAR

The common-average reference has the next best performance in most circumstances. It is possible to create a CAR using either the full-matrix or sparse matrix options; however, the CAR method only calculates the mean value once per sample, and subtracts it only from the selected output channels. In order to implement a CAR in a full-matrix, the mean must be recalculated for every output channel, which is not as efficient, particularly for high channel count systems.

Sparse Matrix

The sparse matrix method performance is determined completely by the number of elements (rows) in the SpatialFilter matrix. In the simplest case, a single channel is multiplied by the weight and assigned to the specified output channel; this would take far less CPU time than the CAR method, and possibly the "none" option as well. In the most complicated case, N*N rows would be created, where N is the number of input channels, and performance would be close to that of an NxN spatial filter matrix. (Actually, theoretically, more than N*N rows can be used, but this is unnecessary because some input/output combinations would overlap, which could be combined into a single weight).

Full Matrix

In general, the full matrix is going to have the highest CPU load of any spatial filtering method, although there are certainly circumstances in which performance could be better. That being said, this method has been used in BCI2000 since its inception, and is the simplest method of calculating complicated transformations, such as a Laplacian spatial filter. However, if the other methods of spatial filtering can be used, they should be in most cases. For example, if the identity matrix is specified (an NxN matrix with ones along the diagonal), then for every output channel, every input channel is multiplied by 0 or 1, utilizing CPU time unnecessarily.

See also

User Reference:LinearClassifier, User Reference:DataIOFilter#ChannelNames