Name: Sarah Badran
Student ID: 1782750
Course: PSYCH 403A1 - Neuroimaging and Neurostimulation
Assignment 6 - Option B: The 'Perfect' Hybrid System
EEG - fNIRS Hybrid Imaging: The Perfect Balance of Temporal and Spatial Precision
Introduction
1. Which Modalities and Why?
Electroencephalography (EEG) and functional near-infrared spectroscopy (fNIRS) are two of the most complementary non-invasive techniques available to cognitive neuroscience. EEG allows the recording of electric potentials from the brain that change at a rapid rate due to the summation of postsynaptic currents across cortical pyramidal neurons. EEG has the ability to record changes in electric potential very quickly (milliseconds) and minimal time lag because the changing electric field can propagate through the scalp and skull (Luck, 2014). However, the conducting layers of the head do smear information, and therefore accuracy in specifying the location varies by approximately a centimetre.
Functional near-infrared spectroscopy (fNIRS) measures changes in optical absorption due to the two types of hemoglobin: oxygenated (HbO) and deoxygenated (HbR), by emitting light between 700-900 nanometers. This light wavelength can penetrate a few millimetres into the cortical tissues, allowing for localized hemodynamic responses associated with the metabolism of neurons to be detected. While this methodology has lower temporal resolution and is slower (0.1-1 Hz) compared to EEG (1000 Hz), it provides spatial specificity with the goal of having temporal precision used during EEG. Overall, EEG and fNIRS provide information on neurovascular coupling (Yeung & Chu, 2022) or the cascade of events linking the firing of neurons and the local consumption of oxygen.
The hybrid methodology connects two important timescales: the electrophysiological millisecond range and the vascular second range. For instance, during a visual-attention task, EEG can pinpoint the P100 and N200 components, which reflect early sensory processing and selective-attention processing, while fNIRS maps the corresponding HbO increase in occipital and parietal cortices at the same time. Taken together, both systems allow researchers to subscribe to when a cognitive process is taking place with where in the cortex it is taking place. Because both systems are safe, portable, inexpensive, and tolerable for repeated measures across diverse populations, they are particularly well-suited to ecological experiments in non-laboratory scanners (Pinti et al., 2018).
2. How Would They Be Integrated?
The EEG-fNIRS hybrid proposed is a compact and ergonomically-designed cap evolving distinct dry metallic EEG electrodes coated with compatible optical transmission LED emission + photodiode detection combinations. The electrodes are positioned at the 64 standard 10-20 locations while the fNIRS optodes are interleaved based on a 30 mm spacing from the source to detector to create sampling through overlapping sensitivity volumes (Li et al., 2022). The electrodes and fNIRS optodes are isolated using a conductive mesh shielding to mitigate electromagnetic disturbance and light leakage. The complete configuration is lightweight (530 g) and has flexible padding with thermoplastic elastomers for comfort and passive ventilation to discourage sweating during time-intensive recordings.
The data acquisition occurs simultaneously with synchronized sampling clocks for EEG 1000 Hz and fNIRS 25 Hz. Both data streams are also time-locked via integrated hardware trigger pulses accurate to plus/minus 2 ms. These safeguards provide the close coupling necessary to identify between hemodynamic changes in arterial and venous blood oxygenation to earlier neural events. At the back of the cap, a compact processing unit executes preliminary amplification and artifact rejection before being wirelessly transmitted to a laptop or cloud server. Machine-learning processes on the GPU seamlessly integrate fast electrical bursts with slower oxygenation curves producing an integrated overview of unified cortical activation maps (Li et al., 2023).
User ergonomics are key considerations in the design. The cap utilizes stretch-fit materials, allowing it to accommodate different head sizes. In addition to its comfort, it features replaceable electrode pads and optode mounts specifically designed for hygiene. A rechargeable lithium-ion cell, capable of lasting 8-10 hours, provides power. Total radio-frequency emission remains below 1 mW/cm^2. EEG and fNIRS are both generally accepted as being non-significant risk for research purposes, which allows for repeated measures, in a safe manner, in research and clinical environments (Delpy & Cope, 1997). Therefore, the integration strategy strikes a balance between high-quality multimodal data and participant comfort, safety, and portability.
3. What Does Multimodal Data Look Like?
EEG and fNIRS produce streams of data simultaneously. EEG generates data as voltage traces (in microvolts) sampled at 1 kHz, whereas fNIRS data consists of concentration changes (derived from optical intensity) in oxygenated and deoxygenated hemoglobin (Delta[HbO], Delta[HbR]) ranging from 10 to 50 Hz (Chiarelli et al., 2017). The two modalities are co-registered to a head model post-artifact removal and band-pass filtering, which enables the generation of 4D activity maps (space x time x modality x participant). Subsequently, the EEG event-related potentials are juxtaposed on the oxygenation heatmaps for simultaneous visualizations of timing and activation spatial patterns of the neural substrates. Real-time data fusion on a GPU allows for sub-100 ms latency maps to be posted on the screen.
4. Technical and Practical Challenges
One major challenge is interference, motion artifacts, computational requirements, and privacy. The effects of crosstalk between optical and electrical components could be minimized through shielding and the optimal positioning of the sensors (Mussi et al., 2022). Motion artifacts from participant head movements and optode displacements can also be reduced through adaptive filters with accelerometer data or wavelet-based methods (Hossain et al., 2022). The degree of data synchronization across EEG and fNIRS platforms generates high data rates, requiring not only sufficient computational resources but also access to video graphics unit (GPU) accelerated pipelines for real-time fusibility and visualizations. Finally, safeguarding the security of participant data is of the utmost importance, most notably through end-to-end encryption, and role-based access controls and security (Pinti et al., 2018).
5. Real-World Applications
EEG-fNIRS hybrids are showing more promise in cognitive naturalistic experiments and clinical settings. These systems may provide researchers with the tools to observe natural fluctuations in cognitive workload, engaged attention, working memory, and decision-making in environments such as classrooms and workspaces (Pinti et al., 2018). Clinical efforts include the localization of seizure foci, assessing neurovascular functions, and aiding recovery from post-stroke physical rehabilitation with neurofeedback (Chen et al., 2023). In applications where the user performs intentional movements, such as rehabilitation of the motor domain or the operation of a brain-computer interface, results demonstrate an increase in performance classification when EEG and fNIRS features were fused earlier in the processing stream (Li et al., 2023). Once the portability of the fNIRS + EEG system becomes more adept, the prospect as a platform for monitoring mental states (i.e. cognitions) in real-world settings becomes plausible.
References
- Chen, J., Xia, Y., Zhou, X., Vidal Rosas, E., Thomas, A., Loureiro, R., Cooper, R. J., Carlson, T., & Zhao, H. (2023). fNIRS-EEG BCIs for Motor Rehabilitation: A Review. Bioengineering, 10(12), 1393. https://doi.org/10.3390/bioengineering10121393
- Chiarelli, A. M., Zappasodi, F., Di Pompeo, F., & Merla, A. (2017). Simultaneous functional near-infrared spectroscopy and electroencephalography for monitoring of human brain activity and oxygenation: a review. Neurophotonics, 4(04), 1. https://doi.org/10.1117/1.nph.4.4.041411
- Delpy, D. T., & Cope, M. (1997). Quantification in tissue nearβinfrared spectroscopy. Philosophical Transactions of the Royal Society of London. Series B: Biological Sciences, 352(1354), 649β659. https://doi.org/10.1098/rstb.1997.0046
- Hossain, M. S., Muhammad, Mamun, Ali, Ashrif, A., Serkan Kiranyaz, Amith Khandakar, Alhatou, M., Habib, R., & Hossain, M. M. (2022). Motion Artifacts Correction from Single-Channel EEG and fNIRS Signals Using Novel Wavelet Packet Decomposition in Combination with Canonical Correlation Analysis. Sensors, 22(9), 3169β3169. https://doi.org/10.3390/s22093169
- Li, R., Yang, D., Fang, F., Hong, K.-S., Reiss, A. L., & Zhang, Y. (2022). Concurrent fNIRS and EEG for Brain Function Investigation: A Systematic, Methodology-Focused Review. Sensors, 22(15), 5865. https://doi.org/10.3390/s22155865
- Li, Y., Zhang, X., & Ming, D. (2023). Early-stage fusion of EEG and fNIRS improves classification of motor imagery. Frontiers in Neuroscience, 16. https://doi.org/10.3389/fnins.2022.1062889
- Luck, S. J. (2014). An introduction to the event-related potential technique (2nd ed.). Mit Press.
- Mughal, N. E., Khan, M. J., Khalil, K., Javed, K., Sajid, H., Naseer, N., Ghafoor, U., & Hong, K.-S. (2022). EEG-fNIRS-based hybrid image construction and classification using CNN-LSTM. Frontiers in Neurorobotics, 16. https://doi.org/10.3389/fnbot.2022.873239
- Mussi, M. G., & Adams, K. D. (2022). EEG hybrid brain-computer interfaces: A scoping review applying an existing hybrid-BCI taxonomy and considerations for pediatric applications. Frontiers in Human Neuroscience, 16. https://doi.org/10.3389/fnhum.2022.1007136
- Pinti, P., Aichelburg, C., Gilbert, S., Hamilton, A., Hirsch, J., Burgess, P., & Tachtsidis, I. (2018). A Review on the Use of Wearable Functional Near-Infrared Spectroscopy in Naturalistic Environments. Japanese Psychological Research, 60(4), 347β373. https://doi.org/10.1111/jpr.12206
- Yeung, M. K., & Chu, V. W. (2022). Viewing neurovascular coupling through the lens of combined EEGβfNIRS: A systematic review of current methods. Psychophysiology, 59(6). https://doi.org/10.1111/psyp.14054
Other Course Work
π Assignment 1: EEG Analysis
π EEG_Assignment1_Fixed.ipynb - Colab - Sarah Badran.pdf
View Original PDFEEG Data Loading and Basic Filtering (Updated)
This notebook will help you complete Assignment 1 step by step.
Includes ! xed Step 4 (Frequency Analysis) with both individual electrode
spectra and average spectrum .
PSYCH 403A1 - Assignment 1 ξ Setting up your brain data analysis toolkit... ββββββββββββββββββββββββββββββββββββββββ 7.4/7.4 MB 32.7 MB/s eta 0:00: SUCCESS! All tools loaded and ready to go! MNE version: 1.10.1 NumPy version: 2.0.2 # STEP 1: Install & Import Required Packages print ( " Setting up your brain data analysis toolkit..." ) ! pip install -q mne matplotlib numpy scipy requests import mne import numpy as np import matplotlib.pyplot as plt from scipy import signal import requests import os from pathlib import Path plt.rcParams[ 'figure.figsize' ] = ( 10 , 6 ) plt.rcParams[ 'font.size' ] = 11 plt.rcParams[ 'lines.linewidth' ] = 1.5 mne.set_log_level( 'WARNING' ) print ( " SUCCESS! All tools loaded and ready to go!" ) print ( f " MNE version: {mne. __version__ } " ) print ( f " NumPy version: {np. __version__ } " ) # STEP 2: Load Brain Wave Data print ( " Loading brain wave data (this might take a moment)..." ) ο§
Loading brain wave data (this might take a moment)...
SUCCESS! Brain data loaded!
Data info:
Length: 277.7 seconds
Channels: 59 EEG electrodes
Sampling rate: 601 Hz
sample_data_folder = mne.datasets.sample.data_path ()
raw_file = Path(sample_data_folder) / 'MEG' / 'sample' / 'sample_audvis_ra
raw = mne.io.read_raw_fif(raw_file, preload= True )
raw.pick_types(meg= False , eeg= True , stim= False , exclude= 'bads' )
print ( " SUCCESS! Brain data loaded!" )
print ( f " Data info:" )
print ( f " Length: {raw.times[ -1 ] :.1f } seconds" )
print ( f " Channels: { len (raw.ch_names)} EEG electrodes" )
print ( f " β‘ Sampling rate: {raw.info[ 'sfreq' ] :.0f } Hz" )
raw.plot(n_channels= 10 , duration= 5 , scalings= 'auto' )
EEG 001
38.67 V
EEG 002
EEG 003
EEG 004
EEG 005
EEG 006
EEG 007
EEG 008
EEG 009
EEG 010
2
Help
50 100 150 200
50 100 150
Time (s) 200 Applying band-pass filter (1-40 Hz)... Filter applied! # STEP 3: Basic Filtering print ( " Applying band-pass filter (1-40 Hz)..." ) raw_filtered = raw.copy(). filter (l_freq= 1 ., h_freq= 40 .) print ( " Filter applied!" ) raw_filtered.plot(n_channels= 10 , duration= 5 , scalings= 'auto' )
Calculating frequency spectrum...
# STEP 4: Frequency Analysis (Power Spectral Density)
print ( " Calculating frequency spectrum..." )
# Use modern MNE function
psd = raw_filtered.compute_psd(fmin= 1 , fmax= 40 , n_fft= 1024 )
psds, freqs = psd.get_data(return_freqs= True )
# Plot all electrode spectra
plt.figure(figsize=( 10 , 5 ))
for psd_line in psds:
plt.plot(freqs, psd_line, color= 'lightgray' , alpha= 0.5 )
# Add average spectrum (bold)
mean_psd = psds.mean(axis= 0 )
plt.plot(freqs, mean_psd, color= 'red' , linewidth= 2 , label= 'Average Spectru
plt.xlabel( "Frequency (Hz)" )
plt.ylabel( "Power (dB)" )
plt.title( "EEG Frequency Spectrum (1β40 Hz)" )
plt.legend()
plt.show()
Start coding or generate with AI.
π EEG_Assignment1_Fixed-2 - Sarah Badran.ipynb
Jupyter Notebookπ‘ Opens in Google Colab for interactive execution. Requires Google account.
π¨ Assignment 2: BrainImation
π Assignment 2 psych 403 - Sarah Badran.pdf
View Original PDFCode: We had troubles saving the code so it is pasted below:
// Brain particle system
let particles = [];
function setup() {
// HSB in 0..1 (you already had this)
colorMode( HSB , 1 , 1 , 1 );
for ( let i = 0 ; i < 100 ; i++) {
particles.push({
x: random(width),
y: random(height),
// base fast velocities (your choice kept)
vx: random( 0 , 50 ),
vy: random(- 2 , 50 ),
life: 1.0 ,
seed: random( 1 ) // NEW: per-particle hue for rainbow
});
}
}
function draw() {
// Use BrainImation sliders: Attentionβbeta, Meditationβalpha
const alpha = (eegData.meditation ?? eegData.alpha ?? 0 );
const beta = (eegData.attention ?? eegData.beta ?? 0 );
// stress logic: true if attention > meditation
const stressed = beta > alpha + 0.02 ; // tiny margin avoids flicker
// BG: stressed = white, calm = dark
if (stressed) background( 0 , 0 , 1 , 0.15 );
else background( 0 , 0 , 0.06 , 0.10 );
// speed scale: calm slow, stressed fast
const speed = stressed ? 1.0 : 0.18 ; // <<< slow when calm
for ( let p of particles) {
// Movement influenced by brain waves (your logic kept)
p.vx += (random(- 1 , 1 ) * (eegData.alpha ?? alpha) * 0.1 );
p.vy += (random(- 1 , 1 ) * (eegData.beta ?? beta) * 0.1 );
// Apply speed scaling (NEW)
p.x += p.vx * speed;
p.y += p.vy * speed;
// Wrap around
if (p.x < 0 ) p.x = width;
if (p.x > width) p.x = 0 ;
if (p.y < 0 ) p.y = height;
if (p.y > height) p.y = 0 ;
// Color: stressed = red, calm = rainbow (NEW)
let hue = stressed ? 0.0 : (p.seed + frameCount * 0.002 ) % 1.0 ;
fill(hue, 0.9 , 0.95 , p.life);
noStroke();
ellipse(p.x, p.y, 5 + (eegData.gamma ?? 0 ) * 10 );
// life (your fade kept)
p.life *= 0.995 ;
if (p.life < 0.1 ) p.life = 1.0 ;
}
}
Demo
Calm Mode:
Meditation β 0.8 β Attention β 0.2 β
Dark background, slow/rainbow drift
Stressed mode:
Attention β 0.9 β Meditation β 0.1 β
White background, red fast streaks
Zen Blood Particles: A Brain-Controlled Visualization of Stress and Calm
Contributors:
Ayaan Jimale, Sarah Badran, Marinaya Saigh, Hamza Razzo
Concept
Our project began with the Brain Particles example from the BrainImation platform.
We wanted to transform a simple particle system into a bio-responsive visualization of stress and calm
β a sort of βdigital moodβ that reflects brain activity. When a user becomes stressed (higher beta /
attention activity), the screen erupts into fast-moving red particles against a white background,
resembling blood splatter or heightened physiological arousal. When the user relaxes (higher alpha /
meditation activity), the environment shifts to a dark background with slow, softly colored rainbow
particles drifting gently. The contrasting aesthetics represent two opposing brain states: tension versus
calm.
Technical Implementation
We used the built-in BrainImation variables eegData.attention (as a proxy for beta ) and
eegData.meditation (as a proxy for alpha ).
The program continuously compares these two values to determine the current state:
if attention > meditation β stressed mode
else β calm mode
Stressed Mode
β White background
β Red particles
β High velocity (up to 50 px per frame)
β Slight downward/right bias to suggest urgency and gravity
Calm Mode
β Dark background
β Rainbow-cycling particle hues (based on each particleβs seed and frame count)
β Reduced velocity for smoother, slower drift
To avoid flicker during rapid EEG fluctuations, the code includes a small threshold (attention >
meditation + 0.02) before switching states.
This keeps transitions visually stable while remaining responsive in real time.
The system also uses the βSimulate Dataβ mode for testing, with the Attention and Meditation
sliders controlling stress and calm levels manually.
When connected to a Muse headset, these values update automatically from the userβs EEG signals.
Challenges
Early versions of the code produced constant flickering because simulated EEG data changed
frame-by-frame. We fixed this by slightly smoothing the inputs and introducing a small difference
threshold before toggling modes. Another challenge was balancing aesthetics and performance: large
particle velocities looked dramatic but caused visual clutter, so we tuned the speed scale for a more
natural flow. We also adjusted HSB color ranges so that red remained vivid on a white background
while rainbow hues remained visible on a dark one.
What We Learned
Working with BrainImation showed how small numerical differences in brain-wave bands can create
striking visual differences. We learned how to translate abstract EEG measures (alpha vs beta) into an
intuitive sensory experience of stress versus relaxation. The project also reinforced principles of
real-time visualization, such as smoothing noisy data, scaling motion by signal intensity, and
designing visual metaphors that match psychological states.
Future Improvements
β Add gradual color blending instead of hard switching between modes.
β Include subtle particle size or opacity changes linked to overall calmness level.
β Experiment with live Muse input to explore individualized thresholds.
β Optionally add sound modulation for a multimodal neurofeedback experience.
Summary
Zen Blood Particles transforms EEG data into a visceral display of the brainβs changing internal state.
By mapping stress to speed and color intensity, and calmness to slow, colorful drift, the animation
becomes a live mirror of the userβs mental tension and relaxation β a minimal yet powerful
demonstration of brain-computer interaction through art.
π― Midterm Project
π sarah bardan description for part 1 and part 2 - Sarah Badran.pdf
View Original PDFSarah Badran/1782750
Course: PSYCH 403A1 β Neuroimaging and Neurostimulation
Part 1: Adaptive Flow Neurofeedback: Beyond Basic Control
The project is based on extending the previous Assignment 2 particle system to a neurofeedback -
based visual output that adjusts and updates in real - time to the simulated EEG input. Using
BrainImation's Attention ( Ξ²) and Meditation ( Ξ±) variables, I compute engagement = Ξ² - Ξ± and
determine a flow window near 0.06. The program continuously smooths incoming values to
prevent flickering, as well as calculates distance from the target, and does modifies each session's
difficulty through real - time adaptive tolera nce bands .
When the user drifts out of flow (large Ξ² - Ξ±) the animation becomes stormy and chaotic and the
center cue reads, βAttention Fluctuating - Recenter.β As values move closer together, the system
enters a calm concentration zone, displays a smooth particle mo vement, and reads, βFocus
Stabilized .β The HUD provides a readout of tolerance metrics, engagement, score, and streak for
current status feedback about their performance and progress (real time neurofeedback).
The design of this model works as a closed - loop BCI system, rather than simple parameter
mapping to visuals in the form of a BCI interface. The animation provides a link between EEG -
derived signals to adaptive visual content output, and quantitative metri cs to train focused
attention engagement to further move the user toward a more stable, even state.
While "Focus Stabilized" can show up when Attention and Meditation have numbers that are not
numerically equal, this is intentional. The program defines a flow zone, where Attention is
slightly higher than Meditation ( Ξ² β Ξ± β 0.06), to indicate engaged but relaxed mental states,
rather than indicating that those two numbers are truly equal. Because the values are smoothed
over time, the system is responding to trends and averages rather than to single instantaneous
numbers, thereby producing more natural an d stable feedback. This reflects how real
neurofeedback systems reward us when we have good balance with our focus, and when we
achieve sustained mental alertness without overstimulation, rather than focusing on maintaining
absolute stillness.
Sarah Badran/1782750
Course: PSYCH 403A1 β Neuroimaging and Neurostimulation
Part 2
Component & Rationale. I recorded the N400, a negative - going ERP that peaks ~400 ms post -
meaningful stimuli. This component is larger (more negative) for semantically incongruent
versus congruent targets (e.g. CAT β TREE vs. CAT β DOG). The N400 component ind exes
semantic integration difficulty and violation of expectancy.
Stimulus Design & Timing. Each trial consists of prime β target word pairs selected from equal
numbers of match and mismatch items in a balanced design. I utilize a simple state machine with
four defined states: baseline ( β 200 β 0 ms), prime (400 ms), target (400 ms), and ITI (1000 ms).
The timing is compliant with the midterm having a pre - stimulus baseline and post - stimulus
period of ~800 ms in ~1 s epochs at 256 Hz (Muse rate).
At the onset of each target, I sample 256 samples in each of the four channels (TP9, AF7, AF8,
and TP10), run a baseline correction on the 200 β 0 ms, and add the correct epoch to the buffer
allocated to that condition (for example, match/mismatch). I run a moving average for the
specific condition and each channel capped at 20 trials so that the waveform is stable yet
responsive on the display. In the upper part of the display, it shows the condition averages for
each channel, and in the bottom part of the d isplay shows the current prime/target and a label
indicating the condition. Tick marks appear every 100 ms, and I also include an anchor time for 0
ms as a vertical line. I include running trial counters for each condition. Overall Satisfying the
ERP visua lization requirements.
With ~20 β 50 trials/condition, I expect a more negative deflection ~300 β 500 ms post - target for
mismatch versus match, largest over central β parietal regions (Muse coverage is limited but will
show a condition difference). I would expect the baseline to be ne ar 0 ΞΌV pre - stimulus; more
trials will help with SNR.
π₯ Screen Recording 2025-10-22 at 9.46.05β―PM - Sarah Badran.mov
π‘ Videos require Google Drive access. Open in new tab if it doesn't load.
π₯ Screen Recording 2025-10-26 at 5.32.03β―PM - Sarah Badran.mov
π‘ Videos require Google Drive access. Open in new tab if it doesn't load.
π badran_midterm_part2 - Sarah Badran.txt
π‘ Code is embedded in this portfolio - opens instantly in the live BrainImation editor (no internet required!)
π Badran_midterm_part1 - Sarah Badran.txt
π‘ Code is embedded in this portfolio - opens instantly in the live BrainImation editor (no internet required!)