├── .gitignore ├── LICENSE ├── README.md ├── data ├── ecg.csv ├── manual-correction-rr.txt └── rr.txt ├── notebooks └── blogpost-exploring-hrv.ipynb ├── output ├── ecg-with-corrected-rr-240000-250000.png ├── ecg-with-rr-240000-250000.png └── peaks-60000-70000.png └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Salomon Tetelepta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Exploring heart rate variability 3 | 4 | ECG signal and RR-values 6 | 7 | This repository contains the complete source code for the experiment described in my blogpost ["Exploring Heart Rate Variability using Python"](https://medium.com/@stetelepta/exploring-heart-rate-variability-using-python-483a7037c64d) 8 | 9 | ### Installation 10 | 11 | * Install the requirements using `pip install -r requirements.txt` (and use Python 3) 12 | 13 | -------------------------------------------------------------------------------- /data/manual-correction-rr.txt: -------------------------------------------------------------------------------- 1 | 932 2 | 965 3 | 893 4 | 834 5 | 825 6 | 828 7 | 871 8 | 916 9 | 810 10 | 809 11 | 795 12 | 889 13 | 941 14 | 894 15 | 848 16 | 827 17 | 869 18 | 914 19 | 868 20 | 822 21 | 885 22 | 897 23 | 874 24 | 916 25 | 910 26 | 969 27 | 867 28 | 820 29 | 766 30 | 775 31 | 932 32 | 868 33 | 793 34 | 676 35 | 700 36 | 695 37 | 862 38 | 945 39 | 921 40 | 929 41 | 818 42 | 807 43 | 772 44 | 797 45 | 921 46 | 894 47 | 849 48 | 822 49 | 773 50 | 829 51 | 862 52 | 904 53 | 892 54 | 816 55 | 821 56 | 851 57 | 907 58 | 919 59 | 864 60 | 856 61 | 785 62 | 881 63 | 912 64 | 878 65 | 845 66 | 771 67 | 826 68 | 823 69 | 873 70 | 926 71 | 844 72 | 807 73 | 865 74 | 877 75 | 923 76 | 838 77 | 816 78 | 858 79 | 901 80 | 938 81 | 847 82 | 804 83 | 873 84 | 887 85 | 940 86 | 880 87 | 781 88 | 837 89 | 850 90 | 913 91 | 901 92 | 826 93 | 842 94 | 848 95 | 938 96 | 920 97 | 862 98 | 837 99 | 816 100 | 858 101 | 902 102 | 849 103 | 828 104 | 801 105 | 882 106 | 905 107 | 860 108 | 828 109 | 785 110 | 852 111 | 813 112 | 744 113 | 741 114 | 692 115 | 734 116 | 910 117 | 925 118 | 874 119 | 826 120 | 838 121 | 861 122 | 903 123 | 852 124 | 770 125 | 790 126 | 794 127 | 883 128 | 863 129 | 864 130 | 772 131 | 783 132 | 874 133 | 864 134 | 933 135 | 884 136 | 850 137 | 860 138 | 902 139 | 938 140 | 988 141 | 956 142 | 914 143 | 884 144 | 830 145 | 934 146 | 967 147 | 975 148 | 991 149 | 909 150 | 854 151 | 924 152 | 957 153 | 977 154 | 1006 155 | 904 156 | 856 157 | 882 158 | 956 159 | 1004 160 | 1028 161 | 942 162 | 888 163 | 905 164 | 923 165 | 966 166 | 978 167 | 929 168 | 833 169 | 846 170 | 798 171 | 696 172 | 760 173 | 960 174 | 908 175 | 812 176 | 826 177 | 824 178 | 797 179 | 764 180 | 773 181 | 928 182 | 924 183 | 926 184 | 878 185 | 829 186 | 797 187 | 801 188 | 888 189 | 917 190 | 908 191 | 894 192 | 797 193 | 796 194 | 715 195 | 853 196 | 902 197 | 914 198 | 957 199 | 834 200 | 842 201 | 876 202 | 893 203 | 965 204 | 936 205 | 894 206 | 890 207 | 835 208 | 880 209 | 930 210 | 880 211 | 869 212 | 792 213 | 804 214 | 906 215 | 853 216 | 849 217 | 725 218 | 751 219 | 688 220 | 875 221 | 935 222 | 890 223 | 878 224 | 798 225 | 766 226 | 877 227 | 847 228 | 908 229 | 834 230 | 794 231 | 842 232 | 865 233 | 940 234 | 871 235 | 830 236 | 860 237 | 844 238 | 918 239 | 886 240 | 855 241 | 853 242 | 758 243 | 752 244 | 714 245 | 934 246 | 874 247 | 862 248 | 844 249 | 802 250 | 871 251 | 877 252 | 902 253 | 932 254 | 838 255 | 822 256 | 869 257 | 889 258 | 947 259 | 863 260 | 782 261 | 792 262 | 750 263 | 952 264 | 891 265 | 895 266 | 926 267 | 862 268 | 884 269 | 868 270 | 888 271 | 944 272 | 860 273 | 817 274 | 839 275 | 862 276 | 944 277 | 930 278 | 926 279 | 912 280 | 842 281 | 854 282 | 915 283 | 950 284 | 955 285 | 964 286 | 874 287 | 880 288 | 854 289 | 894 290 | 979 291 | 951 292 | 926 293 | 927 294 | 879 295 | 908 296 | 990 297 | 962 298 | 944 299 | 948 300 | 786 301 | 968 302 | 951 303 | 931 304 | 936 305 | 821 306 | 819 307 | 945 308 | 899 309 | 870 310 | 820 311 | 824 312 | 868 313 | 851 314 | 901 315 | 980 316 | 940 317 | 946 318 | 816 319 | 855 320 | 924 321 | 879 322 | 898 323 | 890 324 | 801 325 | 863 326 | 854 327 | 882 328 | 904 329 | 804 330 | 805 331 | 750 332 | 787 333 | 825 334 | 850 335 | 925 336 | 862 337 | 858 338 | 812 339 | 856 340 | 890 341 | 874 342 | 891 343 | 883 344 | 774 345 | 831 346 | 840 -------------------------------------------------------------------------------- /data/rr.txt: -------------------------------------------------------------------------------- 1 | 932 2 | 965 3 | 893 4 | 834 5 | 825 6 | 828 7 | 871 8 | 916 9 | 810 10 | 809 11 | 795 12 | 889 13 | 941 14 | 894 15 | 848 16 | 827 17 | 869 18 | 914 19 | 868 20 | 822 21 | 885 22 | 897 23 | 868 24 | 868 25 | 853 26 | 868 27 | 910 28 | 969 29 | 867 30 | 820 31 | 766 32 | 775 33 | 932 34 | 868 35 | 793 36 | 676 37 | 700 38 | 695 39 | 862 40 | 945 41 | 921 42 | 929 43 | 818 44 | 807 45 | 772 46 | 797 47 | 921 48 | 894 49 | 849 50 | 822 51 | 773 52 | 829 53 | 862 54 | 904 55 | 892 56 | 816 57 | 821 58 | 851 59 | 907 60 | 919 61 | 864 62 | 856 63 | 785 64 | 881 65 | 912 66 | 878 67 | 845 68 | 771 69 | 826 70 | 823 71 | 873 72 | 926 73 | 844 74 | 807 75 | 865 76 | 877 77 | 923 78 | 838 79 | 816 80 | 858 81 | 901 82 | 938 83 | 847 84 | 804 85 | 873 86 | 887 87 | 940 88 | 880 89 | 781 90 | 837 91 | 850 92 | 913 93 | 901 94 | 826 95 | 842 96 | 848 97 | 938 98 | 920 99 | 862 100 | 837 101 | 816 102 | 858 103 | 902 104 | 849 105 | 828 106 | 801 107 | 882 108 | 905 109 | 860 110 | 828 111 | 785 112 | 852 113 | 813 114 | 744 115 | 741 116 | 692 117 | 734 118 | 910 119 | 925 120 | 874 121 | 826 122 | 838 123 | 861 124 | 903 125 | 852 126 | 770 127 | 790 128 | 794 129 | 883 130 | 863 131 | 864 132 | 772 133 | 783 134 | 874 135 | 864 136 | 933 137 | 884 138 | 850 139 | 860 140 | 902 141 | 938 142 | 988 143 | 956 144 | 914 145 | 884 146 | 830 147 | 934 148 | 967 149 | 975 150 | 991 151 | 909 152 | 854 153 | 924 154 | 957 155 | 977 156 | 1006 157 | 904 158 | 856 159 | 882 160 | 956 161 | 1004 162 | 1028 163 | 942 164 | 888 165 | 905 166 | 923 167 | 966 168 | 978 169 | 929 170 | 833 171 | 846 172 | 798 173 | 696 174 | 760 175 | 960 176 | 908 177 | 812 178 | 826 179 | 824 180 | 797 181 | 764 182 | 773 183 | 928 184 | 924 185 | 926 186 | 878 187 | 829 188 | 797 189 | 801 190 | 888 191 | 917 192 | 908 193 | 894 194 | 797 195 | 796 196 | 715 197 | 853 198 | 902 199 | 914 200 | 957 201 | 834 202 | 842 203 | 876 204 | 893 205 | 965 206 | 868 207 | 901 208 | 894 209 | 890 210 | 835 211 | 880 212 | 930 213 | 880 214 | 869 215 | 792 216 | 804 217 | 906 218 | 853 219 | 849 220 | 725 221 | 751 222 | 688 223 | 875 224 | 935 225 | 890 226 | 878 227 | 798 228 | 766 229 | 877 230 | 847 231 | 908 232 | 834 233 | 794 234 | 842 235 | 865 236 | 940 237 | 871 238 | 830 239 | 860 240 | 844 241 | 918 242 | 886 243 | 855 244 | 853 245 | 758 246 | 752 247 | 714 248 | 934 249 | 874 250 | 862 251 | 844 252 | 802 253 | 871 254 | 877 255 | 902 256 | 932 257 | 838 258 | 868 259 | 889 260 | 947 261 | 863 262 | 782 263 | 792 264 | 750 265 | 952 266 | 891 267 | 895 268 | 926 269 | 862 270 | 884 271 | 868 272 | 888 273 | 944 274 | 860 275 | 817 276 | 839 277 | 862 278 | 944 279 | 930 280 | 926 281 | 912 282 | 842 283 | 868 284 | 950 285 | 955 286 | 964 287 | 874 288 | 880 289 | 854 290 | 894 291 | 979 292 | 951 293 | 926 294 | 927 295 | 879 296 | 908 297 | 990 298 | 962 299 | 944 300 | 948 301 | 786 302 | 968 303 | 951 304 | 931 305 | 936 306 | 821 307 | 819 308 | 945 309 | 899 310 | 870 311 | 820 312 | 824 313 | 868 314 | 851 315 | 901 316 | 980 317 | 940 318 | 946 319 | 816 320 | 855 321 | 924 322 | 879 323 | 898 324 | 890 325 | 801 326 | 863 327 | 854 328 | 882 329 | 904 330 | 804 331 | 805 332 | 750 333 | 787 334 | 825 335 | 850 336 | 925 337 | 862 338 | 858 339 | 812 340 | 856 341 | 890 342 | 874 343 | 891 344 | 883 345 | 774 346 | 831 347 | 840 348 | -------------------------------------------------------------------------------- /output/ecg-with-corrected-rr-240000-250000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stetelepta/exploring-heart-rate-variability/fce1b41f591e4a18dd854452605b3a942baf0944/output/ecg-with-corrected-rr-240000-250000.png -------------------------------------------------------------------------------- /output/ecg-with-rr-240000-250000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stetelepta/exploring-heart-rate-variability/fce1b41f591e4a18dd854452605b3a942baf0944/output/ecg-with-rr-240000-250000.png -------------------------------------------------------------------------------- /output/peaks-60000-70000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stetelepta/exploring-heart-rate-variability/fce1b41f591e4a18dd854452605b3a942baf0944/output/peaks-60000-70000.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | hrv==0.1.5 2 | matplotlib==2.2.3 3 | numpy==1.14.5 4 | pandas==0.23.4 5 | scipy==1.1.0 6 | seaborn==0.9.0 7 | wfdb==2.0.3 8 | ipython==6.5.0 9 | jupyter==1.0.0 10 | --------------------------------------------------------------------------------