Пример #1
0
def main(argv):
    siarray = wfdb.isigopen("100s")
    if siarray.nsig < 2: sys.exit(1)
    v = wfdb.WFDB_SampleArray(2)
    for i in range(0,10):
        if wfdb.getvec(v.cast()) < 0: sys.exit(2)
        print "\t%d\t%d" % (v[0], v[1])
Пример #2
0
 def read(self , record = None):
     if record == None:
         if self.record == None:
             sys.exit(1)
         else:
             record = self.record
     else:
         self.record = record
         
     sig0 = []
     sigt = []
     
     siarray = wfdb.WFDB_SiginfoArray(2)
     
     if (wfdb.isigopen(record , siarray.cast() , 2) < 1):
         sys.exit(1)
     
     v = wfdb.WFDB_SampleArray(2)
     
     
     #Getting X Axes Interval
     #Appending data to array
     X_INTERVAL = 20
     pause = 0
     for i in range(siarray.cast().nsamp):
         if ( wfdb.getvec(v.cast()) < 0 ):
             break
         sig0.append(v.__getitem__(0))
         sigt.append(pause)
         pause = pause + X_INTERVAL
         pass
     
     #High Pass Filtering
     highpass_filter = HighpassFilter()
     high_pass = highpass_filter.process(sig0,siarray.cast().nsamp)
     #Low pass Filtering
     lowpass_filter = LowpassFilter()
     low_pass = lowpass_filter.process(high_pass, len(high_pass))
     
     qrs = QRSDetector()
     qrs_data = qrs.process(low_pass, len(low_pass))
     
     feature_extractor = FeatureExtractor()
     features = feature_extractor.get_RR_interval(sig0, qrs_data)
     
     #sig0 = qrs_dat
       
     
     wfdb.wfdbquit() 
     
     return sigt , sig0 , features
Пример #3
0
    def read(self, record=None):
        if record == None:
            if self.record == None:
                sys.exit(1)
            else:
                record = self.record
        else:
            self.record = record

        sig0 = []
        sigt = []

        siarray = wfdb.WFDB_SiginfoArray(2)

        if (wfdb.isigopen(record, siarray.cast(), 2) < 1):
            sys.exit(1)

        v = wfdb.WFDB_SampleArray(2)

        #Getting X Axes Interval
        #Appending data to array
        X_INTERVAL = 20
        pause = 0
        for i in range(siarray.cast().nsamp):
            if (wfdb.getvec(v.cast()) < 0):
                break
            sig0.append(v.__getitem__(0))
            sigt.append(pause)
            pause = pause + X_INTERVAL
            pass

        #High Pass Filtering
        highpass_filter = HighpassFilter()
        high_pass = highpass_filter.process(sig0, siarray.cast().nsamp)
        #Low pass Filtering
        lowpass_filter = LowpassFilter()
        low_pass = lowpass_filter.process(high_pass, len(high_pass))

        qrs = QRSDetector()
        qrs_data = qrs.process(low_pass, len(low_pass))

        feature_extractor = FeatureExtractor()
        features = feature_extractor.get_RR_interval(sig0, qrs_data)

        #sig0 = qrs_dat

        wfdb.wfdbquit()

        return sigt, sig0, features
Пример #4
0
def main(argv):
    nsamp = 1000
    if len(argv) < 2:
        print "usage:", argv[0], "record"
        sys.exit(1)
    nsig = wfdb.isigopen(argv[1], None, 0)
    if nsig <= 0: sys.exit(2)
    s = wfdb.WFDB_SiginfoArray(nsig)
    vin = wfdb.WFDB_SampleArray(nsig)
    vout = wfdb.WFDB_SampleArray(nsig)
    if wfdb.isigopen(argv[1], s.cast(), nsig) != nsig: sys.exit(2)
    if wfdb.osigopen("8l", s.cast(), nsig) <= 0: sys.exit(3)
    while nsamp > 0 and wfdb.getvec(vin.cast()) > 0:
        nsamp -= 1
        for i in range(0, nsig): vout[i] -= vin[i]
        if wfdb.putvec(vout.cast()) < 0: break
        for i in range(0, nsig): vout[i] = vin[i]
    wfdb.newheader("dif")
    wfdb.wfdbquit()
