Beispiel #1
0
def max2interval(peaks, cols,  minrate=40, maxrate=200):
    """
    Returns intervals from timesMax, after filtering possible artefacts based on rate range (rates in min^(-1))
    if two peaks are nearer than minrate or further than maxrate, the algorithm try to recognize if there's a false true or a peak missing
    return: an nparray (N,3) containing in order the time, the ibi and the label
    peaks: an nparray (N,3) containing in order the timestamp, the height and the label of each peak
    minrate: represents the minimum(in min^(-1)) bpm to detect
    maxrate: represents the maximum(in min^(-1)) bpm to detect
    """
    maxRR=60/minrate
    minRR=60/maxrate

    RR=[]
    timeRR=[]

    # algoritmo alternativo
    # beat artifacts correction
    ##inizializzazioni
    timed_lbls = selcol(peaks, cols, ["TIME", "LAB"])
    peaks_time = selcol(peaks, cols, "TIME")
    # print "TIME %d, LAB %d" % (len(timed_lbls[:,0]), len(timed_lbls[:,1]))
    
    tprev=peaks_time[0]
    tfalse=tprev

    for i in range(1, len(peaks_time)):
        tact=peaks_time[i]

        RRcurr=tact-tprev
        if (RRcurr<minRR): # troppo breve: falso picco?
            tfalse=tact  #aspetto (non aggiorno tact) e salvo il falso campione

        elif RRcurr>maxRR: # troppo lungo ho perso un picco?
            RRcurr=tact-tfalse # provo con l'ultimo falso picco se esiste
            tprev=tact # dopo ripartiro' da questo picco

        if RRcurr>minRR and RRcurr<maxRR: # tutto OK
            RR.append(RRcurr) #aggiungo valore RR
            timeRR.append(tact) #aggiungo istante temporale
            tfalse=tact #aggiorno falso picco
            tprev=tact #aggiorno tprev
    #calculates the labels foreach time in timeRR
    try:
        labelRR = get_row_for_col(timed_lbls, timeRR)[:,1]
    except IndexError as e:
        print "NO LABELS: ", e.message
        labelRR=np.array([])
        pass
    #the result contains a 2D array with the times and the ibi
    return np.column_stack((timeRR, RR, labelRR)), ["TIME", "IBI", "LAB"]
Beispiel #2
0
def getPeaksIBI(signal, cols, peakDelta, s_type):
    '''
    get the peaks for the ibi calculation
    return: an nparrays (N,3), containing in order the time (in s), the height of the peak and the lables and the column names
    signal: signal as np.array (N,3) in which search the peaks (columns: timestamp, signal, labels)
    peakDelta: minimum peak height
    SAMP_F: the sampling frequency of signal
    cols: the column labels
    s_type=signal type: BVP or GSR
    '''
    timed_lbls = selcol(signal, cols, ["TIME", "LAB"])
    t = selcol(signal, cols,  "TIME")
    signal_vals = selcol(signal ,cols, s_type)
    maxp, minp = peakdet(signal_vals, peakDelta, t)
    try:
        new_lbls = get_row_for_col(timed_lbls, maxp[:,0])[:,1]
    except IndexError as e:
        print "IBI LABS: ", e.message
        new_lbls = np.array([])
        pass
    cols_out=["TIME", "PEAK", "LAB"]
    return np.column_stack((maxp, new_lbls)), cols_out