p1 = feffpath('feff0001.dat')
p1.e0 = -0.2
p1.sigma2 = 0.006
path2chi(p1, interp='linear')

eps_off = 1.e-7
kwin='parzen'
kwin='welch'

for iscale in range(15):
    scale = 1.e-5 *  2**iscale
    eps = []
    for  i in range(25):
        sum  = p1.chi + random.normal(size=len(p1.chi), scale=scale)
        tmp = group(k=p1.k, chi=sum)
        xftf(tmp.k, tmp.chi, group=tmp,
             kmin=3, kmax=16, kweight=2, dk=3.5, window=kwin)
        estimate_noise(tmp.k, tmp.chi, group=tmp,
                       kmin=3, kmax=16, kweight=2, dk=3.5, window=kwin)
        eps.append(tmp.epsilon_k)
    endfor
    if iscale == 0:
         newplot(tmp.k, tmp.chi*tmp.k)
         plot(tmp.k, tmp.kwin*0.7)
         newplot(tmp.r, tmp.chir_mag, xmax=25, win=2)
         print( ' I  InputNoise| Estimated Noise       =>  Ratio')
    else:
        update_trace(tmp.k, tmp.chi*tmp.k, trace=1, win=1)
        update_trace(tmp.r, tmp.chir_mag, trace=1, win=2)
    endif
    eps  = array(eps)
    eave = eps.mean()
    pred = sqrt(scale**2 + eps_off**2)
    print( ' %2.2i  %.7f  | %.7f +/-  %.7f  => %.7f || %.7f=> %.7f' % (iscale, scale, eave, eps.std(), eave/scale, pred, pred/eave))
endfor
