def main(): # Read the ISHNE file global ecg ecg = ishne.ISHNE(sys.argv[1]) ecg.read() # number of samples: 0.06 - 0.1 * SAMPLING_RATE (QRS Time: 60-100ms) num_samples = int(0.08 * ecg.sampling_rate) # The math suggests 16 samples is the width of the QRS complex # Measuring the QRS complex for 9004 gives 16 samples # Measured correlated peak 7 samples after start of QRS h_hat = numpy.zeros(num_samples).astype(numpy.float32) # Mexican hats seem to hold a nonzero value between -4 and 4 w/ sigma=1 sigma = 1.0 maxval = 4 * sigma minval = -maxval hat = numpy.zeros(16).astype(numpy.float32) mexican_hat(cuda.Out(hat), numpy.float32(sigma), numpy.float32(minval), numpy.float32((maxval - minval) / num_samples), grid=(1, 1), block=(int(ecg.sampling_rate), 1, 1)) with Timer() as pre_time: d_mlead, length = preprocess(ecg.leads[0], ecg.leads[1], ecg.leads[2], hat, 1.0) with Timer() as time: y = get_heartbeat(d_mlead, length) print pre_time.interval, time.interval, pre_time.interval + time.interval x = numpy.linspace(0, 23, num=len(y)) plt.figure(2) plt.plot(x, y, 'b') plt.show()
def read_ISHNE(ecg_filename): # Read the ISHNE file ecg = ishne.ISHNE(ecg_filename) ecg.read() return ecg
import pycuda.autoinit import pycuda.driver as cuda import numpy import matplotlib.pyplot as plt import ishne from pycuda.compiler import SourceModule import sys with open("wavelet_mod.cu") as wavelet_file: mod = SourceModule(wavelet_file.read()) calculate_hats = mod.get_function("calculate_hats") cross_correlate_with_hat = mod.get_function("cross_correlate_with_hat") ecg = ishne.ISHNE(sys.argv[1]) ecg.read() lead = ecg.leads[0].astype(numpy.float32)[:1000] hats = numpy.zeros(170 * 21).astype(numpy.float32) correlated = numpy.zeros(1000).astype(numpy.float32) calculate_hats(cuda.Out(hats), grid=(170, 1), block=(21, 1, 1)) cross_correlate_with_hat(cuda.Out(correlated), cuda.In(lead), cuda.In(hats[:21]), numpy.int32(10000), grid=(1, 1), block=(1000, 1, 1)) plt.figure(1)