Skip to content
This repository
Newer
Older
100644 584 lines (455 sloc) 17.787 kb
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
1 """
ebea7bf2 »
2006-03-14 Run reindent.py (script distributed with Python) over the source to r…
2 Discrete Fourier Transforms - basic.py
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
3 """
4 # Created by Pearu Peterson, August,September 2002
5
6 __all__ = ['fft','ifft','fftn','ifftn','rfft','irfft',
5ae4f263 »
2010-09-12 3K: fftpack: fix integer division in rfftfreq, and remove its duplica…
7 'fft2','ifft2']
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
8
2221e50e »
2010-11-20 ENH: fftpack: update 'raise' statements (and remove unused imports)
9 from numpy import zeros, swapaxes
0e1578a0 »
2006-06-22 Replace uses of oldnumeric API and typecodes in fftpack
10 import numpy
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
11 import _fftpack
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
12
13 import atexit
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
14 atexit.register(_fftpack.destroy_zfft_cache)
15 atexit.register(_fftpack.destroy_zfftnd_cache)
16 atexit.register(_fftpack.destroy_drfft_cache)
17 atexit.register(_fftpack.destroy_cfft_cache)
18 atexit.register(_fftpack.destroy_cfftnd_cache)
19 atexit.register(_fftpack.destroy_rfft_cache)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
20 del atexit
21
0e1578a0 »
2006-06-22 Replace uses of oldnumeric API and typecodes in fftpack
22 def istype(arr, typeclass):
23 return issubclass(arr.dtype.type, typeclass)
24
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
25 def _datacopied(arr, original):
26 """
27 Strict check for `arr` not sharing any data with `original`,
28 under the assumption that arr = asarray(original)
29
30 """
31 if arr is original:
32 return False
33 if not isinstance(original, numpy.ndarray) and hasattr(original, '__array__'):
34 return False
35 return arr.base is None
36
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
37 # XXX: single precision FFTs partially disabled due to accuracy issues
38 # for large prime-sized inputs.
39 #
40 # See http://permalink.gmane.org/gmane.comp.python.scientific.devel/13834
41 # ("fftpack test failures for 0.8.0b1", Ralf Gommers, 17 Jun 2010,
42 # @ scipy-dev)
43 #
44 # These should be re-enabled once the problems are resolved
45
46 def _is_safe_size(n):
47 """
48 Is the size of FFT such that FFTPACK can handle it in single precision
49 with sufficient accuracy?
50
51 Composite numbers of 2, 3, and 5 are accepted, as FFTPACK has those
52 """
53 n = int(n)
54 for c in (2, 3, 5):
55 while n % c == 0:
56 n /= c
57 return (n <= 1)
58
59 def _fake_crfft(x, n, *a, **kw):
60 if _is_safe_size(n):
61 return _fftpack.crfft(x, n, *a, **kw)
62 else:
63 return _fftpack.zrfft(x, n, *a, **kw).astype(numpy.complex64)
64
65 def _fake_cfft(x, n, *a, **kw):
66 if _is_safe_size(n):
67 return _fftpack.cfft(x, n, *a, **kw)
68 else:
69 return _fftpack.zfft(x, n, *a, **kw).astype(numpy.complex64)
70
71 def _fake_rfft(x, n, *a, **kw):
72 if _is_safe_size(n):
73 return _fftpack.rfft(x, n, *a, **kw)
74 else:
75 return _fftpack.drfft(x, n, *a, **kw).astype(numpy.float32)
76
77 def _fake_cfftnd(x, shape, *a, **kw):
78 if numpy.all(map(_is_safe_size, shape)):
79 return _fftpack.cfftnd(x, shape, *a, **kw)
80 else:
81 return _fftpack.zfftnd(x, shape, *a, **kw).astype(numpy.complex64)
82
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
83 _DTYPE_TO_FFT = {
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
84 # numpy.dtype(numpy.float32): _fftpack.crfft,
85 numpy.dtype(numpy.float32): _fake_crfft,
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
86 numpy.dtype(numpy.float64): _fftpack.zrfft,
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
87 # numpy.dtype(numpy.complex64): _fftpack.cfft,
88 numpy.dtype(numpy.complex64): _fake_cfft,
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
89 numpy.dtype(numpy.complex128): _fftpack.zfft,
90 }
91
92 _DTYPE_TO_RFFT = {
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
93 # numpy.dtype(numpy.float32): _fftpack.rfft,
94 numpy.dtype(numpy.float32): _fake_rfft,
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
95 numpy.dtype(numpy.float64): _fftpack.drfft,
96 }
97
98 _DTYPE_TO_FFTN = {
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
99 # numpy.dtype(numpy.complex64): _fftpack.cfftnd,
100 numpy.dtype(numpy.complex64): _fake_cfftnd,
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
101 numpy.dtype(numpy.complex128): _fftpack.zfftnd,
8e80796c »
2010-09-26 BUG: fftpack: use single-precision FFT implementation only for "easy"…
102 # numpy.dtype(numpy.float32): _fftpack.cfftnd,
103 numpy.dtype(numpy.float32): _fake_cfftnd,
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
104 numpy.dtype(numpy.float64): _fftpack.zfftnd,
105 }
106
107 def _asfarray(x):
108 """Like numpy asfarray, except that it does not modify x dtype if x is
109 already an array with a float dtype, and do not cast complex types to
110 real."""
111 if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]:
112 return x
113 else:
114 # We cannot use asfarray directly because it converts sequences of
115 # complex to sequence of real
116 ret = numpy.asarray(x)
117 if not ret.dtype.char in numpy.typecodes["AllFloat"]:
118 return numpy.asfarray(x)
119 return ret
120
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
121 def _fix_shape(x, n, axis):
122 """ Internal auxiliary function for _raw_fft, _raw_fftnd."""
123 s = list(x.shape)
124 if s[axis] > n:
125 index = [slice(None)]*len(s)
126 index[axis] = slice(0,n)
127 x = x[index]
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
128 return x, False
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
129 else:
130 index = [slice(None)]*len(s)
131 index[axis] = slice(0,s[axis])
132 s[axis] = n
cbf1bb2b »
2006-01-15 Updated to use .dtype.char
133 z = zeros(s,x.dtype.char)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
134 z[index] = x
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
135 return z, True
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
136
137
138 def _raw_fft(x, n, axis, direction, overwrite_x, work_function):
139 """ Internal auxiliary function for fft, ifft, rfft, irfft."""
140 if n is None:
141 n = x.shape[axis]
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
142 elif n != x.shape[axis]:
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
143 x, copy_made = _fix_shape(x,n,axis)
144 overwrite_x = overwrite_x or copy_made
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
145 if axis == -1 or axis == len(x.shape)-1:
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
146 r = work_function(x,n,direction,overwrite_x=overwrite_x)
147 else:
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
148 x = swapaxes(x, axis, -1)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
149 r = work_function(x,n,direction,overwrite_x=overwrite_x)
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
150 r = swapaxes(r, axis, -1)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
151 return r
152
153
154 def fft(x, n=None, axis=-1, overwrite_x=0):
066f6fa4 »
2008-12-30 Merge from doc wiki
155 """
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
156 Return discrete Fourier transform of real or complex sequence.
157
158 The returned complex array contains ``y(0), y(1),..., y(n-1)`` where
159
160 ``y(j) = (x * exp(-2*pi*sqrt(-1)*j*np.arange(n)/n)).sum()``.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
161
066f6fa4 »
2008-12-30 Merge from doc wiki
162 Parameters
163 ----------
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
164 x : array_like
165 Array to Fourier transform.
066f6fa4 »
2008-12-30 Merge from doc wiki
166 n : int, optional
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
167 Length of the Fourier transform. If ``n < x.shape[axis]``, `x` is
168 truncated. If ``n > x.shape[axis]``, `x` is zero-padded. The
169 default results in ``n = x.shape[axis]``.
066f6fa4 »
2008-12-30 Merge from doc wiki
170 axis : int, optional
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
171 Axis along which the fft's are computed; the default is over the
172 last axis (i.e., ``axis=-1``).
066f6fa4 »
2008-12-30 Merge from doc wiki
173 overwrite_x : bool, optional
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
174 If True the contents of `x` can be destroyed; the default is False.
066f6fa4 »
2008-12-30 Merge from doc wiki
175
176 Returns
177 -------
178 z : complex ndarray
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
179 with the elements::
180
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
181 [y(0),y(1),..,y(n/2),y(1-n/2),...,y(-1)] if n is even
066f6fa4 »
2008-12-30 Merge from doc wiki
182 [y(0),y(1),..,y((n-1)/2),y(-(n-1)/2),...,y(-1)] if n is odd
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
183
184 where::
185
066f6fa4 »
2008-12-30 Merge from doc wiki
186 y(j) = sum[k=0..n-1] x[k] * exp(-sqrt(-1)*j*k* 2*pi/n), j = 0..n-1
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
187
188 Note that ``y(-j) = y(n-j).conjugate()``.
066f6fa4 »
2008-12-30 Merge from doc wiki
189
190 See Also
191 --------
192 ifft : Inverse FFT
193 rfft : FFT of a real sequence
194
195 Notes
196 -----
197 The packing of the result is "standard": If A = fft(a, n), then A[0]
198 contains the zero-frequency term, A[1:n/2+1] contains the
199 positive-frequency terms, and A[n/2+1:] contains the negative-frequency
200 terms, in order of decreasingly negative frequency. So for an 8-point
201 transform, the frequencies of the result are [ 0, 1, 2, 3, 4, -3, -2, -1].
202
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
203 For n even, A[n/2] contains the sum of the positive and negative-frequency
204 terms. For n even and x real, A[n/2] will always be real.
205
066f6fa4 »
2008-12-30 Merge from doc wiki
206 This is most efficient for n a power of two.
207
208 Examples
209 --------
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
210 >>> from scipy.fftpack import fft, ifft
066f6fa4 »
2008-12-30 Merge from doc wiki
211 >>> x = np.arange(5)
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
212 >>> np.allclose(fft(ifft(x)), x, atol=1e-15) #within numerical accuracy.
066f6fa4 »
2008-12-30 Merge from doc wiki
213 True
214
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
215 """
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
216 tmp = _asfarray(x)
217
218 try:
219 work_function = _DTYPE_TO_FFT[tmp.dtype]
220 except KeyError:
221 raise ValueError("type %s is not supported" % tmp.dtype)
222
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
223 if not (istype(tmp, numpy.complex64) or istype(tmp, numpy.complex128)):
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
224 overwrite_x = 1
225
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
226 overwrite_x = overwrite_x or _datacopied(tmp, x)
227
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
228 if n is None:
229 n = tmp.shape[axis]
230 elif n != tmp.shape[axis]:
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
231 tmp, copy_made = _fix_shape(tmp,n,axis)
232 overwrite_x = overwrite_x or copy_made
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
233
234 if axis == -1 or axis == len(tmp.shape) - 1:
235 return work_function(tmp,n,1,0,overwrite_x)
236
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
237 tmp = swapaxes(tmp, axis, -1)
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
238 tmp = work_function(tmp,n,1,0,overwrite_x)
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
239 return swapaxes(tmp, axis, -1)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
240
241 def ifft(x, n=None, axis=-1, overwrite_x=0):
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
242 """
243 Return discrete inverse Fourier transform of real or complex sequence.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
244
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
245 The returned complex array contains ``y(0), y(1),..., y(n-1)`` where
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
246
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
247 ``y(j) = (x * exp(2*pi*sqrt(-1)*j*np.arange(n)/n)).mean()``.
248
249 Parameters
250 ----------
251 x : array_like
252 Transformed data to invert.
253 n : int, optional
254 Length of the inverse Fourier transform. If ``n < x.shape[axis]``,
255 `x` is truncated. If ``n > x.shape[axis]``, `x` is zero-padded.
256 The default results in ``n = x.shape[axis]``.
257 axis : int, optional
258 Axis along which the ifft's are computed; the default is over the
259 last axis (i.e., ``axis=-1``).
260 overwrite_x : bool, optional
261 If True the contents of `x` can be destroyed; the default is False.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
262
263 """
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
264 tmp = _asfarray(x)
265
266 try:
267 work_function = _DTYPE_TO_FFT[tmp.dtype]
268 except KeyError:
269 raise ValueError("type %s is not supported" % tmp.dtype)
270
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
271 if not (istype(tmp, numpy.complex64) or istype(tmp, numpy.complex128)):
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
272 overwrite_x = 1
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
273
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
274 overwrite_x = overwrite_x or _datacopied(tmp, x)
275
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
276 if n is None:
277 n = tmp.shape[axis]
278 elif n != tmp.shape[axis]:
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
279 tmp, copy_made = _fix_shape(tmp,n,axis)
280 overwrite_x = overwrite_x or copy_made
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
281
282 if axis == -1 or axis == len(tmp.shape) - 1:
283 return work_function(tmp,n,-1,1,overwrite_x)
284
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
285 tmp = swapaxes(tmp, axis, -1)
6c6f1e25 »
2003-03-22 Optimized fftpack.{i,}fft for short vectors. Now fftpack.fft benchmar…
286 tmp = work_function(tmp,n,-1,1,overwrite_x)
93835111 »
2003-12-13 Using faster implementation of Numeric.asarray. Clean ups and importi…
287 return swapaxes(tmp, axis, -1)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
288
289
290 def rfft(x, n=None, axis=-1, overwrite_x=0):
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
291 """
292 Discrete Fourier transform of a real sequence.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
293
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
294 The returned real arrays contains::
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
295
296 [y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2))] if n is even
297 [y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2)),Im(y(n/2))] if n is odd
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
298
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
299 where
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
300 ::
301
302 y(j) = sum[k=0..n-1] x[k] * exp(-sqrt(-1)*j*k*2*pi/n)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
303 j = 0..n-1
304
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
305 Note that ``y(-j) == y(n-j).conjugate()``.
306
307 Parameters
308 ----------
309 x : array_like, real-valued
310 The data to tranform.
311 n : int, optional
312 Defines the length of the Fourier transform. If `n` is not specified
313 (the default) then ``n = x.shape[axis]``. If ``n < x.shape[axis]``,
314 `x` is truncated, if ``n > x.shape[axis]``, `x` is zero-padded.
315 axis : int, optional
316 The axis along which the transform is applied. The default is the
317 last axis.
318 overwrite_x : bool, optional
319 If set to true, the contents of `x` can be overwritten. Default is
320 False.
321
322 See also
323 --------
324 fft, irfft, scipy.fftpack.basic
325
326 Notes
327 -----
328 Within numerical accuracy, ``y == rfft(irfft(y))``.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
329
330 """
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
331 tmp = _asfarray(x)
332
0e1578a0 »
2006-06-22 Replace uses of oldnumeric API and typecodes in fftpack
333 if not numpy.isrealobj(tmp):
2221e50e »
2010-11-20 ENH: fftpack: update 'raise' statements (and remove unused imports)
334 raise TypeError("1st argument must be real sequence")
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
335
336 try:
337 work_function = _DTYPE_TO_RFFT[tmp.dtype]
338 except KeyError:
339 raise ValueError("type %s is not supported" % tmp.dtype)
340
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
341 overwrite_x = overwrite_x or _datacopied(tmp, x)
342
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
343 return _raw_fft(tmp,n,axis,1,overwrite_x,work_function)
344
b92e2bc6 »
2005-10-07 Fixes to optimize and fftpack
345
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
346 def irfft(x, n=None, axis=-1, overwrite_x=0):
0f179f03 »
2012-06-04 DOC: fix more doc wiki edits.
347 """
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
348 Return inverse discrete Fourier transform of real sequence x.
0f179f03 »
2012-06-04 DOC: fix more doc wiki edits.
349
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
350 The contents of x is interpreted as the output of the ``rfft(..)``
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
351 function.
352
0f179f03 »
2012-06-04 DOC: fix more doc wiki edits.
353 Parameters
354 ----------
355 x : array_like
356 Transformed data to invert.
357 n : int, optional
358 Length of the inverse Fourier transform.
359 If n < x.shape[axis], x is truncated.
360 If n > x.shape[axis], x is zero-padded.
361 The default results in n = x.shape[axis].
362 axis : int, optional
363 Axis along which the ifft's are computed; the default is over
364 the last axis (i.e., axis=-1).
365 overwrite_x : bool, optional
366 If True the contents of `x` can be destroyed; the default is False.
367
368 Returns
369 -------
370 irfft : ndarray of floats
371 The inverse discrete Fourier transform.
372
373 See Also
374 --------
375 rfft, ifft
376
377 Notes
378 -----
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
379 The returned real array contains::
380
381 [y(0),y(1),...,y(n-1)]
382
383 where for n is even::
384
385 y(j) = 1/n (sum[k=1..n/2-1] (x[2*k-1]+sqrt(-1)*x[2*k])
386 * exp(sqrt(-1)*j*k* 2*pi/n)
387 + c.c. + x[0] + (-1)**(j) x[n-1])
388
389 and for n is odd::
390
391 y(j) = 1/n (sum[k=1..(n-1)/2] (x[2*k-1]+sqrt(-1)*x[2*k])
392 * exp(sqrt(-1)*j*k* 2*pi/n)
393 + c.c. + x[0])
394
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
395 c.c. denotes complex conjugate of preceeding expression.
396
5c4c8ea8 »
2012-04-22 DOC: fix more Sphinx issues. Also complete fftpack.tilbert docstring.
397 For details on input parameters, see `rfft`.
398
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
399 """
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
400 tmp = _asfarray(x)
0e1578a0 »
2006-06-22 Replace uses of oldnumeric API and typecodes in fftpack
401 if not numpy.isrealobj(tmp):
2221e50e »
2010-11-20 ENH: fftpack: update 'raise' statements (and remove unused imports)
402 raise TypeError("1st argument must be real sequence")
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
403
404 try:
405 work_function = _DTYPE_TO_RFFT[tmp.dtype]
406 except KeyError:
407 raise ValueError("type %s is not supported" % tmp.dtype)
408
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
409 overwrite_x = overwrite_x or _datacopied(tmp, x)
410
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
411 return _raw_fft(tmp,n,axis,-1,overwrite_x,work_function)
412
413 def _raw_fftnd(x, s, axes, direction, overwrite_x, work_function):
414 """ Internal auxiliary function for fftnd, ifftnd."""
415 if s is None:
ca178d9d »
2008-07-02 Forbid shape and axes to be of different lengths for fftn.
416 if axes is None:
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
417 s = x.shape
418 else:
419 s = numpy.take(x.shape, axes)
e7710193 »
2008-07-01 Raise a proper exception instead of assertion when s argument shape i…
420
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
421 s = tuple(s)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
422 if axes is None:
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
423 noaxes = True
424 axes = range(-x.ndim, 0)
425 else:
426 noaxes = False
427 if len(axes) != len(s):
428 raise ValueError("when given, axes and shape arguments "\
429 "have to be of the same length")
430
a01c2777 »
2008-11-02 ran reindent
431 # No need to swap axes, array is in C order
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
432 if noaxes:
433 for i in axes:
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
434 x, copy_made = _fix_shape(x, s[i], i)
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
435 overwrite_x = overwrite_x or copy_made
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
436 return work_function(x,s,direction,overwrite_x=overwrite_x)
437
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
438 # We ordered axes, because the code below to push axes at the end of the
439 # array assumes axes argument is in ascending order.
440 id = numpy.argsort(axes)
441 axes = [axes[i] for i in id]
442 s = [s[i] for i in id]
443
444 # Swap the request axes, last first (i.e. First swap the axis which ends up
445 # at -1, then at -2, etc...), such as the request axes on which the
446 # operation is carried become the last ones
447 for i in range(1, len(axes)+1):
448 x = numpy.swapaxes(x, axes[-i], -i)
449
450 # We can now operate on the axes waxes, the p last axes (p = len(axes)), by
451 # fixing the shape of the input array to 1 for any axis the fft is not
452 # carried upon.
453 waxes = range(x.ndim - len(axes), x.ndim)
454 shape = numpy.ones(x.ndim)
455 shape[waxes] = s
456
457 for i in range(len(waxes)):
3ea20167 »
2011-01-31 BUG: fftpack: fix data overwriting in FFT routines (#1353)
458 x, copy_made = _fix_shape(x, s[i], waxes[i])
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
459 overwrite_x = overwrite_x or copy_made
9d76d60a »
2008-11-02 BUG: Refactor fftn axes/shape handling, fix problem similar to #244 w…
460
461 r = work_function(x, shape, direction, overwrite_x=overwrite_x)
462
463 # reswap in the reverse order (first axis first, etc...) to get original
464 # order
465 for i in range(len(axes), 0, -1):
466 r = numpy.swapaxes(r, -i, axes[-i])
467
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
468 return r
469
470
471 def fftn(x, shape=None, axes=None, overwrite_x=0):
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
472 """
473 Return multi-dimensional discrete Fourier transform of x.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
474
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
475 The returned array contains::
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
476
477 y[j_1,..,j_d] = sum[k_1=0..n_1-1, ..., k_d=0..n_d-1]
478 x[k_1,..,k_d] * prod[i=1..d] exp(-sqrt(-1)*2*pi/n_i * j_i * k_i)
479
480 where d = len(x.shape) and n = x.shape.
b853c347 »
2011-08-22 DOC: merge doc wiki edits. Thanks to everyone who contributed.
481 Note that ``y[..., -j_i, ...] = y[..., n_i-j_i, ...].conjugate()``.
482
483 Parameters
484 ----------
485 x : array_like
486 The (n-dimensional) array to transform.
487 shape : tuple of ints, optional
488 The shape of the result. If both `shape` and `axes` (see below) are
489 None, `shape` is ``x.shape``; if `shape` is None but `axes` is
490 not None, then `shape` is ``scipy.take(x.shape, axes, axis=0)``.
491 If ``shape[i] > x.shape[i]``, the i-th dimension is padded with zeros.
492 If ``shape[i] < x.shape[i]``, the i-th dimension is truncated to
493 length ``shape[i]``.
494 axes : array_like of ints, optional
495 The axes of `x` (`y` if `shape` is not None) along which the
496 transform is applied.
497 overwrite_x : bool, optional
498 If True, the contents of `x` can be destroyed. Default is False.
499
500 Returns
501 -------
502 y : complex-valued n-dimensional numpy array
503 The (n-dimensional) DFT of the input array.
504
505 See Also
506 --------
507 ifftn
508
509 Examples
510 --------
511 >>> y = (-np.arange(16), 8 - np.arange(16), np.arange(16))
512 >>> np.allclose(y, fftn(ifftn(y)))
513 True
514
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
515 """
1e864660 »
2010-02-10 BUG: fix single precision handling for ifftn.
516 return _raw_fftn_dispatch(x, shape, axes, overwrite_x, 1)
517
518 def _raw_fftn_dispatch(x, shape, axes, overwrite_x, direction):
bdf6d232 »
2010-03-31 BUG: fix long double fft (fix #948)
519 tmp = _asfarray(x)
520
521 try:
522 work_function = _DTYPE_TO_FFTN[tmp.dtype]
523 except KeyError:
524 raise ValueError("type %s is not supported" % tmp.dtype)
525
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
526 if not (istype(tmp, numpy.complex64) or istype(tmp, numpy.complex128)):
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
527 overwrite_x = 1
579b13fb »
2011-01-31 BUG: fftpack: more robust data overwrite behavior
528
529 overwrite_x = overwrite_x or _datacopied(tmp, x)
1e864660 »
2010-02-10 BUG: fix single precision handling for ifftn.
530 return _raw_fftnd(tmp,shape,axes,direction,overwrite_x,work_function)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
531
532
533 def ifftn(x, shape=None, axes=None, overwrite_x=0):
7b6be03d »
2010-05-24 DOC: merge wiki edits - fftpack module.
534 """
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
535 Return inverse multi-dimensional discrete Fourier transform of
536 arbitrary type sequence x.
537
7b6be03d »
2010-05-24 DOC: merge wiki edits - fftpack module.
538 The returned array contains::
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
539
540 y[j_1,..,j_d] = 1/p * sum[k_1=0..n_1-1, ..., k_d=0..n_d-1]
541 x[k_1,..,k_d] * prod[i=1..d] exp(sqrt(-1)*2*pi/n_i * j_i * k_i)
542
7b6be03d »
2010-05-24 DOC: merge wiki edits - fftpack module.
543 where ``d = len(x.shape)``, ``n = x.shape``, and ``p = prod[i=1..d] n_i``.
544
545 For description of parameters see `fftn`.
546
547 See Also
548 --------
549 fftn : for detailed information.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
550
551 """
1e864660 »
2010-02-10 BUG: fix single precision handling for ifftn.
552 return _raw_fftn_dispatch(x, shape, axes, overwrite_x, -1)
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
553
554 def fft2(x, shape=None, axes=(-2,-1), overwrite_x=0):
f5b4d404 »
2009-10-01 updated docstrings from the scipy documentation editor (thanks to eve…
555 """
556 2-D discrete Fourier transform.
ebea7bf2 »
2006-03-14 Run reindent.py (script distributed with Python) over the source to r…
557
f5b4d404 »
2009-10-01 updated docstrings from the scipy documentation editor (thanks to eve…
558 Return the two-dimensional discrete Fourier transform of the 2-D argument
559 `x`.
560
561 See Also
562 --------
563 fftn : for detailed information.
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
564
565 """
566 return fftn(x,shape,axes,overwrite_x)
567
568
569 def ifft2(x, shape=None, axes=(-2,-1), overwrite_x=0):
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
570 """
571 2-D discrete inverse Fourier transform of real or complex sequence.
ebea7bf2 »
2006-03-14 Run reindent.py (script distributed with Python) over the source to r…
572
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
573 Return inverse two-dimensional discrete Fourier transform of
574 arbitrary type sequence x.
575
5005464a »
2010-11-14 DOC: merge wiki edits for fftpack module.
576 See `ifft` for more information.
577
578 See also
579 --------
580 fft2, ifft
581
530a62f6 »
2002-11-15 Replaced fftpack with fftpack2. Now f2py 2.23.190-1367 or newer is re…
582 """
583 return ifftn(x,shape,axes,overwrite_x)
Something went wrong with that request. Please try again.