How to recognize organism state via EEG?

I’m still new in EEG, and I need advice about the strategy of working with available data. The main idea is to recognize whether a person is tired or not. My way of thinking was started from setting max and min frequency filters 8-15Hz because as I read the best for drowsiness detection is alpha waves. Then I applied ICA filters, which as personally I understood required for removing artifacts like eye blinking and so on (because we don’t have any other channels for the file only EEG). And now I’m not sure what to do then.

In the end I’m trying to understand whether a person is tired or now via EEG, so as I read from some papers I will need to classify my features of EEG, or what? Below you can see script which shows some of my results:

data_path = './'
vhdr_file_base_1 = os.path.join(data_path, 'S01_exp.vhdr')
raw = mne.io.read_raw_brainvision(vhdr_file_base_1, preload=True)  # read raw data with mne
info = raw.info

raw.plot(clipping=None, scalings='auto')

raw.load_data()

montage = mne.channels.make_standard_montage("biosemi32")
for ch in range(0, 32):
    mne.rename_channels(info, {info["ch_names"][ch]: montage.ch_names[ch]})

raw.set_montage('biosemi32', on_missing='ignore')

raw.filter(l_freq=1, h_freq=None)  # High-pass filter above 1 Hz
raw.filter(l_freq=None, h_freq=40)  # Low-pass filter below 40 Hz
raw.filter(l_freq=8, h_freq=30)  # Band-pass filter between 8 and 30 Hz
raw.notch_filter(freqs=50)  # Notch filter at 50 Hz (power line noise)

# The regression technique works regardless of chosen reference. However, it is
# important to choose a reference before proceeding with the analysis.
raw.set_eeg_reference("average")

# Removing slow drifts makes for more stable regression coefficients. Make sure
# to apply the same filter to both EEG and EOG channels!
raw.filter(0.3, 40)

# # set up and fit the ICA
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2]  # details on how we picked these are omitted here

raw.plot()
raw.compute_psd(fmax=50).plot(picks="eeg", exclude="bads", amplitude=False)
raw.plot_psd()
raw.plot(duration=5, n_channels=30)
ica.plot_properties(raw, picks=ica.exclude)

method = 'fastica'

# Choose other parameters
n_components = 25  # if float, select n_components by explained variance of PCA
decim = 3  # we need sufficient statistics, not all time points -> saves time
random_state = 23
ica = ICA(n_components=n_components, method=method, random_state=random_state)
print(ica)
reject = dict(mag=5e-12, grad=4000e-13)

picks_meg = mne.pick_types(raw.info, meg=False, eeg=True, eog=False,
                           stim=False, exclude='bads')
ica.fit(raw, picks=picks_meg, decim=decim, reject=reject)
print(ica)

ica.plot_components()
ica.plot_sources(raw)

But maybe I’m wrong. In general the another idea was to convert the raw EEG data to numpy and compare with other available EEG files after the experiments, with possible analysis of alpha waves, but I’m not sure that this is very promissing direction.

It will be good when I will just have some understanding what to do next and the strategy in general, because now I’m little bit confused :smiley: and also not sure whether all what I had done and think now are correct :slight_smile:

Hello, how long is your recording? Do you have events or did you record resting-state EEG? If you have no events, you could look at alpha power over time and based on the power value (higher alpha power => participants more tired) classify sleepiness in individual participants over time. Maybe tutorials dealing with sleep staging might also be helpful.

Best,

Carina

2 Likes

Hi, thank you for your response. The length of recording is about 2-2.5 minutes. Yes, I have resting-state EEG, but no events. Just EEG and that is all. I checked the power tutorial, so it’s possible as I see to handle only alpha power as I see what will the possible solution for me, right?

Best,
Andrii

also when I’m trying to get events like below:
events = mne.events_from_annotations(raw)

and then from mne tutorial:

# picks MEG gradiometers
picks = mne.pick_types(raw.info, meg="grad", eeg=False, eog=True, stim=False)

# Construct Epochs
event_id, tmin, tmax = 1, -1.0, 3.0
baseline = (None, 0)
epochs = mne.Epochs(raw, events, tmin=-0.3, tmax=0.7)

epochs.compute_psd(fmin=2.0, fmax=40.0).plot(
    average=True, amplitude=False, picks="data", exclude="bads"
)

epochs.compute_psd().plot_topomap(ch_type="grad", normalize=False, contours=0)

it gives error:
TypeError: events should be a NumPy array of integers, got <class 'tuple'>

but I don’t have any events, so maybe it’s possible to work with epochs without events?

According to the documentation, events_from_annotations() returns a tuple (events, event_id). So you will want to change your call of the function to:

events, event_id = mne.events_from_annotations(raw)
1 Like

thank you for you help, but it still does not have ability to compute psd because of error:

ValueError: zero-size array to reduction operation minimum which has no identity

but as I see I have some values in epochs, or I’m wrong with it:

You only have one epoch… i don’t know if this is actually what you want. And I would assume that this one even gets dropped when you call epochs.load_data() as it’s just the marker at the very start of the recording, so MNE will probably not be able to find a baseline signal.

in general I don’t have any stimuli inside the eeg, just plain recording during some time and that is all. Because of so small amount of features I asked here what to do and how to recognize states of the body. And now after some more context from @CarinaFo and you, I’m trying to build some plots or analyze values of alpha power during the record.

You could create rolling window epochs with mne.make_fixed_length_epochs.

it should be done before plotting or at which place?

I did the current window, but now when I use such code:

epochs = mne.make_fixed_length_epochs(raw)

epochs.compute_psd(fmin=2.0, fmax=40.0).plot(
    average=True, amplitude=False, picks="data", exclude="bads"
)

epochs.compute_psd().plot_topomap(normalize=False, contours=0)

with several different EEG files from the experiments, it usually gives the similar results:

even when between two files was 4-5 hours between measurements, or it’s ok?

This looks fine to me, what’s your concern here?

I’m trying to understand where to see difference between two similar plots and for example to say that we have wrong body state :frowning:

I don’t think you’ll be able to see that with your eyes. You’ll need to run some statistics or machine learning model. I’d suggest checking the literature to learn how others have done it.

Good luck,
Richard

thank you for your response, in general I thought it would be visually visible via plot, but now I understand that better run some pipeline for further classification. I will try to continue, in any case I will usually able to ask here for better search direction for such newbie people like me :smiley: Thank you and have a nice day!

Andrii

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