R Package: eegwhiten

Published:

Package: eegwhiten (EEG Signal Whitening Toolkit)
Title: Whitening Transforms for EEG Covariance Matrices
Version: 0.1.0
Maintainer: Yiming Shen
License: MIT

Overview

eegwhiten provides whitening transforms with a simple fit/transform API for EEG covariance workflows. Data convention is rows as trials/epochs and columns as channels/features, with reusable model objects for cross-dataset transforms.

Key Methods (DESCRIPTION)

The package implements the following whitening transformations:

  1. PCA Whitening: Principal Component Analysis based whitening to maximize variance in orthogonal directions.
  2. PCA Whitening on Correlation Matrix: Correlation-standardized PCA variant.
  3. ZCA Whitening (Mahalanobis): Zero-phase Component Analysis, preserving the spatial arrangement of the original sensors while decorrelating them.
  4. ZCA Whitening on Correlation Matrix: Correlation-standardized ZCA variant.
  5. Cholesky Decomposition: Uses the Cholesky factor of the inverse covariance matrix for efficient whitening.
  6. SVD Whitening: Stable SVD-based whitening transformation.

Additional Utilities

  • Reusable fitted whitening models for train/test consistency.
  • Inverse transforms and basic diagnostics.
  • Depends: R (>= 3.6.0).
  • Suggests: testthat (>= 3.0.0).

Installation & Usage

You can install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("Yiming-S/eegwhiten")

Quick Start

library(eegwhiten)

# Apply ZCA whitening to an EEG epoch
# X is an [n_channels x n_timepoints] matrix
X_whitened <- eeg_whiten(X, method = "ZCA")

# Check correlation matrix (should be Identity)
print(round(cor(t(X_whitened)), 2))

View on GitHub