# [Tutor] fourier transform

Christian Meesters meesters at uni-mainz.de
Wed Aug 3 14:49:37 CEST 2005

```Hi Jeff,

On 3 Aug 2005, at 02:03, Jeff Peery wrote:
> hope this is more clear. from the output I would expect that two
> spikes appear with amplitude = 1.
[snip]
> I don't understand the output amplitudes. they should all be zero
> except for at one herz it should be one. not sure about the frequency
> for that matter either. I gotta dig up my math book and figure this
> out. in the meantime any suggestions for what this is outputing would
> be greatly appreciated! thanks.
>

Yes, well, the math book idea might be a good one ;-). No, but
seriously: You are just making a little mistake. First of all you are
NOT exactly calculating a Fourier transform but a numerical estimation
of it (you are dealing with an array of discrete data points, which is
unavoidable when dealing with computers ;-)). Look on your sine wave.
Is it a perfect one? Then, what do you see when you plot your data?
Some 'noise' and one little peak. The noise is due to errors which have
to do with floating point arithmetics (see
http://docs.python.org/tut/node16.html). It's really small and in most
cases I'm sure it's neglectable as well.
But when looking on your idea of what you would expect, I'm wondering
whether you actually want a power spectrum estimation (see
http://mathworld.wolfram.com/PowerSpectrum.html)? Try

myFFT = abs(fft.fft(inp))

myFFT = fft.real_fft(inp)

This a least might come close to what I think you want to see, right?

You might have a look on

myFFt = fft.fft(inp).real

as well, because it might make things to appear a little clearer.

One more remark: Try to avoid overwriting python key words like 'input'.

Hope this helped.

Cheers
Christian

PS Here is the code I used. It looks a bit different from yours - I
hope the comments help a bit:

from numarray import *
import numarray.fft as fft

#at least one of the numbers should be floating point here
period = 1.0
#use numarray's / Numpy's pi instead of 3.14...
inp = sin(arange(0,64)*pi*2/64.0)

myFFT = abs(fft.fft(inp))
#or
#myFFt = fft.fft(inp).real
#or
#myFFT = fft.real_fft(inp)
#depending on what you really want
dtime = period/64.0

dfreq = 1.0/dtime

for i in range(len(myFFT)):
print myFFT[i], dfreq*i

```