(eeg, dins, labels=None)
return eeg
Convert DIN field into events

    Code adapted from https://github.com/MAMEM/eeg-processing-toolbox
Convert DIN field into events
Convert DIN field into events
def mamem_event(eeg, dins, labels=None):
    """Convert DIN field into events

    Code adapted from https://github.com/MAMEM/eeg-processing-toolbox
    """
    thres_split = 2000
    timestamps = dins[1, :]
    samples = dins[3, :]
    numDins = dins.shape[1]

    sampleA = samples[0]
    previous = timestamps[0]
    t_start, freqs = [], []
    s, c = 0, 0
    for i in range(1, numDins):
        current = timestamps[i]
        if (current - previous) > thres_split:
            sampleB = samples[i - 1]
            freqs.append(s // c)
            if (sampleB - sampleA) > 382:
                t_start.append(sampleA)
            sampleA = samples[i]
            s = 0
            c = 0
        else:
            s = s + (current - previous)
            c = c + 1
        previous = timestamps[i]
    sampleB = samples[i - 1]
    freqs.append(s // c)
    t_start.append(sampleA)
    freqs = np.array(freqs, dtype=np.int) * 2
    freqs = 1000 // freqs
    t_start = np.array(t_start)

    if labels is None:
        freqs_labels = {6: 1, 7: 2, 8: 3, 9: 4, 11: 5}
        for f, t in zip(freqs, t_start):
            eeg[-1, t] = freqs_labels[f]
    else:
        for f, t in zip(labels, t_start):
            eeg[-1, t] = f
    return eeg
def mamem_event ( eeg , dins , labels = None ) : thres_split = 2000 timestamps = dins [ 1 , : ] samples = dins [ 3 , : ] numDins = dins . shape [ 1 ] sampleA = samples [ 0 ] previous = timestamps [ 0 ] t_start , freqs = [ ] , [ ] s , c = 0 , 0 for i in range ( 1 , numDins ) : current = timestamps [ i ] if ( current - previous ) > thres_split : sampleB = samples [ i - 1 ] freqs . append ( s // c ) if ( sampleB - sampleA ) > 382 : t_start . append ( sampleA ) sampleA = samples [ i ] s = 0 c = 0 else : s = s + ( current - previous ) c = c + 1 previous = timestamps [ i ] sampleB = samples [ i - 1 ] freqs . append ( s // c ) t_start . append ( sampleA ) freqs = np . array ( freqs , dtype = np . int ) * 2 freqs = 1000 // freqs t_start = np . array ( t_start ) if labels is None : freqs_labels = { 6 : 1 , 7 : 2 , 8 : 3 , 9 : 4 , 11 : 5 } for f , t in zip ( freqs , t_start ) : eeg [ - 1 , t ] = freqs_labels [ f ] else : for f , t in zip ( labels , t_start ) : eeg [ - 1 , t ] = f return eeg