Пример #5
0
def main(argv):
    record = ''

    # Parse the arguments
    try:
        opts, args = getopt.getopt(argv, "hr:", ["help"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt == '-r':
            record = arg

    # Read the number of signals in the record
    nsig = wfdb.isigopen(record, None, 0)

    # Exit if the record is not found, or there are no signals
    if nsig < 1:
        usage()
        sys.exit(2)

    siarray = wfdb.WFDB_SiginfoArray(nsig)
    wfdb.isigopen(record, siarray, nsig)

    n = 0
    v = wfdb.intArray(nsig)

    # Loop over each sample and print the signal values.
    while wfdb.getvec(v) > 0:
        print n,
        for i in range(0,nsig):
            print v[i],
        print
        n = n + 1
        
    wfdb.wfdbquit()
Пример #6
0
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()
Пример #7
0
def main(argv):
    db_path = "/opt/physiobank/database"
    record = ''
    wfdb.setwfdb(db_path)
    # Parse the arguments
    try:
        opts, args = getopt.getopt(argv, "hr:", ["help"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt == '-r':
            record = arg

    # Read the number of signals in the record
    nsig = wfdb.isigopen(record, None, 0)

    # Exit if the record is not found, or there are no signals
    if nsig < 1:
        usage()
        sys.exit(2)

    siarray = wfdb.WFDB_SiginfoArray(nsig)
    wfdb.isigopen(record, siarray, nsig)

    n = 0
    v = wfdb.intArray(nsig)
    lf = bf_math.intArray(siarray[0].nsamp)
    global sld_samp
    global ln
    global y_axes
    global sr_ds  
    global subplt
    sr = (int)(wfdb.sampfreq(record))
    print "sr:",sr
    sr_ds = 50
    # Loop over each sample and print the signal values.
    while wfdb.getvec(v) > 0:
        for i in range(0,1):
            lf[n] = v[i]
        n = n + 1
    bf_math.filtering(lf,siarray[0].nsamp,sr)
    _nsamp = siarray[0].nsamp
    
    x_axes = xrange(_nsamp*sr_ds/sr)
    print "x_axes:", _nsamp*sr_ds/sr
    y_axes = []
    for i in xrange(_nsamp):
         b, val = bf_math.down_sample(lf[i], sr, sr_ds)
         if (b):
             y_axes.append(val)
    print "y_axes:", len(y_axes)
    plt.figure(1)
    subplt = plt.subplot(111)
    ln, = plt.plot(xrange(0,5*sr_ds), y_axes[0:5*sr_ds] )
    #plt.axis([-100, 100])
    plt.ylim(-300,300)
    #subplt.autoscale_view(True,True,True)
    axcolor = 'lightgoldenrodyellow'
    axsamp = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
    sld_samp = Slider(axsamp, 'samp', 0.1, 33*60, valinit=1)

    sld_samp.on_changed(update)
    plt.show()    
    wfdb.wfdbquit()
Пример #8
0
def get_ecg_signal(rec_name, annotation, start_time, end_time):
    #variables and arrays

    iteration = []
    sig_time = []
    #count=0;
    #ann_graph=[];
    #split_time0=[];
    #annotator_array=[];

    nsamp, freq, annot, init_time, sdata = ws.setupWfdb(rec_name, annotation)

    sig0 = []
    sig1 = []

    #physig0 is array with physical units
    physig0 = []
    physig1 = []

    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));

    #sample interval

    #required length of signal in seconds
    #num_sample_start=start_time*60*freq
    num_sample_end = end_time * 60 * freq
    loop_iteration = int(math.floor(num_sample_end))

    #print("loop iteration = " +str(loop_iteration));

    # loop runs for loop_iteration times to extract signal samples

    num_value = loop_iteration

    for i in range(0, num_value):
        if wfdb.getvec(sdata.cast()) < 0:
            print "ERROR: getvec() < 0"
            exit()
        else:
            #signal values in adu units:
            sig0.append(sdata[0])
            sig1.append(sdata[1])

            sig_time.append(gettime(i, freq, init_time))
            #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
            #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
            physig0.append(aduphys(0, sig0[i]))
            physig1.append(aduphys(1, sig1[i]))

            #append iteration number as value in
            iteration.append(i)

    #getann reads next annotation and returns 0 when successful
    while wfdb.getann(0, annot) == 0:
        if annot.time > num_value:
            #print("annot.time>number of samples extracted");
            break
        #  annot.time is time of the annotation, in samples from the beginning of the record.
        print wfdb.timstr(-annot.time), "(" + str(
            annot.time) + ")", wfdb.annstr(
                annot.anntyp), annot.subtyp, annot.chan, annot.num
        print("signal value at this annotation is : " +
              str(physig0[annot.time]) + " " + str(sig_time[annot.time]))

    return (physig0, physig1, sig_time)
Пример #9
0
    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))

