[Matrix-SIG] FFT derivative

Jean-Bernard ADDOR jbaddor@sca.uqam.ca
Thu, 4 Nov 1999 17:00:43 -0500 (EST)


Hey Numerical people!

I wrote a python code for derivation in Fourrier space, and it gives very
bad results. The idea is to multiply the transform of the data by -ik.

Do you have any hint? Do you know about any code in any language which do
that, and I could just translate into python? Are any books with detailled
example of the use of the FFT to compute derivatives?


	Jean-Bernard

def FFTderivative(a, order=1, axis=-1):
    from Numeric import arange
    from FFT import fft, inverse_fft
    a = Numeric.asarray(a) # works on arbitrary python sequence
    l = a.shape[axis]/2
    m = a.shape[axis] - 2*l
    if axis != -1: a = Numeric.swapaxes(a, axis, -1)
    b = fft(concatenate((a, a[...,::-1]), -1)) # JD trick, could be made
nicer
    c =
(1j*concatenate((arange(a.shape[-1]),arange(-a.shape[-1],0))))**order
    #c = (1j*concatenate((arange(l+m),arange(-l,0))))**order # was before
fourier space doubling
    # from the FT theory it should be -1j instead of 1j, why?
    d = b*c
    r = inverse_fft(d)[...,:a.shape[-1]]
    if a.typecode() != 'D' and a.typecode() != 'F': # not complex type
        r = r.real
    if axis != -1: r = Numeric.swapaxes(r, axis, -1)
    return r