[Ifeffit] Purple & Red E Derivatives

Matt Newville newville at cars.uchicago.edu
Tue Feb 22 19:28:51 CST 2011


Hi Bruce, Matthew,

Oh, deriv() (and smooth()) are not nearly as sophisticated as what
Matthew suggests.  They are simply applied to a single array,
sequentially, without regard to "the x axis"  (as, in fact, it does
not know what x might be):

Deriv would translate (sorry for the python) to
def deriv(x):
    npts = len(x)
    out  = array(npts)
    out[0] = x[1] - x[0]
    out[npts-1] = x[npts-1] - x[npts-2]
    for i in range(1, npts-2):  # (1, 2, 3, ... npts-2)
        out[i] = (x[i+1] - x[i])/2.0

    return out

and Smooth:
def smooth(x):
    npts = len(x)
    out  = array(npts)
    out[0] = 0.75*x[0] + 0.25 * x[1]
    out[npts-1] = 0.75*x[npts-1] + 0.25 * x[npts-2]
    for i in range(1, npts-2): # (1, 2, 3, ... npts-2)
        out[i] = 0.5*x[i] + 0.25*x[i+1] + 0.25*x[i-1]

    return out

Like Matthew suggests, interpolating onto a finer, uniform x (energy)
grid and then taking the derivative might be a better approach, at
least for data which needs smoothing.

--Matt



On Wed, Feb 23, 2011 at 8:46 AM, Bruce Ravel <bravel at bnl.gov> wrote:
> On Tuesday, February 22, 2011 06:19:16 pm Matthew Marcus wrote:
>> > The numerical derivative
>> > is computed as the numerical differential of the mu(E) spectrum
>> > divided by the numerical differential of the energy array.  Smoothing
>> > happens as explained above.  Justw atch the lines that get printed to
>> > the buffer when you click the plot buttons. - B. Ravel
>>
>> I wonder if that's the right way to go for data that, for instance, might
>> have gaps or changes in step size.  What I do in my code is run a cubic
>> spline through the data, with the abscissa as is,
>> then take the derivative of that spline.  Thus, if the data is smooth
>> enough to be locally approximated by a cubic, the derivative will come out
>> smooth regardless of how it's tabulated.  I'm not
>> sure that's the case with Bruce's algorithm.  Is the 'numerical
>> differential' the difference E(i+1)-E(i) or (1/2)*(E(i+1)-E(i-1)) or some
>> form that's intended to approximate dE(i)/di (i= point index)?
>>
>> It's not clear to me whether it's any more correct to do smoothing before
>> or after differentiating.  You can take the red pill or the blue pill :-)
>>     mam
>
> Well ... red pill or purple pill.  They both have side effects that 4
> out of 5 doctors advise against :)
>
> So, I do what's easy using Ifeffit as Ifeffit is implemented.  I would
> have to code dive (or ask Matt) what the deriv() function actually
> does.
>
> A big gap in the data might result in a weird derivative spectrum, but
> changes in step size isn't so much of a problem because I ask Ifeffit
> to compute d(mu)/d(E).
>
> I agree that "smooth then differentiate" is not obviously better than
> "differentiate then smooth".  What is certainly wrong is to do this
> inconsistently.
>
> B
>
>
> --
>
>  Bruce Ravel  ------------------------------------ bravel at bnl.gov
>
>  National Institute of Standards and Technology
>  Synchrotron Methods Group at NSLS --- Beamlines U7A, X24A, X23A2
>  Building 535A
>  Upton NY, 11973
>
>  My homepage:    http://xafs.org/BruceRavel
>  EXAFS software: http://cars9.uchicago.edu/~ravel/software/exafs/
> _______________________________________________
> Ifeffit mailing list
> Ifeffit at millenia.cars.aps.anl.gov
> http://millenia.cars.aps.anl.gov/mailman/listinfo/ifeffit
>
>




More information about the Ifeffit mailing list