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): 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()