ECG Anomaly Detection System using HTM
In this projects, We build Electrocardiogram(ECG) anomaly detection system using HTM(NuPIC). This system will detect Palpitation, Arrhythmia and Heart Rate anomaly.
There are about three parts of the projects.
- Data Collector
- FFT Converter
- Anomaly Detector
It's not difficult to make your own ECG device.
If you are not interested in collecting data by yourself,
You can skip this part and use data in data
directory.
We use
Sparkfun's tutorial is very friendly. You can also use Sparkfun's Github Repository to get simple visualization of ECG Data. Visualization output is like this video.
Next, Collect ECG Data through the script.
$ python src/take_data.py > data/foobar.csv
Collected Data have this format.
2015-10-17 21:05:10.078937,483
2015-10-17 21:05:10.094542,481
2015-10-17 21:05:10.094833,480
2015-10-17 21:05:10.094949,485
2015-10-17 21:05:10.095044,492
2015-10-17 21:05:10.110693,501
If you want to visualize collected data, You can use Gnuplot.
$ gnuplot
set datafile separator ","
plot "< head -1000 data/foobar.csv" using 2 with line
Before detecting anomalous part of the ECG data,
We use a signal processing technique, FFT(Fast Fourier Transform).
FFT can be used to extract charactaristics of data sequence.
Numpy
library contain FFT, and we use that.
See example for using FFT Converter with ECG data collected by take_data.py
.
You can also use the preset data of the repository.
FFT converter can use like this.
$ python src/fft_converter.py --target healthy_person1
2015-10-17 21:05:12.685818,11.808565811567473,...,10.957521665215634
2015-10-17 21:05:12.701433,11.808734646395951,...,7.7589930598122354
...
2015-10-17 21:05:57.033917,11.821344935267192,...,8.5655396209023618
You can use --target
option to specify the target file's name.
Dont's forget to remove .csv
string from file name.
FFT Converted data are can be visualized using Gnuplot.
Non uniform parts are corredpond to the anomalous of ECG data.
We use anomaly detection using vector_anomaly.py
Script.
You shoud use FFT Converted data.
$ python src/vector_anomaly.py
This is the visualization of the output.
This repository include some helathy and abnormal ECG data.
These data are in data
directory.
data/healthy_person1.csv
data/healthy_person2.csv
data/healthy_person3.csv
data/healthy_person4.csv
data/disease_person1.csv
- This data contain big anomalous part.
data/disease_person2.csv
- This data contain small anomalous part.
data/disease_person3.csv
- This data is chronically abnormal in QRS wave.