print("loop iteration = " + str(loop_iteration))

# loop runs for loop_iteration times to extract signal samples
num_value = loop_iteration
for i in range(0, num_value):
    if wfdb.getvec(sdata.cast()) < 0:
        print "ERROR: getvec() < 0"
        exit()
    else:
        #signal values in adu units:
        sig0.append(sdata[0])
        sig1.append(sdata[1])

        sig_time.append(gettime(i, freq, init_time))
        #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
        #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
        physig0.append(aduphys(0, sig0[i]))
        physig1.append(aduphys(1, sig1[i]))

        #append iteration number as value in
        iteration.append(i)
Пример #10
0
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()
    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));

print("loop iteration = " +str(loop_iteration));


# loop runs for loop_iteration times to extract signal samples
num_value=loop_iteration;
for i in range(0,num_value):
    if wfdb.getvec(sdata.cast()) < 0:
        print "ERROR: getvec() < 0";
        exit();
    else:
        #signal values in adu units:
        sig0.append(sdata[0]);
        sig1.append(sdata[1]);
         
        sig_time.append(gettime(i, freq, init_time));
        #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
        #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
        physig0.append(aduphys(0,sig0[i]));
        physig1.append(aduphys(1,sig1[i]));
        
        #append iteration number as value in 
        iteration.append(i);
Пример #12
0
def get_ecg_signal(rec_name,annotation,start_time,end_time):
    #variables and arrays 
    
    iteration=[];
    sig_time=[];
    #count=0;
    #ann_graph=[];
    #split_time0=[];
    #annotator_array=[];
    
    
    nsamp, freq, annot, init_time,sdata = ws.setupWfdb(rec_name,annotation);
  
    sig0 = [];
    sig1 = [];
    
    #physig0 is array with physical units
    physig0=[];
    physig1=[];
    
    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));
    

    #sample interval
    
    #required length of signal in seconds
    #num_sample_start=start_time*60*freq
    num_sample_end=end_time*60*freq
    loop_iteration=int(math.floor(num_sample_end));
    
    #print("loop iteration = " +str(loop_iteration));
    
    
    # loop runs for loop_iteration times to extract signal samples
    
    num_value=loop_iteration;
    
    for i in range(0,num_value):
        if wfdb.getvec(sdata.cast()) < 0:
            print "ERROR: getvec() < 0";
            exit();
        else:
            #signal values in adu units:
            sig0.append(sdata[0]);
            sig1.append(sdata[1]);
            
            sig_time.append(gettime(i, freq, init_time));
            #print("time for sample " + str(i) + "is: " + str(sig_time[i]));
            #convert adu units to physical units and save in physig0 and 1 (later generalise it for n number of signals)
            physig0.append(aduphys(0,sig0[i]));
            physig1.append(aduphys(1,sig1[i]));
           
            #append iteration number as value in 
            iteration.append(i);
            
        
    #getann reads next annotation and returns 0 when successful
    while wfdb.getann(0,annot) ==0:
        if annot.time>num_value:
            #print("annot.time>number of samples extracted");
            break;
        #  annot.time is time of the annotation, in samples from the beginning of the record.
        print wfdb.timstr(-annot.time),"(" + str(annot.time)+ ")",wfdb.annstr(annot.anntyp), annot.subtyp,annot.chan, annot.num
        print ("signal value at this annotation is : " + str(physig0[annot.time])+" "+ str(sig_time[annot.time]));
    
    
    return(physig0,physig1,sig_time)