[Tutor] fourier transform
Jeff Peery
jeffpeery at yahoo.com
Wed Aug 3 02:03:10 CEST 2005
Hi Christian,
sorry for the lack of detail. how about I use a sine wave because I know what the output should look like - amplitude of one at frequency equal to the frequency of the sine wave.
one period of a sin wave that cycles at one hertz:
period = 1
input = sin(arange(0,64)*3.14159*2/64.0)
do the fft:
myFFT = FFT.real_fft(myData)
the change in time between elements is:
delta_time = period/64
inverse of time is the frequency:
delta_freq = 1/delta_time
print the results:
for i in range(1,len(myFFT)):
print myFFT[i], delta_freq*i
hope this is more clear. from the output I would expect that two spikes appear with amplitude = 1. one spike is the positive frequency (first half of the fft) and another spike is the negative frequency (second half), the first half and second half are symmetrical about the midpoint of the fft. but this is what I get:
-8.22612478587e-005 64.0
2.65354186171e-006 128.0
2.65357174311e-006 192.0
2.65358011376e-006 256.0
2.65358370024e-006 320.0
2.65358557785e-006 384.0
2.65358668451e-006 448.0
2.65358739808e-006 512.0
2.65358788076e-006 576.0
2.65358822231e-006 640.0
.
.
.
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.
Jeff
Christian Meesters <meesters at uni-mainz.de> wrote:
Hi
Pawel Kraszewski wrote:
> 4. The answer is symmetrical - usually you take only half of it. I
> don't
> remember the exact difference between the halves, but you may find it
> in any
> article on FFT.
The real part is identical the imaginary part has the opposite sign
("same amplitude, opposite phase").
Jeff Peery wrote:
> thanks for the help. I think I'm understanding this a bit better.
> although I still don't completely understand the output. here is an
> example... for the input I have 1024 samples taken from a 1 Hz square
> wave with amplitude = 1. for the output I would expect an infinite
> number of frequencies. the output from FFT.fft(myData).real is this:
>
> .
> .
> .
> -0.498 1
> 0.0 2
> -0.498 3
> 0.0 4
> -0.498 5
> 0.0 6
> -0.498 7
> 0.0 8
Frankly, I don't understand this. After your description I thought your
input is like "array([0, 1, 0, ..., 1, 0, 1])". But this can't be.
Could you show us how exactly your input array looks like?
And how do we have to read your output? Is this a 1d-array? What do the
two numbers per line mean?
Cheers
Christian
PS Sorry for the late reply.
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050802/911477e9/attachment.htm
More information about the Tutor
mailing list