Skip to main content

Package to reduce artifacts in eeg from cochlear implant stimuli

Project description

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 \
  -i https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple \
  cors-ica

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"])

Project details


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.1.tar.gz (10.7 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.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: corsica_ci-0.0.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for corsica_ci-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8d0d477e3936ed76bc2a3261db44dce6355319f6933aeb2db737a555d81b1992
MD5 2936953df4dc466e24615abdf833c372
BLAKE2b-256 ab353ed3c5b34975accf894f3d1f8ca4e2673b09b1d45aa394a739420adf6a6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: corsica_ci-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for corsica_ci-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61ff773b4a4b13d0a193ba147188967a74f774cf629cb1ed575ba6c3638be1a2
MD5 5fa561d9330d994712fa9fab8460eefe
BLAKE2b-256 fb40f413f29fdf0d7e20c45c5b5881abfb015b42f697fe834153b8377f4cfa4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page