def main(argv): nc = len(argv) - 4 if len(argv) < 4: print "usage:", argv[0], "record start duration [ coefficients ... ]" sys.exit(1) if nc < 1: nc = 1 c = [0.] * nc for i in range(0, nc): c[i] = float(argv[i+4]) nsig = wfdb.isigopen(argv[1], None, 0) if nsig < 1: sys.exit(3) s = wfdb.WFDB_SiginfoArray(nsig) v = wfdb.WFDB_SampleArray(nsig) if wfdb.isigopen(argv[1], s.cast(), nsig) != nsig: sys.exit(3) if wfdb.isigsettime(wfdb.strtim(argv[2])) < 0: sys.exit(4) nsamp = wfdb.strtim(argv[3]) if nsamp < 1: print argv[0]+ ": inappropriate value for duration" sys.exit(5) if wfdb.osigopen("16l", s.cast(), nsig) != nsig: sys.exit(6) wfdb.sample(0, 0) for t in range(0, nsamp): if not wfdb.sample_valid(): break for j in range(0, nsig): vv = 0 for i in range(0, nc): if c[i] != 0.: vv += c[i] * wfdb.sample(j, t+i) v[j] = int(vv) if wfdb.putvec(v.cast()) < 0: break wfdb.newheader("out") wfdb.wfdbquit()
def main(argv): time = maxslope = nslope = scmin = 0 a = wfdb.WFDB_Anninfo() annot = wfdb.WFDB_Annotation() if len(argv) < 2: print "usage:", argv[0], "record [threshold]" sys.exit(1) a.name = "qrs" a.stat = wfdb.WFDB_WRITE nsig = wfdb.isigopen(argv[1], None, 0) if nsig < 1: sys.exit(2) s = wfdb.WFDB_SiginfoArray(nsig) v = wfdb.WFDB_SampleArray(nsig) if wfdb.wfdbinit(argv[1], a, 1, s.cast(), nsig) != nsig: sys.exit(2) if wfdb.sampfreq(None) < 240. or wfdb.sampfreq(None) > 260.: wfdb.setifreq(250.) if len(argv) > 2: scmin = wfdb.muvadu(0, argv[2]) if scmin < 1: scmin = wfdb.muvadu(0, 1000) slopecrit = scmax = 10 * scmin ms160 = wfdb.strtim("0.16") ms200 = wfdb.strtim("0.2") s2 = wfdb.strtim("2") annot.subtyp = annot.chan = annot.num = 0 annot.aux = None wfdb.getvec(v.cast()) t9 = t8 = t7 = t6 = t5 = t4 = t3 = t2 = t1 = v[0] while 1: t0 = v[0] filter = t0 + 4*t1 + 6*t2 + 4*t3 + t4 - t5 - 4*t6 - 6*t7 - 4*t8 - t9 if time % s2 == 0: if nslope == 0: slopecrit -= slopecrit >> 4 if slopecrit < scmin: slopecrit = scmin elif nslope >= 5: slopecrit += slopecrit >> 4 if slopecrit > scmax: slopecrit = scmax if nslope == 0 and abs(filter) > slopecrit: nslope = 1 maxtime = ms160 if filter > 0: sign = 1 else: sign = -1 qtime = time if nslope != 0: if filter * sign < -slopecrit: sign = -sign nslope = nslope + 1 if nslope > 4: maxtime = ms200 else: maxtime = ms160 elif filter * sign > slopecrit and \ abs(filter) > maxslope: maxslope = abs(filter) if maxtime < 0: if 2 <= nslope and nslope <= 4: slopecrit += ((maxslope>>2) - slopecrit) >> 3 if slopecrit < scmin: slopecrit = scmin elif slopecrit > scmax: slopecrit = scmax annot.time = wfdb.strtim("i") - (time - qtime) - 4 annot.anntyp = wfdb.NORMAL wfdb.putann(0, annot) time = 0 elif nslope >= 5: annot.time = wfdb.strtim("i") - (time - qtime) - 4 annot.anntyp = wfdb.ARFCT wfdb.putann(0, annot) nslope = 0 maxtime = maxtime - 1 t9 = t8 t8 = t7 t7 = t6 t6 = t5 t5 = t4 t4 = t3 t3 = t2 t2 = t1 t1 = t0 time = time + 1 if not wfdb.getvec(v.cast()) > 0: break wfdb.wfdbquit()
#WFDB_Anninfor() contains name and attributes of annotator .atr etc a = wfdb.WFDB_Anninfo() #WFDB_Annotation describes the attributes of signals #declare object in c : WFDB_Annotation annot; see below for declaring object in python annot = wfdb.WFDB_Annotation() #read name and status of annotation file a.name = annotation print a.name a.stat = wfdb.WFDB_READ freq = wfdb.sampfreq(rec_name) nsamp = siarray[0].nsamp init_time = wfdb.timstr(0) print type(init_time) print("strtim for starting value is: " + str(wfdb.strtim(init_time))) print("total num of samples: " + str(nsamp)) print "Starting time of record is: " + str(init_time) print("sampling frequency is:" + str(freq)) def gettime(sample_num, freq, init_time): return float(sample_num) / float(freq) #sample interval #required length of signal in seconds siglength_sec = 1 print type(freq)
def main(argv): nbeats = stoptime = 0 a = wfdb.WFDB_Anninfo() annot = wfdb.WFDB_Annotation() if len(argv) < 3: print "usage:", argv[0], "annotator record [beat-type from to]", sys.exit(1) a.name = argv[1] a.stat = wfdb.WFDB_READ nsig = wfdb.isigopen(argv[2], None, 0) if nsig < 1: sys.exit(2) s = wfdb.WFDB_SiginfoArray(nsig) v = wfdb.WFDB_SampleArray(nsig) vb = wfdb.WFDB_SampleArray(nsig) sum = [None] * nsig if wfdb.wfdbinit(argv[2], a, 1, s.cast(), nsig) != nsig: sys.exit(3) hwindow = wfdb.strtim(".05") window = 2*hwindow + 1 for i in range(nsig): sum[i] = [0] * window if len(argv) > 3: btype = wfdb.strann(argv[3]) else: btype = wfdb.NORMAL if len(argv) > 4: wfdb.iannsettime(wfdb.strtim(argv[4])) if len(argv) > 5: stoptime = wdfb.strtim(argv[5]) if stoptime < 0: stoptime = -stoptime if s[0].nsamp > 0 and stoptime > s[0].nsamp: stoptime = s[0].nsamp else: stoptime = s[0].nsamp if stoptime > 0: stoptime -= hwindow while 1: if not (wfdb.getann(0, annot) == 0 and annot.time < hwindow): break while 1: if annot.anntyp == btype: wfdb.isigsettime(annot.time - hwindow - 1) wfdb.getvec(vb.cast()) j=0 while j < window and wfdb.getvec(v.cast()) > 0: for i in range(nsig): sum[i][j] += v[i] - vb[i] j += 1 nbeats += 1 if not (wfdb.getann(0, annot) == 0 and \ (stoptime == 0L or annot.time < stoptime)): break if nbeats < 1: print argv[0] + ": no `" + wfdb.annstr(btype) + "' beats found" sys.exit(4) print "Average of", nbeats, "`" + wfdb.annstr(btype) + "' beats:" for j in range(window): for i in range(nsig): print "%(av)g" % {'av': float(sum[i][j])/nbeats}, sys.stdout.write("") # surpress next space if i < nsig-1: print "\t", else: print wfdb.wfdbquit()
#WFDB_Anninfor() contains name and attributes of annotator .atr etc a = wfdb.WFDB_Anninfo(); #WFDB_Annotation describes the attributes of signals #declare object in c : WFDB_Annotation annot; see below for declaring object in python annot = wfdb.WFDB_Annotation(); #read name and status of annotation file a.name=annotation; print a.name a.stat = wfdb.WFDB_READ; freq=wfdb.sampfreq(rec_name); nsamp=siarray[0].nsamp; init_time=wfdb.timstr(0); print type(init_time); print("strtim for starting value is: " + str(wfdb.strtim(init_time))); print("total num of samples: " + str(nsamp)); print "Starting time of record is: "+ str(init_time); print("sampling frequency is:"+ str(freq)); def gettime(sample_num, freq, init_time): return float(sample_num)/float(freq) #sample interval #required length of signal in seconds siglength_sec=1; print type(freq); loop_iteration=int(math.floor(siglength_sec*freq));