iizukak / ecg-htm

ECG Anomaly Detection System using HTM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ECG + HTM

ECG Anomaly Detection System using HTM

Abstruct

In this projects, We build Electrocardiogram(ECG) anomaly detection system using HTM(NuPIC). This system will detect Palpitation, Arrhythmia and Heart Rate anomaly.

System Structure and Usage

There are about three parts of the projects.

  • Data Collector
  • FFT Converter
  • Anomaly Detector

Data Collector

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

device

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

2015-11-09 21 48 35

FFT Converter

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.

2015-11-07 18 54 14

Non uniform parts are corredpond to the anomalous of ECG data.

Anomaly Detection

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.

d2378b575a8f02188069ef80a08ae6fd 1

Data

This repository include some helathy and abnormal ECG data. These data are in data directory.

Nomral ECG data

  • data/healthy_person1.csv
  • data/healthy_person2.csv
  • data/healthy_person3.csv
  • data/healthy_person4.csv

Abnormal ECG data

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

About

ECG Anomaly Detection System using HTM

License:GNU Affero General Public License v3.0


Languages

Language:Python 95.8%Language:Arduino 3.6%Language:Gnuplot 0.6%