A PsychoPy implementation of a block-design N-back working memory task developed for functional Near-Infrared Spectroscopy (fNIRS) experiments.
The paradigm was developed for evaluating a wearable multimodal forehead-mounted fNIRS sensor during cognitive workload induction.
The N-back task is a well-established cognitive paradigm widely used to investigate working memory and prefrontal cortex activation. This implementation includes:
- 0-back (control condition)
- 2-back (working memory condition)
- Adaptive practice phase
- Pseudorandomized block design
- Trial-by-trial behavioural recording
- High-precision event logging for fNIRS synchronization
- Performance feedback between blocks
- Automated generation of behavioural and event log files
The task was designed specifically for fNIRS studies targeting prefrontal cortex activity and cognitive workload assessment.
The experiment consists of:
- 8 × 0-back blocks
- 8 × 2-back blocks
- 16 task blocks in total
- Pseudorandomized block order
- No condition appears more than twice consecutively
A target digit is presented at the start of each block.
Participants press:
- Match key when the displayed digit equals the target digit
- Non-match key for all other digits
This condition primarily measures sustained attention and response execution while minimizing working memory demand.
Participants press the match key when the current digit matches the digit presented two trials earlier.
Example:
Sequence:
3 → 7 → 3 → 5 → 5
The third digit ("3") is a target because it matches the digit presented two trials earlier.
The first two stimuli in each 2-back block have no valid reference and are always treated as non-targets.
---
- One mandatory practice block
- Additional block if accuracy < 80%
- Minimum of two practice blocks
- Additional practice provided if accuracy remains below 80%
- Trial-by-trial feedback is shown during practice
No feedback is provided during the main experiment.
For each trial the following information is saved:
- Block number
- Condition
- Trial number
- Presented digit
- Target status
- Correct response
- Participant response
- Response accuracy
- Reaction time
- Stimulus onset time
A dedicated event log is automatically generated for synchronization with physiological recordings.
Logged events include:
- Baseline start
- Cue start
- Task start
- Task end
- Rest start
- Rest end
- Block order
- Experiment end
Each event contains:
- Relative timestamp
- Wall-clock timestamp
- Block number
- Condition
- Additional metadata
This allows precise alignment with fNIRS acquisition systems during offline analysis.
Prior to deployment with the custom wearable fNIRS sensor, the paradigm was validated by performing experiment on 10 subjects using the Artinis Frontal BriteLite system. The paradigm elicited the expected bilateral prefrontal hemodynamic activation, with stronger activation during the combined 0-back and 2-back task periods compared to rest (Figure 1). This confirms the task's sensitivity to cognitive load manipulation.
Figure 1. Mean oxygenated hemoglobin (HbO) concentration during task (0-back + 2-back) and rest, averaged across all channels. The task condition elicited significantly higher activation than rest.
Group block-averaged hemodynamic responses (Figure 2) demonstrated the canonical increase in HbO and decrease in HbR during the 2-back task blocks in both hemispheres, with a slightly stronger response observed in the right hemisphere.
Figure 2. Block-averaged HbO and HbR responses in the left and right prefrontal cortex during the 2-back task. Both hemispheres exhibited the expected hemodynamic response, with slightly greater activation in the right hemisphere.
At the individual level, 7 of 10 participants exhibited right-dominant prefrontal activation during the 2-back condition (Figure 3), whereas two participants showed left-dominant activation and one displayed symmetric activation.
Figure 3. Individual prefrontal lateralization during the 2-back condition, computed as right-minus-left HbO. Most participants showed right-dominant activation (blue), while two exhibited left dominance (orange) and one showed symmetric activation.
This validation confirmed that the implemented timing parameters, block structure, and task demands were sufficient to reliably elicit cognitive-load-related haemodynamic responses.
participantID_date.csv
Contains trial-level behavioural performance.
participantID_date_events.csv
Contains block and event timing information for synchronization with fNIRS recordings.
- Python 3.x
- PsychoPy 2026.1.1 or newer
Install PsychoPy:
pip install psychopypython n_back_task.pyParticipants are prompted for:
- Participant ID
- Session Number
The experiment then proceeds through:
- Instructions
- Practice
- Baseline
- Main Task
- End Screen
This task was developed within the Electronics and Informatics Department (ETRO), Vrije Universiteit Brussel (VUB), as part of a Master's Thesis investigating wearable multimodal fNIRS sensing for cognitive workload monitoring.
The paradigm was designed to provide robust and reproducible working-memory-related haemodynamic responses suitable for both sensor validation and future cognitive neuroscience applications.
The task is intended for use with:
- Wearable fNIRS systems
- Multimodal sensing platforms
- Cognitive workload estimation
- Brain-computer interface research
- Real-world neuroergonomics studies

