diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-04 23:32:12 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-04 23:32:12 +0000 |
commit | f1cca04886d4f63f7b1ed5b382986af3a9ee6a61 (patch) | |
tree | 053f566b31cb6edc24a41b800ec7f2972c4bca40 /numpy/fft/helper.py | |
parent | 8f26568de7cc97ac0dcedfd5061e08bb54770b61 (diff) | |
download | numpy-f1cca04886d4f63f7b1ed5b382986af3a9ee6a61.tar.gz |
Many name-changes in oldnumeric. This may break some numpy code that was using the oldnumeric interface.
Diffstat (limited to 'numpy/fft/helper.py')
-rw-r--r-- | numpy/fft/helper.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/numpy/fft/helper.py b/numpy/fft/helper.py new file mode 100644 index 000000000..4e1da2abd --- /dev/null +++ b/numpy/fft/helper.py @@ -0,0 +1,66 @@ +""" +Discrete Fourier Transforms - helper.py +""" +# Created by Pearu Peterson, September 2002 + +__all__ = ['fftshift','ifftshift','fftfreq'] + +from numpy.core import asarray, concatenate, arange, take, \ + array, integer +import types + +def fftshift(x,axes=None): + """ fftshift(x, axes=None) -> y + + Shift zero-frequency component to center of spectrum. + + This function swaps half-spaces for all axes listed (defaults to all). + + Notes: + If len(x) is even then the Nyquist component is y[0]. + """ + tmp = asarray(x) + ndim = len(tmp.shape) + if axes is None: + axes = range(ndim) + y = tmp + for k in axes: + n = tmp.shape[k] + p2 = (n+1)/2 + mylist = concatenate((arange(p2,n),arange(p2))) + y = take(y,mylist,k) + return y + + +def ifftshift(x,axes=None): + """ ifftshift(x,axes=None) - > y + + Inverse of fftshift. + """ + tmp = asarray(x) + ndim = len(tmp.shape) + if axes is None: + axes = range(ndim) + y = tmp + for k in axes: + n = tmp.shape[k] + p2 = n-(n+1)/2 + mylist = concatenate((arange(p2,n),arange(p2))) + y = take(y,mylist,k) + return y + +def fftfreq(n,d=1.0): + """ fftfreq(n, d=1.0) -> f + + DFT sample frequencies + + The returned float array contains the frequency bins in + cycles/unit (with zero at the start) given a window length n and a + sample spacing d: + + f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n) if n is even + f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n) if n is odd + """ + assert isinstance(n,types.IntType) or isinstance(n, integer) + k = range(0,(n-1)/2+1)+range(-(n/2),0) + return array(k,'d')/(n*d) |