Station 0 · Lesson 5
Designing EEG experiments
Your browser's back button takes you to the exact place you were, so open anything you like.
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
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.
Why do I need this step?
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 dataset 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 do it in EEGLAB?
There are no EEGLAB steps in this lesson, because design 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 signal 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.
% 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.
How do I write it as code?
This script does not need EEGLAB. It simulates the most important design decision: the number of trials. Each trial 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.
% 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.
| Item | What you do | Why |
|---|---|---|
| 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 rejected | Noise 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. recording | Send a code for each event (stimulus and response) directly to the EEGA recording of the brain's electrical activity from electrodes on the scalp. system | The 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 accuracy | Measure the delay between the event code and the stimulus appearing on screen with a photodiode | Ordinary 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 condition | Two conditions that differ in one factor only | If the conditions differ in both brightness and meaning, you cannot tell which one caused the ERP difference |
| Trial order | Randomize the conditions, and vary the gap between trials slightly | So 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 channels | Record EOG channels above, below and beside the eyes | To detect blinks and eye movements later (Luck, Appendix 1) |
| Recording environment | Keep screens and power sources away from the participant, and check electrode impedance before starting | Screens 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.
Which value should I choose?
This is a checklist for any design, with the reason and source for each item.
| Item | What you do | Why |
|---|---|---|
| Trials per condition | Start from the number used in published studies of the same component, and add a margin for trials that will be rejected | Noise shrinks only with the square root of the number (script above), and small components need more trials |
| Event recording | Send a code for each event (stimulus and response) directly to the EEG system | The 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 accuracy | Measure the delay between the event code and the stimulus appearing on screen with a photodiode | Ordinary 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 rate of at least 1000 Hz for event-related recordings so event timing is precise |
| Comparison condition | Two conditions that differ in one factor only | If the conditions differ in both brightness and meaning, you cannot tell which one caused the ERP difference |
| Trial order | Randomize the conditions, and vary the gap between trials slightly | So the participant cannot predict the next stimulus, and activity from one trial does not overlap the next in a fixed pattern |
| Eye channels | Record EOG channels above, below and beside the eyes | To detect blinks and eye movements later (Luck, Appendix 1) |
| Recording environment | Keep screens and power sources away from the participant, and check electrode impedance before starting | Screens 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.
How do I check it worked?
- 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.
What mistakes do people make?
- 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.
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.UndoWhere can I read more?
4 sources, official docs first
- EEGLAB Concepts guideDocumentationMaximizing EEG data quality; EEG synchronization
- EEGLAB TutorialDocumentationSample experiment description
- Luck, Applied Event-Related Potential Data Analysis (1st edition)Appendix 1 > Signal Averaging and Event-Related Potentials
- 16 advices for conducting electro-encephalography experimentsVideoFull video · 19:14
Written for EEGLAB 2026.1 · 2026-10-27
Going further
- EEGLAB Concepts guide: https://eeglab.org/tutorials/ConceptsGuide/Setting_up_your_EEG_lab.html (Maximizing EEG data quality; EEG synchronization)
- EEGLAB Tutorial: https://eeglab.org/tutorials/tutorial_data.html (Sample experiment description)
- Luck, Applied Event-Related Potential Data Analysis (1st edition): https://socialsci.libretexts.org/Bookshelves/Psychology/Biological_Psychology/Applied_Event-Related_Potential_Data_Analysis_(Luck)/12%3A_Appendix_1%3A_A_Very_Brief_Introduction_to_EEG_and_ERPs (Appendix 1 > Signal Averaging and Event-Related Potentials)
- 16 advices for conducting electro-encephalography experiments: https://www.youtube.com/watch?v=SSotxRqdFyY (Full video)
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".