In [1]:
import wfdb
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.insert(0, '/home/scidb/HeartRatePatterns/Python')
#QRSDetectorOffline.py
from QRSDetectorOffline import QRSDetectorOffline
Downloading an ECG from mimic III
In [2]:
folder = "p05/p050140"
waveform = "p050140-2188-07-26-05-51"
sig, fields = wfdb.srdsamp(waveform,pbdir='mimic3wdb/matched/'+folder, sampto=10000)
In [3]:
print("signame: " + str(fields['signame']))
print("units: " + str(fields['units']))
print("fs: " + str(fields['fs']))
print("comments: " + str(fields['comments']))
print("fields: " + str(fields))
Lets check if the signal contains the signal II
In [4]:
signalII = None
try:
signalII = fields['signame'].index("II")
except ValueError:
print("List does not contain value")
if(signalII!=None):
print("List contain value")
Obtain only the signal II from the ECG
In [5]:
array = sig[:, signalII]
array = np.nan_to_num(array)
Save the Frame Secuence
In [6]:
fs = fields['fs']
fs
Out[6]:
Create Numpy Array
In [7]:
npArray = np.array(array)
npArray
Out[7]:
check sig:
In [8]:
plt.plot(npArray)
plt.show()
In [9]:
sha = np.arange(npArray.shape[0])
In [10]:
test = np.stack((sha, np.nan_to_num(npArray))).T
In [11]:
ecg_data_path = 'ecg_data/'+waveform+'.csv'
np.savetxt(ecg_data_path, test, delimiter=',')
qrs_detector = QRSDetectorOffline(ecg_data_path=ecg_data_path, verbose=True,log_data=True, plot_data=True,
show_plot=True,signal_frequency=fs)
In [12]:
first = qrs_detector.qrs_peaks_indices[0]
someLater = qrs_detector.qrs_peaks_indices[20]
Small array
In [13]:
small = npArray[first:someLater]
sha = np.arange(small.shape[0])
In [14]:
plt.plot(small)
plt.show()
In [15]:
test = np.stack((sha, np.nan_to_num(small))).T
test
Out[15]:
In [16]:
ecg_data_path = 'ecg_data/small.csv'
np.savetxt(ecg_data_path, test, delimiter=',')
qrs_detector = QRSDetectorOffline(ecg_data_path=ecg_data_path, verbose=True,log_data=True, plot_data=True,
show_plot=True,signal_frequency=fs)
In [17]:
first = qrs_detector.qrs_peaks_indices[4]
someLater = qrs_detector.qrs_peaks_indices[9]
small = qrs_detector.ecg_data_detected[first:someLater,1]
plt.plot(small)
plt.tight_layout()
plt.show()