Station 0 · Lesson 5

Designing EEG experiments

Optional15 minBefore this lesson: Where the EEG signal comes fromPrint the card

The idea in brief

No processing step in EEGLAB can fix a badly designed experiment. If the stimulus timing was not recorded, you cannot cut the data around it. If there are too few trials, the ERPThe brain's average response to a given event across many trials. stays buried in noiseAny part of the recording that does not carry the information we want. no matter how well you clean it.

Before and after

Two timelines of two consecutive trials. Weak design: fixation, stimulus, press, fixed gap, no event marks, timing saved in the presentation software only. Good design: the same sequence with a square mark at the stimulus and an rt mark at the press, a random-length gap, and a photodiode on the screen corner.

Your next questions, each answered in its own section:

Why do I need this step?

The reasons in detail, and the terms you need

This lesson is optional, because the path works on data that has already been recorded. But it matters a lot if you will record your own data, or want to judge an open datasetOne EEG data file loaded in EEGLAB together with its information. before choosing it.

How do I do it in EEGLAB?

There are no EEGLAB steps in this lesson, because designThe definition of which conditions and groups a STUDY compares. happens before recording.

After recording, you will check the result of the design in EEGLAB in the events lesson: you list the events, their types and timing from Edit then Event values, and see them as vertical lines over the signalValues that change over time, such as the voltage recorded on a channel. in Plot then Channel data (scroll).

How do I write it as code?

The same steps in 20 lines of MATLAB

This scriptA MATLAB file of commands that runs processing steps in order. does not need EEGLAB. It simulates the most important design decision: the number of trials. Each trialOne repetition of the task, usually around a single stimulus. contains the same wave (like a P3 component of 5 microvolts) plus random noise much larger than it. Then it averages different numbers of trials.

MATLAB
% How the number of trials changes the noise left in an average
srate = 250;                                         % samples per second
t     = -0.2:1/srate:0.8;                            % epoch from -200 to 800 ms
erp   = 5 * exp(-((t - 0.35).^2) / (2*0.08^2));      % P3-like wave, 5 microvolts
rng(1);                                              % same noise on every run

nTrials = [10 40 160];
labels  = cell(1, numel(nTrials));
figure; hold on;
for k = 1:numel(nTrials)
    n      = nTrials(k);
    trials = erp + 20 * randn(n, numel(t));          % same wave + noise on each trial
    avg    = mean(trials, 1);                        % the average across trials
    noise  = std(avg(t < 0));                        % noise left in the pre-stimulus period
    fprintf('%4d trials: noise left = %.2f microvolts\n', n, noise);
    plot(t*1000, avg);
    labels{k} = sprintf('%d trials', n);
end
plot(t*1000, erp, 'k', 'LineWidth', 2);
xlabel('Time (ms)'); ylabel('Amplitude (\muV)');
legend([labels, {'True wave'}]);
  • A single trial does not show the wave, because the noise (20 microvolts) is four times larger than it.
  • When you average, the constant wave stays and the random noise cancels out (Luck, Appendix 1).
  • The remaining noise shrinks with the square root of the number of trials. Four times more trials only halves the noise.
  • Simplification: real noise is not fully random, and the wave varies a little between trials.

Which value should I choose?

Suitable values for your analysis goal

This is a checklist for any design, with the reason and source for each item.

ItemWhat you doWhy
Trials per conditionAn experimental situation compared with others, such as familiar vs unfamiliar.Start from the number used in published studies of the same component, and add a margin for trials that will be rejectedNoise shrinks only with the square root of the number (script above), and small components need more trials
eventA marker in the recording that flags a moment of interest, such as a stimulus. recordingSend a code for each event (stimulus and response) directly to the EEGA recording of the brain's electrical activity from electrodes on the scalp. systemThe presentation software log alone is not enough to cut the data. The EEGLAB tutorial advises relying only on event signals sent directly to the EEG system
Timing accuracyMeasure the delay between the event code and the stimulus appearing on screen with a photodiodeOrdinary screens can delay the display or draw it in parts. In reaction-time research a 10-millisecond difference is considered large (EEGLAB tutorial). The tutorial also recommends a sampling rateThe number of samples recorded per second on each channel. of at least 1000 Hz for event-related recordings so event timing is precise
Comparison conditionTwo conditions that differ in one factor onlyIf the conditions differ in both brightness and meaning, you cannot tell which one caused the ERP difference
Trial orderRandomize the conditions, and vary the gap between trials slightlySo the participantThe person whose data were recorded in the study. cannot predict the next stimulus, and activity from one trial does not overlap the next in a fixed pattern
Eye channelsRecord EOG channels above, below and beside the eyesTo detect blinks and eye movements later (Luck, Appendix 1)
Recording environmentKeep screens and power sources away from the participant, and check electrode impedance before startingScreens and lights are the main sources of power-line noise, and a bad reference electrode spoils every channel (EEGLAB tutorial)

An example from the path: eeglab_data.set has two events: square when the stimulus appears, and rt at the button press. The participant presses only when the stimulus appears at the attended location (EEGLAB tutorial, dataset description). This is what makes cutting epochs around square possible in station 5.

How do I check it worked?

4 quick checks
  • The script prints three numbers for the remaining noise, each about half of the one before (close to 6.3, 3.2 and 1.6).
  • In the plot, the 160-trial curve is the closest to the black true wave.
  • You can name two checklist items that cannot be fixed after recording: event recording and event timing.
  • Given a design with two conditions, you can say whether they differ in one factor or more.

What mistakes do people make?

5 mistakes and how to avoid them
  • Events saved only in the presentation software. After recording you find that the EEG file has no events, or events that do not match the timing. Test sending codes before the first participant.
  • Not measuring screen delay. Every component will appear late by the same unknown amount, and the delay may vary between trials.
  • Two conditions that differ in more than one factor. The ERP difference cannot be attributed to a single factor.
  • A trial count with no margin. After rejecting bad trials in station 5, fewer trials than needed may remain.
  • Recording without EOG channels. Telling blinks and eye movements apart becomes harder in station 4.

Where can I read more?

4 sources, official docs first

Written for EEGLAB 2026.1 · 2026-10-27

Need help?

Ask, share feedback, or report an error