Station 5 · Lesson 1
Extracting epochs
eeglab_data.set (D1) · Already applied: High-pass & low-pass filtering, Removing line noise (50/60 Hz), Bad channels, Channel interpolation, Re-referencing, Running ICA, 1-Hz filtering for ICA & copying weights, ICLabel & removing componentsDownload the data (opens in a new tab)Script to reach this state
% Shortcut: if you saved D1_main_clean_lp30.set in the ICLabel lesson, keep
% the first line and the last three lines, and replace every line between them with:
% EEG = pop_loadset('D1_main_clean_lp30.set', pwd);
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
eeglabRoot = fileparts(which('eeglab'));
EEG = pop_loadset('eeglab_data.set', fullfile(eeglabRoot, 'sample_data'));
fullLocs = EEG.chanlocs;
% Main dataset: high-pass at 0.1 Hz, then 60 Hz line-noise removal
EEG = pop_eegfiltnew(EEG, 'locutoff', 0.1);
EEG = pop_eegfiltnew(EEG, 'locutoff', 58, 'hicutoff', 62, 'revfilt', 1);
% Bad channels you removed earlier, e.g. {'T7'}; leave empty if none
badChans = {};
if ~isempty(badChans)
EEG = pop_select(EEG, 'rmchannel', badChans);
EEG = pop_interp(EEG, fullLocs, 'spherical');
end
% Average reference, EOG channels excluded
eogIdx = find(ismember({EEG.chanlocs.labels}, {'EOG1', 'EOG2'}));
EEG = pop_reref(EEG, [], 'exclude', eogIdx);
% ICA on a 1-Hz copy, then copy the weights back
EEG_ica = pop_eegfiltnew(EEG, 'locutoff', 1);
EEG_ica = pop_runica(EEG_ica, 'icatype', 'runica', 'extended', 1);
EEG.icaweights = EEG_ica.icaweights;
EEG.icasphere = EEG_ica.icasphere;
EEG.icachansind = EEG_ica.icachansind;
EEG.icawinv = [];
EEG.icaact = [];
EEG = eeg_checkset(EEG);
% Remove components ICLabel rates above 90% Eye or Muscle
EEG = pop_iclabel(EEG, 'default');
EEG = pop_icflag(EEG, [NaN NaN; 0.9 1; 0.9 1; NaN NaN; NaN NaN; NaN NaN; NaN NaN]);
artifactComps = find(EEG.reject.gcompreject);
if ~isempty(artifactComps)
EEG = pop_subcomp(EEG, artifactComps, 0);
end
% Low-pass at 30 Hz
EEG = pop_eegfiltnew(EEG, 'hicutoff', 30);
EEG.setname = 'D1 main clean lp30';
EEG.filename = ''; EEG.filepath = ''; EEG.datfile = ''; EEG.saved = 'no';
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, 0, 'setname', 'D1 main clean lp30', 'gui', 'off');
eeglab redraw;Your browser's back button takes you to the exact place you were, so open anything you like.
The idea in brief
Your data are now one continuous recording, about 4 minutes long. But an ERPThe brain's average response to a given event across many trials. question is about specific moments: what does the brain do right after the stimulus appears?
Before and after
Your next questions, each answered in its own section:
Why do I need this step?
The reasons in detail, and the terms you need
So you cut a time window around each eventA marker in the recording that flags a moment of interest, such as a stimulus., called an epoch. It starts a little before the event and ends a little after it. Every epochA short time segment cut out around an event. starts at the same time relative to its event, so you can compare epochs and later average them.
In D1, a square (square) appeared on the screen 80 times, and the participantThe person whose data were recorded in the study. pressed a button after some of them (event rt). We will cut around the square only.
Why do I need this step?
So you cut a time window around each event, called an epoch. It starts a little before the event and ends a little after it. Every epoch starts at the same time relative to its event, so you can compare epochs and later average them.
In D1, a square (square) appeared on the screen 80 times, and the participant pressed a button after some of them (event rt). We will cut around the square only.
How do I do it in EEGLAB?
7 steps in the menus
Start with the datasetOne EEG data file loaded in EEGLAB together with its information. D1 main clean lp30 open, as in “Starting point”.
- Open Tools then Extract epochs.
- The Extract data epochs - pop_epoch() window opens. Press the … button next to Time-locking event type(s) ([]=all).
- A list of event types appears:
rtandsquare. Selectsquareand press Ok. You can also typesquarein the box directly. - In Epoch limits [start, end] in seconds, keep the default
-1 2: from 1 second before the event to 2 seconds after it. - In Name for the new dataset, type
D1 epochs. - Leave Out-of-bounds EEG limits if any [min max] empty. Rejecting bad epochs has its own lesson, two lessons from now.
- Press Ok. The new-dataset window opens with Name it: set to the name you typed. Leave Overwrite it in memory (set=yes; unset=create a new dataset) unchecked, and press Ok.
The baseline window does not open
The official tutorial says a baselineThe pre-stimulus period used as the zero level for comparison. window opens automatically after epoching. In the EEGLAB 2026.1 code it does not; baseline correctionSubtracting the mean of the baseline period from each epoch. is a separate step under Tools then Remove epoch baseline, and it is the topic of the next lesson.
Instead of the window, the command window shows a message that starts with Warning: Do you also want to remove the single-trial ERP baseline. It is only a reminder, not an error.
The baseline window does not open
The official tutorial says a baselineThe pre-stimulus period used as the zero level for comparison. window opens automatically after epoching. In the EEGLAB 2026.1 code it does not; baseline correctionSubtracting the mean of the baseline period from each epoch. is a separate step under Tools then Remove epoch baseline, and it is the topic of the next lesson.
Instead of the window, the command window shows a message that starts with Warning: Do you also want to remove the single-trial ERP baseline. It is only a reminder, not an error.
How do I do it in EEGLAB?
Start with the dataset D1 main clean lp30 open, as in “Starting point”.
- Open Tools then Extract epochs.
- The Extract data epochs - pop_epoch() window opens. Press the … button next to Time-locking event type(s) ([]=all).
- A list of event types appears:
rtandsquare. Selectsquareand press Ok. You can also typesquarein the box directly. - In Epoch limits [start, end] in seconds, keep the default
-1 2: from 1 second before the event to 2 seconds after it. - In Name for the new dataset, type
D1 epochs. - Leave Out-of-bounds EEG limits if any [min max] empty. Rejecting bad epochs has its own lesson, two lessons from now.
- Press Ok. The new-dataset window opens with Name it: set to the name you typed. Leave Overwrite it in memory (set=yes; unset=create a new dataset) unchecked, and press Ok.
The baseline window does not open
The official tutorial says a baseline window opens automatically after epoching. In the EEGLAB 2026.1 code it does not; baseline correction is a separate step under Tools then Remove epoch baseline, and it is the topic of the next lesson.
Instead of the window, the command window shows a message that starts with Warning: Do you also want to remove the single-trial ERP baseline. It is only a reminder, not an error.
The baseline window does not open
The official tutorial says a baseline window opens automatically after epoching. In the EEGLAB 2026.1 code it does not; baseline correction is a separate step under Tools then Remove epoch baseline, and it is the topic of the next lesson.
Instead of the window, the command window shows a message that starts with Warning: Do you also want to remove the single-trial ERP baseline. It is only a reminder, not an error.
How do I write it as code?
The same steps in 6 lines of MATLAB
% Cut 3-s epochs around every 'square' event: 1 s before to 2 s after
EEG = pop_epoch(EEG, {'square'}, [-1 2], 'newname', 'D1 epochs', 'epochinfo', 'yes');
EEG = eeg_checkset(EEG);
% Channels x time points x epochs
disp(size(EEG.data));
fprintf('Epochs: %d, from %.3f s to %.3f s\n', EEG.trials, EEG.xmin, EEG.xmax);How do I write it as code?
% Cut 3-s epochs around every 'square' event: 1 s before to 2 s after
EEG = pop_epoch(EEG, {'square'}, [-1 2], 'newname', 'D1 epochs', 'epochinfo', 'yes');
EEG = eeg_checkset(EEG);
% Channels x time points x epochs
disp(size(EEG.data));
fprintf('Epochs: %d, from %.3f s to %.3f s\n', EEG.trials, EEG.xmin, EEG.xmax);Which value should I choose?
Suitable values for your analysis goal
| Goal | Window | Why |
|---|---|---|
| ERP only | Start at least 200 ms before the event, and end after the last ERP componentA specific wave in the ERP with a typical timing and meaning, such as P3 or N400. you care about | The part before the event is used as the baseline in the next lesson. Example: the N400 experiment in the ERP CORE data is epoched from -200 to 800 ms. |
| ERP plus time-frequencyAnalysis showing how power at each frequency changes over time. analysis | Longer, such as -1 2 here | The official tutorial recommends long epochs so that low frequencies (below 10 Hz) can be analyzed. |
| Our path on this site | -1 2 | The EEGLAB and official-tutorial default, and long enough for both the ERP and the ERSPThe change in power at each time and frequency relative to baseline. lessons. |
Rule of thumb: keep the window shorter than the gap between two events when you can. In D1, squares are about 3 seconds apart and our window is 3 seconds, so no stretch of data appears in two epochs, except once (two squares 0.7 s apart at the start of the recording).
An experiment with more than one conditionAn experimental situation compared with others, such as familiar vs unfamiliar.: epoch around all conditions together, then pick one condition before averagingAdding a condition's epochs together and dividing by their number.. EEGLAB has a menu for this, Edit then Select epochs or events, but in 2026.1 it stops on epoched data with an error. The channel-erp-plot lesson shows a short script that does the same. In D1 the two square positions are the two conditions, and we compare them in that lesson.
Which value should I choose?
| Goal | Window | Why |
|---|---|---|
| ERP only | Start at least 200 ms before the event, and end after the last ERP component you care about | The part before the event is used as the baseline in the next lesson. Example: the N400 experiment in the ERP CORE data is epoched from -200 to 800 ms. |
| ERP plus time-frequency analysis | Longer, such as -1 2 here | The official tutorial recommends long epochs so that low frequencies (below 10 Hz) can be analyzed. |
| Our path on this site | -1 2 | The EEGLAB and official-tutorial default, and long enough for both the ERP and the ERSP lessons. |
Rule of thumb: keep the window shorter than the gap between two events when you can. In D1, squares are about 3 seconds apart and our window is 3 seconds, so no stretch of data appears in two epochs, except once (two squares 0.7 s apart at the start of the recording).
An experiment with more than one condition: epoch around all conditions together, then pick one condition before averaging. EEGLAB has a menu for this, Edit then Select epochs or events, but in 2026.1 it stops on epoched data with an error. The channel-erp-plot lesson shows a short script that does the same. In D1 the two square positions are the two conditions, and we compare them in that lesson.
How do I check it worked?
3 quick checks
- In the EEGLAB main window: Epochs is 80, Frames per epoch is 384, Epoch start (sec) is -1, and Epoch end (sec) is about 1.992.
- In the command window:
size(EEG.data)returns32 384 80, and the baseline reminder starting withWarning:appears, which is expected. - Open Plot then Channel data (scroll): the data now appear as separate epochs with dividing lines, and each epoch has a
squareevent at zero.
How do I check it worked?
- In the EEGLAB main window: Epochs is 80, Frames per epoch is 384, Epoch start (sec) is -1, and Epoch end (sec) is about 1.992.
- In the command window:
size(EEG.data)returns32 384 80, and the baseline reminder starting withWarning:appears, which is expected. - Open Plot then Channel data (scroll): the data now appear as separate epochs with dividing lines, and each epoch has a
squareevent at zero.
What mistakes do people make?
5 mistakes and how to avoid them
- Epoching before filtering. Filtering short epochs distorts their edges. Filter the continuous data first, then epoch, as we did in station 3.
- Leaving the event type empty. An empty box means “all events”, so you get 153 epochs that mix square onsets with button presses (from 154 events, because the last button press is too close to the end of the recording and its epoch is lost). Always type the event type.
- A window that is too short. If the window starts at the event itself, there is no pre-event period for baseline correction. If it ends too early, you cut off late ERP components.
- Expecting the number of events to equal the number of epochs. Each epoch keeps every event that falls inside it, including the button press after the square. So
length(EEG.event)is larger thanEEG.trials. - Epochs lost at the edges of the recording. If an event is too close to the start or end of the recording, EEGLAB drops its epoch and prints a warning in the command window. In D1 the first square comes 1 second after the start, so no epoch is lost, but with no margin: a window starting at -1.1 s would lose the first epoch.
What mistakes do people make?
- Epoching before filtering. Filtering short epochs distorts their edges. Filter the continuous data first, then epoch, as we did in station 3.
- Leaving the event type empty. An empty box means “all events”, so you get 153 epochs that mix square onsets with button presses (from 154 events, because the last button press is too close to the end of the recording and its epoch is lost). Always type the event type.
- A window that is too short. If the window starts at the event itself, there is no pre-event period for baseline correction. If it ends too early, you cut off late ERP components.
- Expecting the number of events to equal the number of epochs. Each epoch keeps every event that falls inside it, including the button press after the square. So
length(EEG.event)is larger thanEEG.trials. - Epochs lost at the edges of the recording. If an event is too close to the start or end of the recording, EEGLAB drops its epoch and prints a warning in the command window. In D1 the first square comes 1 second after the start, so no epoch is lost, but with no margin: a window starting at -1.1 s would lose the first epoch.
Your browser doesn't allow saving progress. All lessons are open, but completion marks won't be saved.
Done. Your progress is saved in this browser.UndoHow do I write it in my paper?
A Methods template: edit the data, settings and versions to match what you ran
A template: edit the data, settings and versions to match what you ran.
Continuous data were segmented into epochs from -1 to 2 s relative to the onset of each square stimulus (pop_epoch, EEGLAB 2026.1), yielding [80] epochs.How do I write it in my paper?
A template: edit the data, settings and versions to match what you ran.
Continuous data were segmented into epochs from -1 to 2 s relative to the onset of each square stimulus (pop_epoch, EEGLAB 2026.1), yielding [80] epochs.Where can I read more?
3 sources, official docs first
- EEGLAB TutorialDocumentation7. Extract Data Epochs: Extracting data epochs
- Makoto's preprocessing pipeline§10 Epoch data
- Applied Event-Related Potential Data Analysis (Luck)2.07 Exercise: Epoching and Baseline Correction
Written for EEGLAB 2026.1 · 2026-10-28
Going further
- EEGLAB Tutorial: https://eeglab.org/tutorials/07_Extract_epochs/Extracting_Data_Epochs.html (7. Extract Data Epochs: Extracting data epochs)
- Makoto's preprocessing pipeline: https://eeglab.ucsd.edu/wiki/Makoto%27s_preprocessing_pipeline (§10 Epoch data)
- Applied Event-Related Potential Data Analysis (Luck): https://socialsci.libretexts.org/Bookshelves/Psychology/Biological_Psychology/Applied_Event-Related_Potential_Data_Analysis_(Luck) (2.07 Exercise: Epoching and Baseline Correction)
Need help?
Ask, share feedback, or report an error
- Report a scientific error · Needs a GitHub account. Don't have one? Use "Share your thoughts".