Sleep Cycle Simulation
An interactive educational simulator representing human sleep stage neurodynamics, electroencephalographic (EEG) spectral configurations, and sleep pathomechanic models.
Stage: Awake
I. Clinical Overview & Neurophysics of Sleep Architecture
The assessment of human sleep processes utilizes polysomnography (PSG) to track and define neurobiological architecture throughout the rest cycle. A core element of this tracking is the electroencephalogram (EEG), which registers electrical field potentials generated by synchronized postsynaptic potentials in cortical pyramidal neurons. Brain activity during different sleep stages shows variations in voltage amplitudes and signal frequency bands. These signals range from rapid, desynchronized beta and alpha wave dynamics to slow-wave slow rhythmic delta patterns.
Sleep is categorized into Rapid Eye Movement (REM) and Non-Rapid Eye Movement (NREM) states, with NREM subdivided into Light Sleep (Stages N1 and N2) and Slow-Wave/Deep Sleep (Stage N3). Standard wakefulness exhibits dominant Alpha activity (8-12 Hz) during relaxed eyes-closed states, transitioning to Beta oscillations (12-30 Hz) during sensory-cognitive processing.
As NREM sleep progresses, high-frequency signals transition to slower rhythms. Stage N2 (Light Sleep) is characterized by sleep spindles—brief, 11-16 Hz bursts generated by the thalamic reticular nucleus—and K-complexes, high-amplitude biphasic waves [1]. Stage N3 (Deep Sleep) is dominated by Slow-Wave Activity (SWA) or Delta waves (0.5-4 Hz) with amplitudes exceeding 75 microvolts, demonstrating synchronized cortical networks. REM sleep is marked by desynchronized, low-amplitude, mixed-frequency waveforms similar to active wakefulness, often accompanied by distinct "sawtooth" waves.
II. Operational Guide & Interactive Workspace Parameters
This application allows real-time interactive adjustments of a simulated mathematical EEG signal and spectral visualization. The interface provides several control components:
- Start / Pause / Reset controls: These elements allow users to control the temporal timeline of the simulation. Clicking "Reset" instantly restores the parameters to default configurations.
- Direct Stage Selection Buttons: These custom pill selectors allow users to bypass automatic cyclic transitions and force-jump the simulation directly into Awake, Light Sleep, Deep Sleep, or REM Sleep state on demand.
- Skip Stage command: This option allows manual transitioning sequentially through the stages—Awake, REM Sleep, Light Sleep, and Deep Sleep—skipping standard time limits.
- Cycle Transition Speed modifier: This adjust the scale of stage durations, speeding up the overall sleep cycle.
- Waveform Amplitude Scaler: This slider scales signal voltage, allowing users to examine the mathematical differences between low-voltage REM waves and high-voltage deep-sleep delta formations.
- EEG Artifact Noise level: This slider controls random ambient voltage variations, simulating muscular artifacts, electrode drift, or environmental RF noise.
- Audio Synthesizer toggle: This control activates synthesized binaural sound. Left and right channels output frequencies shifted by the dominant EEG frequency of the current sleep stage. This translates active microvolt fluctuations into a corresponding acoustic binaural beat.
III. Technical Architecture & Mathematical Modeling
To maintain clean rendering speeds without bogging down user inputs (INP < 200ms), the EEG wave and spectrogram are synthesized procedurally in standard JavaScript frame loops via requestAnimationFrame(). The mathematical model synthesizes multiple sub-frequency parameters based on clinical EEG bands:
The wave function generates raw voltage \(V(t)\) by summing discrete sine components with amplitude \(a_i\) and frequency \(f_i\) mapped for each sleep stage: \[V(t) = \sum_{i=1}^{n} a_i \sin(2 \pi f_i t) + \epsilon(t)\] where \(\epsilon(t)\) represents a Gaussian pseudo-random artifact component governed by the Noise Level slider.
For visual scrolling, the canvas elements use dynamic buffer-shifting via getImageData and putImageData, shifting existing pixels horizontally by a computed pixel-per-millisecond rate, then appending the latest synthesized column. The Spectrogram canvas calculates the relative energy of each band using discrete phase-shifted values, rendering spectral density via a custom linear gradient. Blue shades correspond to lower values, and deep red regions represent maximum intensity.
Binaural acoustic synthesis uses the Web Audio API, creating two distinct oscillator channels routed to a StereoMergerNode. The left ear generates a base carrier frequency of 100 Hz, while the right ear tracks at \(100 + f_{dominant}\) Hz. Listening with stereo headphones produces a subjective beat sensation representing current brain wave frequencies.
IV. Future Roadmap & Digital Neurotechnology Integration
Future updates for this simulation aim to implement true client-side Fast Fourier Transforms (FFT) on imported raw EEG data, using the European Data Format (.EDF) standard. This addition will allow users to upload sleep-study recordings and compare simulated waves with actual physiological data.
Another planned feature is a 3D cortical electrode projection, mapping local field potentials across 10-20 system scalp configurations to display the spatial distribution of delta waves and sleep spindles. Finally, adding clinical pathology presets would allow users to simulate disorders like obstructive sleep apnea (OSA), sleep fragmentation, or parasomnias, providing an interactive educational tool for sleep science and clinical neurophysiology.