[SciPy-user] FFT not producing correct result

Mike Duffy mike.s.duffy at gmail.com
Thu Jul 6 14:04:37 EDT 2006


I have been trying to use fft/ifft for a program, but the program has been
failing. So, I tried testing the fft fuunction alone and found that it does
not work as I woul expect it to. The test I have been using is to feed it a
standard Gaussian, since the FFT of this should be just another gaussian.
But, this is not what I get at all. I've been using pylab to visualize the
function before and after the transform. Here is my test code:

<code>
def main():
    sigma = 25.
    x = arange(0, 100, 1, 'f')
    x0 = 50.
    g = exp(-(x - x0)**2 / (2 * sigma)) / sqrt(2 * pi)
    for i in xrange(1):
        testFFT(x, g)

def testFFT(x, f):
    pylab.plot(x, f)
    pylab.title('Initial gaussian')
    pylab.show()
    pylab.clf()

    f = fft(f)
    pylab.plot(x, abs(f))
    pylab.title('After first FFT')
    pylab.show()
    pylab.clf()

    f = ifft(f)
    pylab.plot(x, abs(f))
    pylab.title('After first iFFt')
    pylab.show()
    pylab.clf()
</code>

It seems that the result is a Gaussian, but with the first half of the array
swapped with the second. I tried using this silly fudging function

<code>
def swapaxis(a):
    n = len(a)
    tmp = a.copy()
    tmp[:n/2] = a[n/2:]
    tmp[n/2:] = a[:n/2]
    return tmp
</code>

on the result of the fft and, indeed, I got a Gaussian as expected. But,
this does not seem legitimate. Can anyone help?

Thanks in advance.

-- 
Michael S. Duffy
University of Florida
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20060706/7eb98c70/attachment.html>


More information about the SciPy-User mailing list