For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2007 > Re: fft from numerical recipes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: fft from numerical recipes
Steven G. Johnson

2007-04-18, 10:04 pm

On Apr 17, 4:48 pm, heiko liebhart <heiko.liebh...@googlemail.com>
wrote:
> what i got was something like a double gaussian. i.e. the sign was
> alternating. like sign of every second value was inverted oszillating
> from plus to minus.


The problem was that you used the wrong origin. The correct origin
for nearly every FFT implementation is the *first* (zeroth) element of
the array. That is, if you want a Gaussian exp(-an^2), your input
array should be x[0] = 1 and x[n] = x[N-n] = exp(-an^2) for 0 < n <= N/
2. Notice the implicit periodic boundaries. (Shift this by 1 for a 1-
based array in Fortran.)

(Even then, the output will be only approximately Gaussian, because
the FFT is not computing the Fourier transform, it is computing an
approximate Fourier series called the discrete Fourier transform.)

What it sounds like you did was the common error of assuming the
origin was at the center of the array, and so your Gaussian was peaked
at N/2. According to the shift theorem, this causes your output X[k]
to be multiplied by a linear phase exp(2 pi i (N/2) k / N) = (-1)^k,
hence the sign oscillation.

Google for "discrete Fourier transform" (DFT) to look at the
transformation an FFT is actually computing, and think about how it
compares to the Fourier transform you are familiar with.

> in the next step i took a sin wave as input.
> again what i got was not the suspected delta peak at the frequency of
> the oszillation but two antsymmetric peaks in the imaginary part.


Um, even for an analytical Fourier transform, the Fourier transform of
sin(kx) is a sum of two imaginary-amplitude delta functions arranged
antisymmetrically around the origin. The same is true in the discrete
case. It sounds like you have a bit of review to do.

Regards,
Steven G. Johnson

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com