def within_duration(events, time, limits):
    """Check whether event is within time limits.

    Parameters
    ----------
    events : ndarray (dtype='int')
        N x 3 matrix with start, peak, end samples
    time : ndarray (dtype='float')
        vector with time points
    limits : tuple of float
        low and high limit for spindle duration

    Returns
    -------
    ndarray (dtype='int')
        N x 3 matrix with start , peak, end samples

    """
    min_dur = time[events[:, (2)] - 1] - time[events[:, (0)]] >= limits[0]
    max_dur = time[events[:, (2)] - 1] - time[events[:, (0)]] <= limits[1]
    return events[(min_dur & max_dur), :]
