def find_beat(v):
    """
    find the beat of a vector format midi using the autocorrelation function
    """
    # binary vector for testing autocorrelation
    v2 = [0 if x[0] == -1 else 1 for x in v]
    result = []
    # no need to check more than 24*4 = 96
    # i.e. 4 quarter notes of standard midi
    for lag in range(96):
        s = 0
        for i in range(len(v2)):
            if v2[i] > 0 and v2[(i + lag) % len(v2)] > 0:
                s += 1
        result.append((lag, s))
    k = 1
    srt = sorted(result, key=lambda x: x[1])
    while srt[-k][0] == 0:
        k += 1
    return srt[-k][0]