Overview
The Electrocardiogram (ECG) represents a temporal mapping of the electrical vectors generated by cardiac muscle depolarization and repolarization. Under standard physiological conditions, these electrical signals are initiated at the sinoatrial (SA) node, propagate through the atrial syncytium, pass through the slow-conducting atrioventricular (AV) node, and subsequently travel via the Bundle of His and Purkinje network to excite the ventricular myocardium.
The structural landmarks detected in a standard lead configuration are mathematically defined as the $P, Q, R, S, T$ complex:
- P Wave: Corresponds to atrial depolarization. It is a slow, low-amplitude positive deflection.
- QRS Complex: Represents rapid ventricular depolarization. Because ventricular mass is large and conduction is rapid, the QRS complex is sharp and has higher amplitude. The negative $Q$ wave indicates septal activation, the tall $R$ wave indicates apical depolarization, and the negative $S$ wave represents the depolarization of the basal regions.
- T Wave: Corresponds to ventricular repolarization, which is slower than depolarization and produces a broader positive waveform.
Isolating these features is essential for clinical diagnostics. Pathological variations such as prolonged intervals, elevated segments, or morphological anomalies can indicate conditions like arrhythmias, myocardial ischemia, or channelopathies.
How to Use
This diagnostic console simulates a Lead-I ECG sweep and allows you to test physiological feature-extraction algorithms in real-time. Follow this structural process to navigate and analyze the signals:
1. Baseline Signal Controls
Use the right-hand parameter sliders to adjust the simulated cardiac signal. Sweep Duration determines the total captured timeframe (from 4 to 20 seconds). Heart Rate adjusts the ventricular cycle speed (from 50 to 110 bpm). Observe how the intervals between peaks contract or expand as you alter this rate.
2. Extraction Window Calibration
The Segment Range slider defines the analysis buffer ($2 \times \text{SEGMENT\_RANGE}$) centered around the detected $R$-peaks. Adjusting this search window determines the temporal constraints within which the sub-peaks ($P, Q, S, T$) are extracted. If the segment range is set too narrow, the slower $P$ or $T$ waves may lie outside the analysis window and fail to register.
3. Diagnostic Manipulation and Filtering
Open the Pathological Interferences panel to inject real-world noise. Increase the Myoelectric Noise to simulate patient muscle contractions (EMG artifacts), and raise Baseline Wander to mimic respiratory movement. Note how high noise rates introduce false local peaks, causing feature markers to jump. Toggle the DSP Filter button to apply a 5-point moving average filter that smooths the raw signal and helps stabilize extraction.
4. Interactive Diagnostics
Click the Sound Button to enable acoustic monitoring. Hover your cursor over the main telemetry window to inspect coordinates. Tap or click any beat on the sweep to highlight that cardiac complex. The lower-left diagnostic visualizer zooms in on the active cycle, providing precise interval calculations ($QRS$, $QT$, and Bazett's corrected $QTc$).
Technical Details
The system synthesizes a physiological ECG signal $V(t)$ using a superposition of five Gaussian waveforms (corresponding to $P, Q, R, S, T$) combined with low-frequency respiratory drift and high-frequency noise. For each cardiac cycle $k$ centered around an apical R-peak $\tau_k$, the voltage contribution is modeled as:
$$V(t) = B(t) + N(t) + \sum_{k} \sum_{i \in \{P, Q, R, S, T\}} a_i \exp\left( -\frac{(t - \tau_k - t_i)^2}{2 w_i^2} \right)$$
Where $B(t)$ represents the baseline wander modeled as a sinusoidal respiration wave, $N(t)$ represents white Gaussian noise, and $a_i$, $t_i$, and $w_i$ represent the physiological amplitudes, time locations, and widths of the specific cardiac waves respectively.
To capture rate-dependent physiological adaptations, the temporal locations and widths scale dynamically according to Bazett's adaptation factor, calculated from the relative R-R interval duration:
$$s = \sqrt{\frac{RR}{RR_{\text{ref}}}}$$
This scaling alters the cardiac timings ($t_P, t_T$) and wave widths ($w_P, w_T$), simulating the physiological shortening of ventricular repolarization at higher heart rates.
Local Segment Detrending
To insulate the extraction algorithm from baseline wander, the extracted segment $x[n]$ of length $L$ is detrended prior to peak detection. A linear trend line $L[n]$ connecting the boundary points $x[0]$ and $x[L-1]$ is calculated:
$$L[n] = x[0] + \left( \frac{x[L-1] - x[0]}{L-1} \right) \cdot n$$
The detrended, drift-free segment $x_d[n]$ is then isolated:
$$x_d[n] = x[n] - L[n]$$
This step flattens respiratory baseline oscillations, ensuring that absolute thresholds are not distorted by baseline shifts.
Physiologically-Bounded Search Windows
Instead of scanning the entire unconstrained segment for peaks—which risks picking up adjacent heartbeats under tachycardia—the algorithm isolates peaks using dynamic temporal boundaries relative to the central $R$-peak index (located at $n_R = \text{SEGMENT\_RANGE}$):
-
Q Wave search window: Constrained to $n \in [n_R - \text{round}(35 \cdot s / 4), n_R - 2]$. Within this window, the $Q$-wave is identified as the local minimum of the detrended signal:
$$Q_{\text{index}} = \arg\min_n x_d[n]$$
-
S Wave search window: Constrained to $n \in [n_R + 2, n_R + \text{round}(40 \cdot s / 4)]$. Within this window, the $S$-wave is identified as the local minimum:
$$S_{\text{index}} = \arg\min_n x_d[n]$$
-
P Wave search window: Constrained to $n \in [n_R - \text{round}(240 \cdot s / 4), Q_{\text{index}} - 2]$. Within this window, the $P$-wave is identified as the local maximum:
$$P_{\text{index}} = \arg\max_n x_d[n]$$
-
T Wave search window: Constrained to $n \in [S_{\text{index}} + \text{round}(20 \cdot s / 4), n_R + \text{round}(380 \cdot s / 4)]$. Within this window, the $T$-wave is identified as the local maximum:
$$T_{\text{index}} = \arg\max_n x_d[n]$$
Future Directions
The system's diagnostic capabilities can be expanded in several key areas:
- PhysioNet Integration: Integrating the ability to stream annotated clinical records from databases like the MIT-BIH Arrhythmia Database to test feature extraction algorithms on real-world, clinical ECG recordings.
- Multi-Lead Support: Simulating standard 12-lead configurations to reconstruct three-dimensional electrical cardiac vectors and diagnose localized issues, such as lateral or inferior wall infarctions.
- Arrhythmia Synthesis: Implementing pathological state models, such as Atrial Fibrillation (causing missing P-waves and irregular R-R intervals), Premature Ventricular Contractions (PVCs), and Bundle Branch Blocks.
- Advanced QRS Classifiers: Implementing continuous wavelet transform (CWT) filters and derivative-threshold classifiers, such as the Pan-Tompkins algorithm, to improve QRS detection accuracy under high noise levels.
Related Labs and Diagnostic Environments
-
Cardiac Pacemaker Simulator - Explore artificial cardiac pacing, wave synchronization, and conduction block diagnostics.
-
CardioQuest Simulator - Analyze complete hemodynamics, arterial pressures, and systemic cardiovascular loop parameters.
-
Neurofeedback System - Explore dynamic electroencephalogram (EEG) spectral bands and neuroregulation loops.
-
Acoustic Spectrogram - Learn real-time Fast Fourier Transform (FFT) analysis of complex sound frequencies.