Overview: EEG Sonification and Polyphonic Mapping
Electroencephalographic sonification translates complex temporal and spectral brainwave voltage fluctuations into auditory parameters such as pitch, timbre, volume, and rhythm. While classical time-series line charts and periodogram power spectral density plots allow visual inspection of electrophysiological signals, human auditory perception excels at detecting subtle non-stationary frequency shifts, harmonic entrainments, and multi-channel phase interactions that may remain subtle or obscured in visual displays.
In patients with focal epilepsy recorded via 16-channel intracranial EEG arrays (such as the NeuroVista trial recordings), the electrographic transition from the interictal background state to pre-ictal hypersynchrony and active tonic-clonic discharge is characterized by drastic spectral shifts. Background brain activity consists of asynchronous, low-amplitude multi-band noise across Delta ($0.5\text{--}4\text{ Hz}$), Theta ($4\text{--}8\text{ Hz}$), Alpha ($8\text{--}13\text{ Hz}$), and Beta ($13\text{--}30\text{ Hz}$) bands. During seizure onset, local neural populations undergo intense synchronization, causing rapid narrow-band energy bursts that degrade into rhythmic spike-wave discharges.
This interactive laboratory maps these discrete physiological frequency bands directly to multi-octave polyphonic musical scales using Web Audio API synthesis nodes. By evaluating auto-spectral power distributions, the workstation translates brain activity into real-time auditory harmonies while simultaneously rendering high-contrast oscilloscope line charts and Welch power spectral density curves.
How To Use: Interactive Terminal Configuration
This virtual laboratory operates as a serverless single-page workstation. The interface controls are arranged sequentially in the right-hand control panel to streamline signal analysis and musical sonification:
1. Dataset Selection: Use the Data Stream Source dropdown to toggle between Synthetic Seizure Dynamics and Real Patient iEEG (NeuroVista I004). Selecting the Real Patient stream triggers an asynchronous, serverless load of the 2.5 MB text file directly into local client memory, parsing 40,000 samples across 16 channels in milliseconds. Once parsed, toggling between the two modes is instantaneous.
2. Primary Action Controls: Located at the top of the workspace:
- Start Demo: Initiates a silky-smooth $60\text{ FPS}$ continuous timeline scroll across $100\text{ seconds}$, displaying interictal, pre-ictal, ictal, and post-ictal phases while updating the polyphonic music synth. Interacting with any control automatically halts the demo.
- Reset Baseline: Instantly resets all sliders, toggles, and data channels back to default parameters.
- Sound ON/OFF: Activates or suspends the Web Audio API synthesis engine. Note: Browsers require user interaction before playing audio, so click this button once to authorize the synth context.
3. Musical Controls:
- Base Synth Volume: Sets the fundamental gain multiplier for generated musical notes.
- Auto Volume: When enabled, automatically scales the synthesis volume dynamically based on total integrated power spectral density ($P_{\text{total}}$).
- Note Envelope Duration: Controls the exponential decay time ($0.5\text{--}5.0\text{ seconds}$) of the synthesized musical notes.
- Auto Duration: Dynamically links note decay times to the active viewing window size to match rendering speed.
4. Signal Processing Toggles: Enable or disable Wavelet Denoise to observe signal cleanup in real-time. Toggle Detrending to remove baseline low-frequency drift, and toggle Whole Spectrum Overlay to display unfiltered power spectral density outside the primary diagnostic bands ($<0.5\text{ Hz}$ and $>30\text{ Hz}$).
5. Dynamic Scaling (Autoscale): Toggle the Y-Axis Autoscale switch. When enabled, this algorithm dynamically scales the voltage trace vertically according to the peak-to-peak amplitude present within the visible temporal window. This prevents off-scale clipping of high-amplitude epileptic spikes while maintaining resolution on low-voltage background intervals.
6. Multi-Resolution Diagnostics: Expand the Advanced Diagnostics panel to select the discrete wavelet family (Haar or Daubechies 4), set the decomposition level ($1\text{--}10$), and adjust the threshold multiplier ($\lambda$).
Technical Details: Mathematical Algorithm Implementations
The processing architecture runs entirely client-side in vanilla JavaScript to guarantee high interaction performance without backend network latencies. The underlying mathematical operations are detailed below:
1. Linear Detrending
To eliminate baseline offset and slow linear drift caused by electrode polarization, the active time window $x[n]$ of length $N$ is detrended by computing the linear least-squares regression line $y[n] = m \cdot n + c$, where:
$$m = \frac{N \sum n x[n] - \sum n \sum x[n]}{N \sum n^2 - (\sum n)^2}, \quad c = \frac{\sum x[n] - m \sum n}{N}$$
The detrended signal $x_{\text{detrend}}[n] = x[n] - y[n]$ ensures a zero-mean baseline centered on the horizontal axis.
2. Discrete Wavelet Denoising (DWT / IDWT)
Multi-resolution signal decomposition uses discrete wavelet filter banks. The signal $x[n]$ is convolved with low-pass scaling filter $h[k]$ and high-pass wavelet filter $g[k]$, then downsampled by 2 at each level $j$:
$$a_j[n] = \sum_{k} a_{j-1}[k] h[2n - k], \quad d_j[n] = \sum_{k} a_{j-1}[k] g[2n - k]$$
To eliminate uncorrelated Gaussian noise while preserving sharp epileptiform spikes, soft thresholding is applied to detail coefficients $d_j[n]$ using the Universal Threshold rule:
$$\lambda = m \cdot \hat{\sigma} \sqrt{2 \ln N}$$
where $m$ is the user-defined multiplier, $N$ is the sample size, and $\hat{\sigma}$ is estimated via the Median Absolute Deviation (MAD) of the finest scale detail coefficients $d_1[n]$:
$$\hat{\sigma} = \frac{\text{median}(|d_1[n]|)}{0.6745}$$
Detail coefficients are modified via soft shrinkage $\eta_{\text{soft}}(d, \lambda) = \text{sgn}(d) \max(0, |d| - \lambda)$, and the cleaned time-domain signal is reconstructed using synthesis filters through the Inverse Discrete Wavelet Transform (IDWT).
3. Spectral Power & Polyphonic Musical Note Mapping
Frequency analysis uses Welch's periodogram method with a Hanning window $w[n]$ and Radix-2 Cooley-Tukey FFT. The normalized power spectral density within each band determines pitch assignment across equal temperament chromatic scales:
$$f_{\text{note}} = 440 \cdot 2^{\frac{n_{\text{midi}} - 69}{12}}$$
- Delta Power ($0.5\text{--}4\text{ Hz}$): Mapped to Bass register ($C_2\text{--}C_3$).
- Theta Power ($4\text{--}8\text{ Hz}$): Mapped to Tenor register ($D_3\text{--}D_4$).
- Alpha Power ($8\text{--}13\text{ Hz}$): Mapped to Alto register ($E_4\text{--}E_5$).
- Beta Power ($13\text{--}30\text{ Hz}$): Mapped to Soprano register ($F_5\text{--}F_6$).
Future Directions
To support advanced clinical diagnostic needs, future iterations of this platform will aim to integrate deep learning models directly within the client-side pipeline. By utilizing WebAssembly or TensorFlow.js, we plan to implement real-time automated seizure prediction and localization. These neural networks would scan multi-channel iEEG data to identify pre-ictal phase shifts before clinical symptoms appear. Additionally, we plan to implement Independent Component Analysis (ICA) for automated ocular and myogenic artifact rejection, alongside a multi-wavelet packet transform tool for higher resolution at high frequencies.
Related Diagnostics Platforms
Explore BioniChaos's suite of interactive neurological and electrophysiological visualization applications: