# Noise in epoch after filter&ICA&epochreject

**URL:** <https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294>\
**Category:** Support & Discussions\
**Tags:** frequency-filter, epochs\
**Created:** [September 8, 2024, 1:07pm UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294 "2024-09-08T13:07:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SongLin99](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/songlin99/32/3877_2.png) [@SongLin99](https://mne.discourse.group/u/SongLin99)\
**Post date:** [September 8, 2024, 1:07pm UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/1 "2024-09-08T13:07:18Z")

</div>

- 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

1. The filtering frequency is 0.1-40hz
2. 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  
 ![1](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/5/5526841f2161302487338bd5567675d92067a92e.jpeg)

I performed the following actions to investigate the cause of the problem

1. View the PSD image of epoch  

2. 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

```python
# 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)

```

---

<div class="post-metadata">

**Author:** ![SongLin99](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/songlin99/32/3877_2.png) [@SongLin99](https://mne.discourse.group/u/SongLin99)\
**Post date:** [September 9, 2024, 6:25am UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/2 "2024-09-09T06:25:41Z")

</div>

anyone there？ 🥲

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [September 9, 2024, 7:53am UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/3 "2024-09-09T07:53:24Z")

</div>

These look like alpha oscillations to me. Did (some of) the participants have their eyes closed during the experiment? Normally, given enough epochs these oscillations should cancel out, because they are not phase-locked, but apparently that’s not really the case in your data. I don’t know of any automated method to detect such segments, but you could probably inspect and mark those epochs manually just for the problematic participants and see if this improves the ERP.

---

<div class="post-metadata">

**Author:** ![SongLin99](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/songlin99/32/3877_2.png) [@SongLin99](https://mne.discourse.group/u/SongLin99)\
**Post date:** [September 9, 2024, 8:11am UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/4 "2024-09-09T08:11:32Z")

</div>

Thank you!! I think it is alpha wave too, i`m searching way to solve it automated

---

<div class="post-metadata">

**Author:** ![sotpapad](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sotpapad/32/2184_2.png) [@sotpapad](https://mne.discourse.group/u/sotpapad)\
**Post date:** [September 9, 2024, 4:34pm UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/5 "2024-09-09T16:34:19Z")

</div>

Hi,

I don’t exactly suggest it, 'cause I think it can easily turn into a big rabbit hole, but maybe [bycycle](https://bycycle-tools.github.io/bycycle/) is what you need.

Cheers,

---

<div class="post-metadata">

**Author:** ![SongLin99](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/songlin99/32/3877_2.png) [@SongLin99](https://mne.discourse.group/u/SongLin99)\
**Post date:** [September 11, 2024, 10:16am UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/6 "2024-09-11T10:16:57Z")

</div>

Thanks！Are you suggesting that I use bycycle to calculate the frequency domain information for each epoch? For example, check if there is signal enhancement in the alpha frequency band.

---

<div class="post-metadata">

**Author:** ![sotpapad](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sotpapad/32/2184_2.png) [@sotpapad](https://mne.discourse.group/u/sotpapad)\
**Post date:** [September 11, 2024, 12:53pm UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/7 "2024-09-11T12:53:40Z")

</div>

**IF** you can tune it to detect only the time segments you are eye-balling (probably a bit more or a bit less of data) as “alpha bursts”, then I guess you can either reject epochs, or exclude/repair specific time windows and/or channels. I have not tried, though, to use it this way - I only assume that with some fiddling you can make it work.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 18, 2024, 12:54pm UTC](https://mne.discourse.group/t/noise-in-epoch-after-filter-ica-epochreject/9294/8 "2024-09-18T12:54:36Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
