def _detects_peaks(ecg_integrated, sample_rate):
    """
    Detects peaks from local maximum

    ----------
    Parameters
    ----------
    ecg_integrated : ndarray
        Array that contains the samples of the integrated signal.
    sample_rate : int
        Sampling rate at which the acquisition took place.

    Returns
    -------
    choosen_peaks : list
        List of local maximums that pass the first stage of conditions needed to be considered as
        a R peak.
    possible_peaks : list
        List with all the local maximums in the signal.

    """

    # Minimum RR interval = 200 ms
    min_rr = (sample_rate / 1000) * 200

    # Computes all possible peaks and their amplitudes
    possible_peaks = [i for i in range(0, len(ecg_integrated)-1)
                      if ecg_integrated[i-1] < ecg_integrated[i] and
                      ecg_integrated[i] > ecg_integrated[i+1]]

    possible_amplitudes = [ecg_integrated[k] for k in possible_peaks]
    chosen_peaks = []

    # Starts with first peak
    if not possible_peaks:
        raise Exception("No Peaks Detected.")
    peak_candidate_i = possible_peaks[0]
    peak_candidate_amp = possible_amplitudes[0]
    for peak_i, peak_amp in zip(possible_peaks, possible_amplitudes):
        if peak_i - peak_candidate_i <= min_rr and peak_amp > peak_candidate_amp:
            peak_candidate_i = peak_i
            peak_candidate_amp = peak_amp
        elif peak_i - peak_candidate_i > min_rr:
            chosen_peaks += [peak_candidate_i - 6]  # Delay of 6 samples
            peak_candidate_i = peak_i
            peak_candidate_amp = peak_amp
        else:
            pass

    return chosen_peaks, possible_peaks