[SciPy-User] Help with fast fourier transform
Charles R Harris
charlesr.harris@gmail....
Thu Apr 29 20:19:01 CDT 2010
On Thu, Apr 29, 2010 at 10:17 AM, Oscar Gerardo Lazo Arjona <
algebraicamente@gmail.com> 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
> else:
> return 0
> f=[g(x) for x in range(0,1000)]
> f=np.array(f)
>
> #this funtion can be ploted as
> #http://i41.tinypic.com/k0shnk.png
> #which is a step function "centered" at 500
>
>
> F=np.fft.fft(f)
> #when calculate the fft of f i get an array of complex numbers
> #whose absolute value can be ploted as
> #http://i40.tinypic.com/1zcecxx.png
>
> #But that is not the desired output.
> #Instead of that i expect something that can be ploted like this
> #http://i39.tinypic.com/1zmch0g.png
>
>
> #what i think must be happening because my function f
> #has an offset of 500 (it's supposed to be centereed at 500)
>
>
Yep. Think of the data points as lying on a circle. You want the function
centered on index 0, so what this will look like is a chunk at the
beginning, a bunch of zeros, and a chunk at the end. Alternatively, you can
phase shift the transform, which in the case where the function is centered
amounts to multiplying all the odd indices by -1. Note that transformed data
will also be split between the two ends of the transform and you will have
to paste the right end before the left end to get the sinc-like plot. In any
case the result will not be centered.
#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
> #[[-2,0],[-1,1],[0,1],[1,1],[2,0]]
> #so that it can know the position of the step relative to the origin
>
>
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100429/253b2f8b/attachment.html
More information about the SciPy-User
mailing list