def fft(t, y, pow2=False, window=None, rescale=False):
<EOL>y = _n.array(y)<EOL>t = _n.array(t)<EOL>if pow2:<EOL><INDENT>keep  = <NUM_LIT:2>**int(_n.log2(len(y)))<EOL>y.resize(keep)<EOL>t.resize(keep)<EOL><DEDENT>if not window in [None, False, <NUM_LIT:0>]:<EOL><INDENT>try:<EOL><INDENT>w = eval("<STR_LIT>"+window, dict(_n=_n))(len(y))<EOL>v0 = _n.average(abs(y)**<NUM_LIT:2>)<EOL>y = y * w<EOL>if rescale: y = y * _n.sqrt(v0 / _n.average(abs(y)**<NUM_LIT:2>))<EOL><DEDENT>except:<EOL><INDENT>print("<STR_LIT>")<EOL>return<EOL><DEDENT><DEDENT>Y = _n.fft.fftshift( _n.fft.fft(y) / len(t) )<EOL>f = _n.fft.fftshift( _n.fft.fftfreq(len(t), t[<NUM_LIT:1>]-t[<NUM_LIT:0>]) )<EOL>return f, Y<EOL>
FFT of y, assuming complex or real-valued inputs. This goes through the 
numpy fourier transform process, assembling and returning (frequencies, 
complex fft) given time and signal data y.

Parameters
----------
t,y
    Time (t) and signal (y) arrays with which to perform the fft. Note the t
    array is assumed to be evenly spaced.

pow2 = False
    Set this to true if you only want to keep the first 2^n data
    points (speeds up the FFT substantially)

window = None
    Can be set to any of the windowing functions in numpy that require only
    the number of points as the argument, e.g. window='hanning'. 

rescale = False
    If True, the FFT will be rescaled by the square root of the ratio of 
    variances before and after windowing, such that the sum of component 
    amplitudes squared is equal to the actual variance.