def persistent_imag_state(imag_state, spike, threshold, scale):
    """Handles refractory state change due to spike in last time bin.

    Parameters
    ----------
    imag_state : torch tensor
        imaginary sate in last time bin.
    spike : torch tensor
        spike state in last time bin.
    threshold : float
        threshold value.
    scale : int
        parameter scaling value.

    Returns
    -------
    torch tensor
        persistent state to store for next time.
    """
    spike = (spike > 0).to(imag_state.dtype)
    return spike * (threshold - 1 / scale) + (1 - spike) * imag_state