- MNE version: e.g. 1.8.0
- operating system: Windows 11
I used ICLABEL and autoreact to help me automate the segmentation of EEG into epochs and remove noise
- The filtering frequency is 0.1-40hz
- Remove blink and line noise components with a probability greater than 0.8
Question:
Some of my subjects’ evokes showed abnormalities, as shown in the figure
I performed the following actions to investigate the cause of the problem
-
View the PSD image of epoch
-
View epoch sequence,as shown blow
There are some oscillations in the epoch, which I have marked with a red box
What could be the reason for this
My processing flow cannot delete these noises, what should I do?
I am a graduate student in psychology, conducting my first research. I have encountered many difficulties, and if I cannot solve them, it seems difficult for me to apply for a PhD. Please help me
# Process each data file
for data_path in file_paths:
print(f"Processing file: {data_path}")
# Read the raw data
raw = mne.io.read_raw_eeglab(data_path, preload=True)
print(raw.ch_names)
# Set electrode positions
montage = mne.channels.make_standard_montage("standard_1020")
raw.set_montage(montage)
raw = raw.resample(250)
# Filter and set average reference for ICA
raw_filter = raw.copy().filter(l_freq=1.0, h_freq=100.0)
raw_filter = raw_filter.set_eeg_reference("average")
# Calculate events and epochs
events, event_id = mne.events_from_annotations(raw_filter)
print(f"Event IDs: {event_id}")
event_ids = {"self": 1, "luxun": 2, "baoyi": 3}
epochs = mne.Epochs(
raw_filter, events, event_id=event_ids, tmin=-0.2, tmax=1, baseline=None, detrend=1
)
# Train ICA
ica = ICA(
n_components=30, max_iter="auto", method="picard",
random_state=42, fit_params=dict(ortho=False, extended=True)
)
ica.fit(epochs)
epochs.load_data()
# Automatically label ICA components
ic_labels = label_components(epochs, ica, method="iclabel")
print(f"IC Labels: {ic_labels['labels']}, {ic_labels['y_pred_proba']}")
labels = ic_labels["labels"]
y_pred_proba = ic_labels["y_pred_proba"]
exclude_idx = [idx for idx, (label, proba) in enumerate(zip(labels, y_pred_proba)) if
label in ["eye blink", "line noise"] and proba > 0.8]
excluded_components = len(exclude_idx)
# Apply notch filter at 50Hz and bandpass filter
raw = raw.notch_filter(freqs=(50))
raw = raw.filter(l_freq=0.1, h_freq=35.0)
raw = raw.set_eeg_reference('average')
# Apply ICA to epochs
epochs_ICAD = mne.Epochs(
raw, events, event_id=event_ids, tmin=-0.2, tmax=1,
baseline=None, preload=True, detrend=1
)
epochs_ICAD.load_data()
ica.apply(epochs_ICAD, exclude=exclude_idx)
# Apply baseline correction and remove data based on absolute voltage
epochs_ICAD.apply_baseline(baseline=(-0.2, 0))
# Perform automatic rejection of epochs post-ICA
epochs_ICAD.info['bads'] = []
ar = autoreject.AutoReject(n_interpolate=[1, 2, 4, 6, 8], random_state=42,
n_jobs=-1, verbose=True)
ar.fit(epochs_ICAD)
epochs_ICAD_ar, reject_ICAD_log = ar.transform(epochs_ICAD, return_log=True)
# Plot the final processed epochs
epochs_ICAD_ar.plot(block=True)