[SciPy-User] Help with fast fourier transform
Thu Apr 29 20:00:46 CDT 2010
OK there's a number of things going on. First, fft results in a shifted array
(google for fftshift to find out more). Therefore your result should be:
That will centre the result properly. Secondly the width of your resulting
array is a lot smaller than in the desired output (you only cut out the
centre). This is because your stepsize in the stepfunction is too large you
could fix that e.g. by doing f = g(np.arange(0,1000,0.1)). Finally your values
are all positive because you take the absolute value while in the expected result
you do not.
On 04/29/10 11:17, Oscar Gerardo Lazo Arjona wrote:
> Hello! I'm new to this mailing list and to numpy in general.
> I need to calculate fft for my optics class. But I'm having trouble.
> This is the code I'm using (commented):
> import pylab
> import numpy as np
> def g(x):
> if x>450 and x<550:
> return 1
> return 0
> f=[g(x) for x in range(0,1000)]
> #this funtion can be ploted as
> #which is a step function "centered" at 500
> #when calculate the fft of f i get an array of complex numbers
> #whose absolute value can be ploted as
> #But that is not the desired output.
> #Instead of that i expect something that can be ploted like this
> #what i think must be happening because my function f
> #has an offset of 500 (it's supposed to be centereed at 500)
> #So i think it all reduces to two options:
> #somehow telling fft to consider the origin at 500
> #(indicate thetell the offset)
> #Or make fft accept a list of points like
> #so that it can know the position of the step relative to the origin
> Please help!
> SciPy-User mailing list
More information about the SciPy-User