Removing bad stretches and artifacts in EEG Signal

Hi all,
operating system: Windows 10
Trying to remove the bad stretches/interference/noise in the EEG signal.
This is the current plot.

Have seen mne document for handing and rejecting bad channels for meg and eog data.
I need to perform this for the eeg data.
This is how my data looks in csv format.

And also need to remove the artifacts using ICA.
Could you guide me with this?


Hello, almost all the information on bad channel removal and ICA that is being demonstrated on MEG data in our tutorials should apply to EEG data as well. So you can basically do the same, just feed in EEG instead of MEG data.

Best wishes,

Hello richard,

I have tried these two links. But, it’s not working for me. As I don’t have the events data in my dataset.
All the links use the events and only reject the bad stretches.
In my dataset all I have is the 14 channels and the labels to those 14 channel.
Tried using the labels as event, but was not successful.

Could you please guide me here with a proper documentation/tutorial? And also how do I remove the artifacts using ICA. Plotted the ICA like this and used ica.exclude() to remove. Is this the right way to do it.



are you saying you have continuous data without any events?



No, This how my dataset looks.

Totally 5 labels for each task (writing, resting etc…).

I don’t understand your question then… I also don’t understand why you’re always showing your data as a CSV file (?). :thinking: I thought you’d successfully imported it into MNE?

Sorry I showed it to get the context for events.
Yes I have imported it into MNE and created a raw array using the following and have also saved it in .fif incase.

info = mne.create_info(ch_names, ch_types=ch_types, sfreq=sampling_freq)
raw =, info)'data.fif',overwrite=True)

But then when I tried using mne.find_events and mne.Epochs .
I am getting

ValueError: Could not find event data

That’s why I should you the csv to show that I only have 14 channels and a label column in it.
I have imported the data and created a raw array , performed a FIR filter on top of it, now I’m required to remove the bad stretches and artifacts before performing FFT on them.
All the removing/reject/handling are event based on when I try them I get that error.

If I have done something wrong let me know the right way to perform it.

Thanks a lot for guiding me.

Well, it seems you’re not creating a stim channel then… that’s required by find_events(). Or you just have to create the events array manually, which would then allow you to skip using find_events().

In any case, you’ll need to take a step back and fix the data import, I’m afraid.

I have a stim channel, but the “label” column in the csv is becoming the stim channel.

Is that right?
If yes, then I have 4 labels totally but when I print the event id I am getting only 2.
But then again when I use mne.read_events I am getting this error.
TypeError: fname must be an instance of path-like, got <class ‘’> instead.
But I don’t have a path to the events, right.
Could you help me understand and sort this issue. Else like you said how to create events array manually.
Or is there a way to do remove the bad stretches and artifacts before performing FFT on them without the use of events field.
Thanks for being patient and guiding me. :blush:

Event codes must be >0 to be recognized; you seem to have -1 and probably 0. So you need to change this before you create the RawArray.

This result is after converting them only. The label values are now 1,2,3&4. not -1,0,1,2. It’s only detecting the events 2 and 4 not 1 and 3.
Firstly, is it right for the labels/classification to be considered as events.
Secondly, what should I do to get the other labels.

You could try passing consecutive=True to mne.find_events() and see if this changes anything. And probably pass initial_event=True as well.

Hi richard,

After adding these two in the mne.find_events(), all the 4 classes got recognized.
What are the 2nd and 3rd column in the below screenshot represent?


  1. Is it right for the labels/classification column in the table to be considered as events.
  2. There are totally 277548 samples(timestamps) but only 430 events are getting found.
  3. What to do when I use mne.read_events() need to provided fname for the event file right, but I don’t have it right. Asking for when not using mne.find_events().


See the glossary entry for “events”.

I suppose it’s one way to do it, so I’d cautiously say “yes”.

Only changes of the value of the stim channel are recognized as events. Anything else wouldn’t make much sense.

No idea, I don’t think read_events() is meant to support your use case / your specific data.

Best wishes,

A post was split to a new topic: Is there any way to perform feature extraction and logistic regression after removing bad stretches without the use of events and epochs?