API Reference: ecg_sdk.core.generator¶
ecg_sdk.core.generator
¶
Dynamic Synthetic ECG Generator Module¶
Implements dynamical multi-lead synthetic ECG generation based on Gaussian wave decomposition along an angular cardiac phase trajectory (McSharry et al. model), with authentic electrophysiological morphology across all 12 standard clinical leads (I, II, III, aVR, aVL, aVF, V1-V6) and ambulatory leads (MLII).
Academic Literature Sources & Parameter Citations:¶
- Seminal Dynamical Attractor Model (Lead II / Single Lead Formulation):
-
McSharry, P. E., Clifford, G. D., Tarassenko, L., & Smith, L. A. (2003). "A dynamical model for generating synthetic electrocardiogram signals." IEEE Transactions on Biomedical Engineering, 50(3), 289-294. DOI: 10.1109/TBME.2003.808805 [BibTeX: @McSharry2003-dynamical]
-
Multichannel ECG Modeling & 3D Vectorcardiographic Projection:
- Sameni, R., Clifford, G. D., Jutten, C., & Shamsollahi, M. B. (2007). "Multichannel ECG and noise modeling: Application to maternal and fetal ECG signals." EURASIP Journal on Advances in Signal Processing, 2007, 1-14. DOI: 10.1155/2007/43507 [BibTeX: @Sameni2007-multichannel]
- Clifford, G. D., Shoeb, A., McSharry, P. E., & Jané, R. (2005). "Model-based filtering, compression and classification of the ECG." Computers in Cardiology (CinC), 32, 159-162. DOI: 10.1109/CIC.2005.1588061 [BibTeX: @Clifford2005-CinC]
-
Sayadi, O., & Shamsollahi, M. B. (2008). "ECG synthetic generation using a modified dynamical model." Computers in Biology and Medicine, 38(3), 329-337. DOI: 10.1016/j.compbiomed.2007.12.003 [BibTeX: @Sayadi2008-modified]
-
Clinical 12-Lead Morphological Standards (Frontal & Precordial Norms):
- Goldberger, A. L., Goldberger, Z. D., & Shvilkin, A. (2017). Goldberger's Clinical Electrocardiography: A Simplified Approach (9th Edition). Elsevier Health Sciences. ISBN: 978-0323401692. [BibTeX: @Goldberger2017-clinical]
CANONICAL_LEAD_PARAMS = {'I': [{'name': 'P', 'theta': -1.2, 'a': 0.15, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.1, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.1, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.2, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.3, 'b': 0.4}], 'II': [{'name': 'P', 'theta': -1.2, 'a': 0.22, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.15, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.65, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.3, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.42, 'b': 0.4}], 'III': [{'name': 'P', 'theta': -1.2, 'a': 0.08, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.12, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 0.85, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.25, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.18, 'b': 0.4}], 'aVR': [{'name': 'P', 'theta': -1.2, 'a': -0.18, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': 0.1, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 0.15, 'b': 0.1}, {'name': 'S', 'theta': 0.15, 'a': -1.35, 'b': 0.14}, {'name': 'T', 'theta': 1.1, 'a': -0.35, 'b': 0.4}], 'aVL': [{'name': 'P', 'theta': -1.2, 'a': 0.06, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.08, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 0.65, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.18, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.15, 'b': 0.4}], 'aVF': [{'name': 'P', 'theta': -1.2, 'a': 0.16, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.12, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.25, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.25, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.3, 'b': 0.4}], 'V1': [{'name': 'P', 'theta': -1.2, 'a': 0.08, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': 0.0, 'b': 0.1}, {'name': 'R', 'theta': -0.1, 'a': 0.25, 'b': 0.1}, {'name': 'S', 'theta': 0.15, 'a': -1.2, 'b': 0.14}, {'name': 'T', 'theta': 1.1, 'a': 0.2, 'b': 0.4}], 'V2': [{'name': 'P', 'theta': -1.2, 'a': 0.12, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': 0.0, 'b': 0.1}, {'name': 'R', 'theta': -0.08, 'a': 0.45, 'b': 0.1}, {'name': 'S', 'theta': 0.15, 'a': -1.65, 'b': 0.14}, {'name': 'T', 'theta': 1.1, 'a': 0.38, 'b': 0.4}], 'V3': [{'name': 'P', 'theta': -1.2, 'a': 0.15, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.08, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 0.95, 'b': 0.12}, {'name': 'S', 'theta': 0.25, 'a': -1.0, 'b': 0.13}, {'name': 'T', 'theta': 1.1, 'a': 0.45, 'b': 0.4}], 'V4': [{'name': 'P', 'theta': -1.2, 'a': 0.16, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.12, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.75, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.45, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.45, 'b': 0.4}], 'V5': [{'name': 'P', 'theta': -1.2, 'a': 0.16, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.15, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.85, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.2, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.4, 'b': 0.4}], 'V6': [{'name': 'P', 'theta': -1.2, 'a': 0.14, 'b': 0.25}, {'name': 'Q', 'theta': -0.35, 'a': -0.12, 'b': 0.1}, {'name': 'R', 'theta': 0.0, 'a': 1.45, 'b': 0.12}, {'name': 'S', 'theta': 0.3, 'a': -0.12, 'b': 0.12}, {'name': 'T', 'theta': 1.1, 'a': 0.32, 'b': 0.4}]}
module-attribute
¶
LEAD_ALIASES = {'LEAD_I': 'I', 'LEAD_1': 'I', 'LEAD1': 'I', 'LEAD_II': 'II', 'LEAD_2': 'II', 'LEAD2': 'II', 'MLII': 'II', 'LEAD_III': 'III', 'LEAD_3': 'III', 'LEAD3': 'III', 'AVR': 'aVR', 'LEAD_AVR': 'aVR', 'AVL': 'aVL', 'LEAD_AVL': 'aVL', 'AVF': 'aVF', 'LEAD_AVF': 'aVF', 'LEAD_V1': 'V1', 'LEAD_V2': 'V2', 'LEAD_V3': 'V3', 'LEAD_V4': 'V4', 'LEAD_V5': 'V5', 'LEAD_V6': 'V6'}
module-attribute
¶
generate_synthetic_ecg(duration=10.0, sampling_rate=250.0, fs=None, heart_rate=60.0, noise_level=0.03, powerline_hz=50.0, powerline_noise=None, powerline_freq=None, baseline_wander=True, lead_names=None, leads=None, anomaly=None, random_seed=42, seed=None, **kwargs)
¶
Generate realistic multi-lead synthetic ECG signals with authentic electrophysiological morphologies across all 12 standard clinical leads following the McSharry-Clifford-Sameni dynamical models and Goldberger clinical norms.
Mathematical Model:¶
The cardiac angular phase trajectory theta(t) rotates at the instantaneous heart rate: d(theta)/dt = 2*pi * f_HR(t) where f_HR(t) includes Respiratory Sinus Arrhythmia (RSA / HRV modulation at ~0.25 Hz).
The synthetic voltage v_l(t) for lead l is the superposition of Gaussian wavelets: v_l(t) = sum_{i in {P,Q,R,S,T}} a_{l,i} * exp( -0.5 * ( (theta(t) - theta_{l,i}) / b_{l,i} )^2 )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
float
|
Duration of recording in seconds. |
10.0
|
sampling_rate
|
float
|
Sampling frequency in Hz (\(f_s\)). Also accepts alias |
250.0
|
fs
|
Optional[float]
|
Optional alias for |
None
|
heart_rate
|
float
|
Baseline heart rate in beats per minute (bpm). |
60.0
|
noise_level
|
float
|
Amplitude of Gaussian EMG noise in mV. |
0.03
|
powerline_hz
|
Optional[float]
|
Frequency of powerline interference (50.0 or 60.0 Hz, or None). Also accepts alias |
50.0
|
powerline_noise
|
Optional[float]
|
Amplitude of powerline interference in mV (default 0.035 mV). |
None
|
powerline_freq
|
Optional[float]
|
Optional alias for |
None
|
baseline_wander
|
Union[bool, float]
|
If True or float amplitude, adds realistic respiration baseline drift (~0.15 Hz). |
True
|
lead_names
|
Optional[List[str]]
|
List of lead names (e.g. ['I', 'II', 'V1', 'V5'] or standard 12 leads). Also accepts alias |
None
|
leads
|
Optional[List[str]]
|
Optional alias for |
None
|
anomaly
|
Optional[str]
|
Optional anomaly type to inject ('normal', 'bradycardia', 'tachycardia', 'pvc', 'pause', 'noisy'). |
None
|
random_seed
|
Optional[int]
|
Seed for reproducibility. Also accepts alias |
42
|
seed
|
Optional[int]
|
Optional alias for |
None
|
Returns:
| Type | Description |
|---|---|
ECGSignal
|
ECGSignal instance containing the synthetic multi-lead recording. |
Source code in ecg_sdk/core/generator.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
get_lead_parameters(lead_name)
¶
Look up canonical electrophysiological Gaussian parameters for a given lead name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lead_name
|
str
|
String name of the lead (e.g. 'I', 'II', 'aVR', 'V1', 'MLII'). |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries with keys 'name', 'theta', 'a', 'b'. |