def freq_by_extremums(xdata, sample_rate):
    """ Calculate frequency of oscillating signal by extremums.

    Parameters
    ----------
    xdata: array_like
        Values of input signals.
    sample_rate: float
        Sampling frequency (Hz).

    Returns
    -------
    : float
        Frequency.
    """
    T = len(xdata) / sample_rate
    n_max = 0
    n_min = 0
    for x_p, x_c, x_n in zip(xdata[:-2], xdata[1:-1], xdata[2:]):
        if x_p < x_c and x_c >= x_n:
            n_max += 1
        if x_p > x_c and x_c <= x_n:
            n_min += 1
    n = (n_max + n_min) / 2
    return n / T
