Skip to content

Commit e5dd45d

Browse files
author
Nicolas Marc Simon Legrand
committed
examples
1 parent b9981ee commit e5dd45d

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

examples/plot_HeartBeatEvokedArpeggios.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import time
1919
from systole import serialSim
2020
from psychopy.sound import Sound
21-
from systole.circular import to_angles, circular
21+
from systole.utils import to_angles
22+
from systole.plotting import circular
2223
from systole.recording import Oximeter
2324
import matplotlib.pyplot as plt
2425
import numpy as np
@@ -85,14 +86,16 @@
8586

8687
# T + 2/4
8788
if systoleTime2 is not None:
88-
if time.time() - systoleTime2 >= (((oxi.instant_rr[-1]/4) * 2)/1000):
89+
if time.time() - systoleTime2 >= (
90+
((oxi.instant_rr[-1]/4) * 2)/1000):
8991
diastole2 = Sound('G', secs=0.1)
9092
diastole2.play()
9193
systoleTime2 = None
9294

9395
# T + 3/4
9496
if systoleTime3 is not None:
95-
if time.time() - systoleTime3 >= (((oxi.instant_rr[-1]/4) * 3)/1000):
97+
if time.time() - systoleTime3 >= (
98+
((oxi.instant_rr[-1]/4) * 3)/1000):
9699
diastole3 = Sound('A', secs=0.1)
97100
diastole3.play()
98101
systoleTime3 = None
@@ -112,7 +115,6 @@
112115
oxi.plot_events(ax=ax2)
113116
plt.tight_layout()
114117

115-
116118
#%%
117119
# Cardiac cycle
118120
# -------------

examples/plot_RRSubspacesDetection.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Outliers and ectobeats detection
3+
================================
4+
5+
This example show how to detect ectobeat extra, missed and ectobeats from RR
6+
time series using the method proposed by Lipponen & Tarvainen (2019) [#]_.
7+
"""
8+
9+
# Author: Nicolas Legrand <nicolas.legrand@cfin.au.dk>
10+
# Licence: GPL v3
11+
12+
#%%
13+
from systole.detection import rr_outliers
14+
from systole.plotting import plot_subspaces, plot_hr
15+
from systole import import_rr
16+
17+
#%%
18+
# Simulate RR time serie
19+
# ----------------------
20+
21+
rr = import_rr().rr[:100]
22+
23+
#%%
24+
# Add artefacts
25+
# -------------
26+
27+
# Add missed beat
28+
rr[20] = 1600
29+
30+
# Add extra beat
31+
rr[40] = 400
32+
33+
# Add ectobeat (type 1)
34+
rr[60] = 1100
35+
rr[61] = 500
36+
37+
# Add ectobeat (type 2)
38+
rr[80] = 500
39+
rr[81] = 1100
40+
41+
#%%
42+
# Artefact detection
43+
# ------------------
44+
# You can visualize the two main subspaces and spot outliers.
45+
# Here we can see that two intervals have been labelled as probable ectobeats
46+
# (left pannel), and a total of 6 datapoints are considered as outliers, being
47+
# too long or too short (right pannel).
48+
49+
plot_subspaces(rr)
50+
51+
#%%
52+
# Plotting
53+
# --------
54+
# We can then plot back the labelled outliers in the RR interval time course
55+
56+
ectobeats, outliers = rr_outliers(rr)
57+
plot_hr(rr.values, kind='linear', outliers=(ectobeats | outliers))
58+
59+
#%%
60+
# References
61+
# ----------
62+
# .. [#] Lipponen, J. A., & Tarvainen, M. P. (2019). A robust algorithm for
63+
# heart rate variability time series artefact correction using novel
64+
# beat classification. Journal of Medical Engineering & Technology,
65+
# 43(3), 173–181. https://doi.org/10.1080/03091902.2019.1640306

0 commit comments

Comments
 (0)