:orphan:

The Signal-Space Projection (SSP) method
========================================

.. NOTE: part of this file is included in doc/overview/implementation.rst.
   Changes here are reflected there. If you want to link to this content, link
   to :ref:`ssp-method` to link to that section of the implementation.rst
   page. The next line is a target for :start-after: so we can omit the title
   from the include:
   ssp-begin-content

The Signal-Space Projection (SSP) is one approach to rejection of external
disturbances in software. The section presents some relevant details of this
method. For practical examples of how to use SSP for artifact rejection, see
:ref:`tut-artifact-ssp`.

General concepts
~~~~~~~~~~~~~~~~

Unlike many other noise-cancellation approaches, SSP does not require
additional reference sensors to record the disturbance fields. Instead, SSP
relies on the fact that the magnetic field distributions generated by the
sources in the brain have spatial distributions sufficiently different from
those generated by external noise sources. Furthermore, it is implicitly
assumed that the linear space spanned by the significant external noise patterns
has a low dimension.

Without loss of generality we can always decompose any :math:`n`-channel
measurement :math:`b(t)` into its signal and noise components as

.. math::    b(t) = b_s(t) + b_n(t)
   :label: additive_model

Further, if we know that :math:`b_n(t)` is well characterized by a few field
patterns :math:`b_1 \dotso b_m`, we can express the disturbance as

.. math::    b_n(t) = Uc_n(t) + e(t)\ ,
   :label: pca

where the columns of :math:`U` constitute an orthonormal basis for :math:`b_1
\dotso b_m`, :math:`c_n(t)` is an :math:`m`-component column vector, and the
error term :math:`e(t)` is small and does not exhibit any consistent spatial
distributions over time, *i.e.*, :math:`C_e = E \{e e^\top\} = I`. Subsequently,
we will call the column space of :math:`U` the noise subspace. The basic idea
of SSP is that we can actually find a small basis set :math:`b_1 \dotso b_m`
such that the conditions described above are satisfied. We can now construct
the orthogonal complement operator

.. math::    P_{\perp} = I - UU^\top
   :label: projector

and apply it to :math:`b(t)` in Equation :eq:`additive_model` yielding

.. math::    b_{s}(t) \approx P_{\perp}b(t)\ ,
   :label: result

since :math:`P_{\perp}b_n(t) = P_{\perp}(Uc_n(t) + e(t)) \approx 0` and
:math:`P_{\perp}b_{s}(t) \approx b_{s}(t)`. The projection operator
:math:`P_{\perp}` is called the **signal-space projection operator** and
generally provides considerable rejection of noise, suppressing external
disturbances by a factor of 10 or more. The effectiveness of SSP depends on two
factors:

- The basis set :math:`b_1 \dotso b_m` should be able to characterize the
  disturbance field patterns completely and

- The angles between the noise subspace space spanned by :math:`b_1 \dotso b_m`
  and the signal vectors :math:`b_s(t)` should be as close to :math:`\pi / 2`
  as possible.

If the first requirement is not satisfied, some noise will leak through because
:math:`P_{\perp}b_n(t) \neq 0`. If the any of the brain signal vectors
:math:`b_s(t)` is close to the noise subspace not only the noise but also the
signal will be attenuated by the application of :math:`P_{\perp}` and,
consequently, there might by little gain in signal-to-noise ratio.

Since the signal-space projection modifies the signal vectors originating in
the brain, it is necessary to apply the projection to the forward solution in
the course of inverse computations.

For more information on SSP, please consult the references listed in
:footcite:`TescheEtAl1995,UusitaloIlmoniemi1997`.

Estimation of the noise subspace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As described above, application of SSP requires the estimation of the signal
vectors :math:`b_1 \dotso b_m` constituting the noise subspace. The most common
approach, also implemented in :func:`mne.compute_proj_raw`
is to compute a covariance matrix
of empty room data, compute its eigenvalue decomposition, and employ the
eigenvectors corresponding to the highest eigenvalues as basis for the noise
subspace. It is also customary to use a separate set of vectors for
magnetometers and gradiometers in the Vectorview system.

EEG average electrode reference
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The EEG average reference is the mean signal over all the sensors. It is
typical in EEG analysis to subtract the average reference from all the sensor
signals :math:`b^{1}(t), ..., b^{n}(t)`. That is:

.. math::	{b}^{j}_{s}(t) = b^{j}(t) - \frac{1}{n}\sum_{k}{b^k(t)}
   :label: eeg_proj

where the noise term :math:`b_{n}^{j}(t)` is given by

.. math:: 	b_{n}^{j}(t) = \frac{1}{n}\sum_{k}{b^k(t)}
   :label: noise_term

Thus, the projector vector :math:`P_{\perp}` will be given by
:math:`P_{\perp}=\frac{1}{n}[1, 1, ..., 1]`

.. warning::
   When applying SSP, the signal of interest can also be sometimes removed.
   Therefore, it's always a good idea to check how much the effect of interest
   is reduced by applying SSP. SSP might remove *both* the artifact and signal
   of interest.
