|
| 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