{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Outliers and artefacts detection\n\nThis example shows how to detect ectopic, missed, extra, slow and long long\nfrom RR or pulse rate interval time series using the method proposed by\nLipponen & Tarvainen (2019) [#]_.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: Nicolas Legrand \n# Licence: Apache-2.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from systole.detection import rr_artefacts\nfrom systole.plots import plot_subspaces\nfrom systole.utils import simulate_rr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## RR artefacts\nThe proposed method will detect 4 kinds of artefacts in an RR time series:\nMissed R peaks, when an existing R component was erroneously NOT detected by\nthe algorithm.\n* Extra R peaks, when an R peak was detected but does not exist in the\nsignal.\n* Long or short interval intervals, when R peaks are correctly detected but\nthe resulting interval has extreme value in the overall time-series.\n* Ectopic beats, due to disturbance of the cardiac rhythm when the heart\neither skip or add an extra beat.\n* The category in which the artefact belongs will have an influence on the\ncorrection procedure (see Artefact correction).\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulate RR time series\nThis function will simulate RR time series containing ectopic, extra, missed,\nlong and short artefacts.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "rr = simulate_rr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Artefact detection\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "outliers = rr_artefacts(rr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Subspaces visualization\nYou can visualize the two main subspaces and spot outliers. The left pamel\nplot subspaces that are more sensitive to ectopic beats detection. The right\npanel plot subspaces that will be more sensitive to long or short beats,\ncomprizing the extra and missed beats.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot_subspaces(rr, figsize=(12, 6))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## References\n.. [#] Lipponen, J. A., & Tarvainen, M. P. (2019). A robust algorithm for\n heart rate variability time series artefact correction using novel\n beat classification. Journal of Medical Engineering & Technology,\n 43(3), 173\u2013181. https://doi.org/10.1080/03091902.2019.1640306\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.16" } }, "nbformat": 4, "nbformat_minor": 0 }