def step_symmetry(autocorr_peak_values):
    """
    Calculate step symmetry from autocorrelation peak values.

    Step symmetry measures based on `Moe-Nilssen (2004) - Estimation of gait
    cycle characteristics by trunk accelerometry
    <http://www.jbiomech.com/article/S0021-9290(03)00233-1/abstract>`_.

    If calculating symmetry from acceleration in the vertical axis, this
    function receives the detected peaks from the vertical axis
    autocorrelation.

    However, if calculating symmetry from lateral axis
    acceleration, you should pass in *both* peaks and valleys from the
    autocorrelation of the lateral axis.

    Perfect step symmetry is 1.0 for the vertical axis - larger values are
    more symmetric, capped at 1.0.

    Perfect step symmetry is -1.0 for the lateral axis - smaller values are
    more symmetric, capped at -1.0.

    Parameters
    ----------
    autocorr_peak_values : ndarray
        Values of the autocorrelation peaks/valleys detected by
        :func:`sensormotion.peak.find_peaks`. This should contain only peak
        values when looking at the vertical axis, and both peak and valley
        values when looking at the lateral axis.

    Returns
    -------
    step_sym : float
        Step symmetry. Value is capped at 1.0 or -1.0 depending on the
        axis of interest.
    """

    peaks_half = autocorr_peak_values[autocorr_peak_values.size // 2 :]

    assert len(peaks_half) >= 3, (
        "Not enough autocorrelation peaks detected. Plot the "
        "autocorrelation signal to visually inspect peaks"
    )

    ac_d1 = peaks_half[1]  # first dominant period i.e. a step (left-right)
    ac_d2 = peaks_half[2]  # second dominant period i.e. a stride (left-left)

    # Always divide smaller peak by the larger peak
    if abs(ac_d1) > abs(ac_d2):
        step_sym = ac_d2 / ac_d1  # Preserve sign by not using abs()
    else:
        step_sym = ac_d1 / ac_d2  # Preserve sign by not using abs()

    return step_sym