Understanding how Epochs work

I have annotated EEG data (raw; continuous) spanning 900 s. The start of Event A coincides with t = 0 and runs for 30 s. Followed by Event B which runs for the next 30 s. This cycle repeats till the end of the data.

So, I execute the following code for epoching into the default 0.7s segments:

raw = ...
epochs = mne.epochs(raw, mne.events_from_annotations(raw)[0], event_id=mne.events_from_annotations(raw)[1], preload=True);
Ev_A_epochs = epochs['Event A']
Ev_B_epochs = epochs['Event B']

So, 15 epochs corresponding to Event A and another 15 corresponding to Event B are created.

Query: All epochs (taken together) span (15+15) * 0.7 = 21 s which means 900 - 21 = 879 s worth of data was lost. Am I correct? Such being the case, how were these 0.7s segments sampled from the 30s events (almost 43 times as long) during the creation of epochs?

The tmin, tmax are relative to the event onset. For instance, if you have a continuous recording of 10 seconds with a trigger onset at t=1 second, then tmin=-0.5, tmax=2 will create an epoch which starts at t=0.5 (event - 0.5) and ends at t=3 (event + 2). It’s simply cropping the data.

import numpy as np

from matplotlib import pyplot as plt
from mne import create_info, Epochs
from mne.io import RawArray


info = create_info(["AF7"], 1024, "eeg")
data = np.random.randn(1, 5120)
data[0, 800:1200] *= 3
raw = RawArray(data, info)
events = np.array([[1024, 0, 1]])  # event at t=1 second (1024 samples)
epochs = Epochs(
    raw, events, event_id=dict(my_evt=1), baseline=None, tmin=-0.5, tmax=2
)

raw_data = raw.get_data()  # (1, 10240) - (1 channel, n_samples)
epo_data = epochs.get_data()  # (1, 1, 2561) - (1 epoch, 1 channel, n_samples)

f, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(raw.times, raw_data[0, :])
ax[0].set_title("Raw data")
ax[1].plot(epochs.times + 1, epo_data[0, 0, :])  # event is at t=1 second
ax[1].set_title("Epoch positionned on the same time-axis")

image

The default 700 ms window is good in most ERP analyses, where you have an event that elicits a short brain response. In this case, you consider the 200 ms before the event comes up as a baseline and you study the reaction to the event in the following 500 ms.

2 Likes