Skip to main content

SurfaceLaplacian

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Python equivalent

mne.preprocessing.compute_current_source_density in MNE-Python.

#include <dsp/surface_laplacian.h>

class UTILSLIB::SurfaceLaplacian

Surface Laplacian / Current Source Density (CSD) transformation.

Computes a reference-free spatial Laplacian of EEG data using spherical spline interpolation (Perrin et al. 1989). This improves spatial resolution by acting as a high-pass spatial filter that enhances local sources and attenuates volume-conducted far-field activity.

src/examples/ex_dsp_preprocessing/main.cpp
MatrixX3d electrodes(8, 3); // head coordinates in metres, on a 9 cm sphere
electrodes << 0.0, 0.0, 0.09,
0.05785088487178853, 0.0, 0.06894399988070801,
0.0, 0.05785088487178853, 0.06894399988070801,
-0.05785088487178853, 0.0, 0.06894399988070801,
0.0, -0.05785088487178853, 0.06894399988070801,
0.0626727816288017, 0.0626727816288017, 0.015628335990023737,
-0.0626727816288017, 0.0626727816288017, 0.015628335990023737,
-0.06267278162880172, -0.0626727816288017, 0.015628335990023737;
MatrixXd eeg(8, 10);
for (int k = 0; k < 8; ++k) {
for (int t = 0; t < 10; ++t) {
eeg(k, t) = std::sin(t * (k + 1) * 0.3);
}
}
const SurfaceLaplacianResult csd = SurfaceLaplacian::compute(eeg, electrodes, 1e-5, 4, 50, 0.09);

Static Methods​

compute(matData, matPositions, dLambda2, iStiffness, iNLegendreTerms, dSphereRadius)​

Compute the surface Laplacian (CSD) transformation.

Parameters:

  • matData : const Eigen::MatrixXd & EEG data matrix (n_channels × n_times).

  • matPositions : const Eigen::MatrixX3d & Electrode positions in 3D (n_channels × 3), in head coordinates.

  • dLambda2 : double Regularization parameter (default 1e-5).

  • iStiffness : int Spline stiffness parameter (default 4).

  • iNLegendreTerms : int Number of Legendre terms to evaluate (default 50).

  • dSphereRadius : double Radius of a sphere centred at the origin, in metres; if <= 0, a sphere (centre and radius) is fitted to the positions (default -1).

Returns:


computeTransform(matPositions, dLambda2, iStiffness, iNLegendreTerms, dSphereRadius)​

Compute only the CSD transformation matrix (without applying to data).

Parameters:

  • matPositions : const Eigen::MatrixX3d & Electrode positions in 3D (n_channels × 3).

  • dLambda2 : double Regularization parameter (default 1e-5).

  • iStiffness : int Spline stiffness parameter (default 4).

  • iNLegendreTerms : int Number of Legendre terms (default 50).

  • dSphereRadius : double Radius of a sphere centred at the origin; if <= 0, centre and radius are fitted.

Returns:

  • Eigen::MatrixXd — Transformation matrix (n_channels × n_channels).

Example​

Used in examples​

ex_dsp_preprocessing​

Preprocessing tools of the dsp library on synthetic data with a known ground truth.

src/examples/ex_dsp_preprocessing/main.cpp, line 219
const SurfaceLaplacianResult csd = SurfaceLaplacian::compute(eeg, electrodes, 1e-5, 4, 50, 0.09);
// mne.preprocessing.compute_current_source_density(sphere=(0, 0, 0, 0.09), lambda2=1e-5, stiffness=4), sample 3
VectorXd mneCsd(8);
mneCsd << 984.4089021671608, 1280.7679646395302, 457.7070056428769, -775.4476983026417,
-977.028371298518, -378.06791643722704, -311.9232346310464, 211.576727857144;
const double csdErr = (csd.matData.col(3) - mneCsd).cwiseAbs().maxCoeff() / mneCsd.cwiseAbs().maxCoeff();
ok &= expect(csdErr < 1e-6, QString("surface Laplacian = mne compute_current_source_density (relative error %1)").arg(csdErr));

Authors of this file​