def chisquare_ci(N = 19):
    """
    Retrieves the critical z-value for the chi-square distribution.
    This is used during PSD estimation to get a 95% confidence interval (CI).

    input:
    ------------------------
    N : the number of averaging used to produce the estimation.
    (argument `overlap` of `psd` minus 1)

    returns:
    ------------------------
    lower, upper, N

    The PSD should be transformed as p_low = p*a1/N and p_up = p*a2/N to give the
    range of the 95% CI values.
    """
    lower = []
    upper = []
    if N == 19:
        a1 = 8.907
        a2 = 32.852
    elif N == 17:
        a1 = 7.56
        a2 = 30.19
    elif N == 4:
        a1 = 0.485
        a2 = 11.14
    elif N == 3:
        a1 = 0.216
        a2 = 9.348
    elif N == 2:
        a1 = 0.0506
        a2 = 7.378
    elif N == 1:
        a1 = 0.000982
        a2 = 5.024
        # for p in pxx:
        #     lower.append(p*a1/N)
        #     upper.append(p*a2/N)
    else:
        raise Exception("Unknown overlap")
    return a1, a2, N