Skip to main content

CI Artifact Reduction

ci_artifact_reduction(
    raw,
    subject_id,
    trial_id,
    output_dir,
    fs_eeg,
    attended_audio,
    distraction_audio=None,
    snr_threshold=27,
    start_search_window=-0.005,
    end_search_window=0.012,
    n_components=None,
    plot=False,
    metadata=False
)

Filtering CI Artifacts based on Correlation of Independent Components and audio

Method Overview

  1. EEG data is decomposed into independent components using ICA.
  2. Each component is cross-correlated with the audio stimulus.
  3. The peak correlation within a search window is identified.
  4. The SNR value is computed from the correlation peak.
  5. Components with an SNR value above the defined threshold are classified as CI artifact-related components and are removed.
  6. The cleaned EEG signal is reconstructed from the remaining components.

Parameters

raw : mne.io.Raw
    EEG recording loaded with MNE-Python

subject_id : str | int
    Identifier of the subject used for output file naming

trial_id : str | int
    Identifier of the trial used for output file naming

output_dir : str
    Directory where plots and metadata files are saved

fs_eeg : int
    Sampling frequency of the EEG recording in Hz

attended_audio : np.ndarray
    1D array containing the attended audio signal

distraction_audio : np.ndarray, optional
    1D array containing the distracting audio signal, default = None

snr_threshold : float
    Independent components with SNR values above this threshold are removed, default = 27

start_search_window : float, optional
    Start point of the search window relative to zero lag (in seconds), default = -0.005

end_search_window : float, optional
    End point of the search window relative to zero lag (in seconds), default = 0.012

n_components : int | float | None, optional     Number of components passed to the ICA algorithm. If None, 0.999999 will be used, default = None.

plot : bool, optional
    If True, saves cross-correlation plots of all independent components, default = False

metadata : bool, optional
    If True, saves metadata and summary statistics as CSV files, default = False


Returns

cleaned_eeg : np.ndarray
    EEG data after CI artifact removal

raw_cleaned : mne.io.Raw
    Cleaned EEG data as an MNE Raw object

metadata_out : dict     Dictionary containing summary information about the artifact reduction, including all SNR values, excluded ICs, used ICs, peak times, and threshold settings


Raises

ValueError
    If output_dir is not specified.

ValueError
    If EEG and audio dimensions do not match.


Warns

UserWarning
    If EEG sampling frequency is below 500 Hz.

UserWarning     If a Trial ID already exists in the metadata file and will be overwritten.

UserWarning     If Trial ID contains non-numeric values and sorting is skipped.


Installation

This package requires:

  • NumPy
  • Pandas
  • SciPy
  • Matplotlib
  • MNE-Python

All dependencies are installed automatically when installing the package.

Install the latest release using pip:

pip install corsica-ci

Notes

  • EEG and audio must already be temporally aligned and have identical sampling and length. No resampling is performed internally.
  • ICA is performed using MNE’s Infomax algorithm.
  • In dual-speaker scenarios, attended and distraction signals are summed to form the reference stimulus.

Dataset

The dataset used for development and evaluation of this method is available on Zenodo:

CI Artifact Reduction Dataset


Example

import numpy as np
import mne
from CORSICA.artifact_reduction import ci_artifact_reduction

# Load EEG data (EEGLAB .set file)
raw = mne.io.read_raw_eeglab("subject_01_trial_01.set", preload=True)

# Sampling frequency
fs_eeg = 1000

# Ensure matching length with EEG
n_samples = raw.get_data().shape[1]

# Example audio signals (must be time-aligned with EEG)
attended_audio = raw.get_data()[31, :]
distraction_audio = raw.get_data()[32, :]

           

# Run CI artifact reduction

cleaned_eeg, raw_cleaned, metadata_out  = ci_artifact_reduction(
    raw=raw,
    subject_id="301",
    trial_id="123",
    output_dir="./results",
    fs_eeg=fs_eeg,
    attended_audio=attended_audio,
    distraction_audio=distraction_audio,
    snr_threshold=9.5,
    start_search_window=-0.005,
    end_search_window=0.012,
    n_components = None,
    plot=True,
    metadata=True
)

print("Cleaned EEG shape:", cleaned_eeg.shape)
print("Excluded ICs:", metadata_out["Indices of excluded ICs"]) 
print("Used ICs:", metadata_out["Indices of used ICs"])

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

corsica_ci-0.0.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

corsica_ci-0.0.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file corsica_ci-0.0.3.tar.gz.

File metadata

  • Download URL: corsica_ci-0.0.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for corsica_ci-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6353d33c979fdf8d94989cde5a4163631ff2f39dede1c24b436026b5bbfae059
MD5 cebb2d662a6d5acdec3b71d2a30e642e
BLAKE2b-256 5eb9cc76c0fac5c6daf0643871ab494a3958ed3dac46a3e569ef7e1ba30655dc

See more details on using hashes here.

File details

Details for the file corsica_ci-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: corsica_ci-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for corsica_ci-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2295047e429b2b8752e114e4468aa7eb9485bdcd63f39773757aec9377aa649
MD5 077ffece851314b53f0f8a0ce5f3e3d7
BLAKE2b-256 033f869e09155f6a3a0d17eca438c6d29f128fbd730eb95a4354aee200db7a0a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page