def window_bounds(i, n, wn):
    """Start and stop indices for a moving window.

    Parameters
    ----------
    i : int
        Current index
    n : int
        Total number of points
    wn : int, odd
        Total window size

    Returns
    -------
    start : int
        Start index
    stop : int
        Stop index
    at_end : bool
        Whether we are truncating the window
    """

    at_end = False
    hw = wn // 2

    start = i - hw
    stop = i + hw + 1

    if start < 0:
        at_end = True
        start = 0
    elif stop > n:
        at_end = True
        stop = n

    return start, stop, at_end