1. Scientific & Biophysical Overview
Bioelectrical signal monitoring provides a real-time window into complex cardiac and cortical dynamics.
This simulator implements physiological synthetic models for two primary bioelectric indicators: the
Electrocardiogram (ECG) representing cardiac electrical depolarization, and the Electroencephalogram (EEG)
tracking superficial neural postsynaptic synchronization.
In cardiac modeling, the standard waveform is mathematically constructed by modeling distinct dipolar wavefront propagation coordinates.
Each wave component—$P$, $Q$, $R$, $S$, and $T$—corresponds to a localized physiological event. We approximate this using a summation
of Gaussians across continuous time-series parameters mapping to cardiac pacemaking beats:
$$V_{ECG}(t) = \sum_{b \in \mathcal{B}} \sum_{i \in \{P, Q, R, S, T\}} a_i \exp\left(-\frac{(t - b - \theta_i)^2}{2 w_i^2}\right)$$
where $\mathcal{B}$ represents the chronologically computed set of cardiac pacemaking trigger events, $a_i$ maps to local action potential amplitudes, $\theta_i$ determines the chronological onset boundaries relative to the $R$-peak trigger, and $w_i$ regulates wave widths. Under this additive multi-beat superposition model, adjacent wave complexes can naturally overlap without artificial discontinuities.
For instance, in Hyperkalemia, extracellular potassium elevation leads to impaired myocardial conduction,
resulting in classic clinical presentation: flattened $P$-waves, intraventricular conduction delays (widened QRS complex), and pathologically peaked, narrow $T$-waves modeled via elevated $a_T$
and reduced $w_T$.
Cortical tracking via EEG registers rhythmic microvolt fluctuations arising from synchronized postsynaptic potentials across millions of vertically oriented pyramidal cells. The signal contains five distinct bands characterized by operational frequencies: Delta ($\delta$, $0.5 - 4\text{ Hz}$), Theta ($\theta$, $4 - 8\text{ Hz}$), Alpha ($\alpha$, $8 - 13\text{ Hz}$), Beta ($\beta$, $13 - 30\text{ Hz}$), and Gamma ($\gamma$, $30 - 100\text{ Hz}$).
Sleep staging analysis, governed by clinical polysomnography (PSG) guidelines, classifies brain states as follows:
- Wakefulness (Awake): High-frequency, desynchronized $\beta$ waves dominate during active alert states. Under
mental relaxation with eyes closed, the occipital networks achieve a highly coherent, synchronized resonance resulting in the
emergence of alpha rhythms ($8 - 13\text{ Hz}$), a phenomenon termed "Alpha Bloom."
- Stage N1 (Transition): Drifting somnolence yields a suppression of alpha rhythms, replaced by low-amplitude,
mixed-frequency theta waves.
- Stage N2 (Light Sleep): Characterized by distinct neurophysiological signatures critical for memory consolidation:
Sleep Spindles ($12 - 15\text{ Hz}$ rhythmic pacemaking bursts generated by thalamocortical networks) and
K-Complexes (high-amplitude, biphasic slow waves lasting $>0.5\text{ s}$).
- Stage N3 (Deep Slow-Wave Sleep): Synchronized high-amplitude, slow delta waves ($0.5 - 4\text{ Hz}$) dominate,
signifying deep, non-rapid eye movement (NREM) restorative sleep.
- REM (Paradoxical Sleep): High-frequency, low-voltage EEG similar to wakefulness, accompanied by rapid saccadic
excursions on Electrooculography (EOG) channels and somatic muscle paralysis (atonia) captured on Electromyography (EMG) baselines.
3. Technical Architecture & Client-Side Engine
The simulation runs client-side using native HTML5 Canvas rendering.
This approach maintains high framerates and immediate feedback loop responsiveness by avoiding network round-trips.
A challenge in browser-based medical signal simulation is generating authentic $1/f$ (pink) spectral noise. Unlike standard white
noise (uncorrelated random variables), pink noise features a power spectral density inversely proportional to frequency:
$$S(f) \propto \frac{1}{f^\alpha}, \quad \alpha \approx 1$$
This is implemented using a Voss-McCartney algorithm. By summing multiple cascading white noise generators updated at binary octaves,
we achieve a $-3\text{ dB}$ octave slope, providing realistic electrode background noise.
Audio synthesis uses the Web Audio API to map the ongoing bioelectric signals to acoustic tones. When active, a real-time oscillator
synthesizes pitch based on voltage gradients, mimicking clinical auditory monitoring systems. To safeguard performance, canvas redraws
utilize `requestAnimationFrame` while inputs are decoupled via non-blocking rendering.