def _condition_inputs(data, kernel): data, kernel = num.asarray(data), num.asarray(kernel) if data.rank == 0: data.shape = (1, ) if kernel.rank == 0: kernel.shape = (1, ) if data.rank > 1 or kernel.rank > 1: raise ValueError("arrays must be 1D") if len(data) < len(kernel): data, kernel = kernel, data return data, kernel
def _condition_inputs(data, kernel): data, kernel = num.asarray(data), num.asarray(kernel) if data.rank == 0: data.shape = (1,) if kernel.rank == 0: kernel.shape = (1,) if data.rank > 1 or kernel.rank > 1: raise ValueError("arrays must be 1D") if len(data) < len(kernel): data, kernel = kernel, data return data, kernel
def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti, work_function=fftpack.cfftf, fft_cache=_fft_cache): a = num.asarray(a) if n == None: n = a.getshape()[axis] wsave = init_function(n) if a.getshape()[axis] != n: s = list(a.getshape()) if s[axis] > n: index = [slice(None)] * len(s) index[axis] = slice(0, n) a = a[index] else: index = [slice(None)] * len(s) index[axis] = slice(0, s[axis]) s[axis] = n z = num.zeros(s, a.type()) z[index] = a a = z if axis != -1: a = num.swapaxes(a, axis, -1) # print work_function, a r = work_function(a, wsave) if axis != -1: r = num.swapaxes(r, axis, -1) return r
def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti, work_function=fftpack.cfftf, fft_cache = _fft_cache ): a = num.asarray(a) if n == None: n = a.getshape()[axis] wsave = init_function(n) if a.getshape()[axis] != n: s = list(a.getshape()) if s[axis] > n: index = [slice(None)]*len(s) index[axis] = slice(0,n) a = a[index] else: index = [slice(None)]*len(s) index[axis] = slice(0,s[axis]) s[axis] = n z = num.zeros(s, a.type()) z[index] = a a = z if axis != -1: a = num.swapaxes(a, axis, -1) # print work_function, a r = work_function(a, wsave) if axis != -1: r = num.swapaxes(r, axis, -1) return r
def _raw_fftnd(a, s=None, axes=None, function=fft): a = num.asarray(a) s, axes = _cook_nd_args(a, s, axes) itl = range(len(axes)) itl.reverse() for ii in itl: a = function(a, n=s[ii], axis=axes[ii]) return a
def _raw_fftnd(a, s=None, axes=None, function=fft): a = num.asarray(a) s, axes = _cook_nd_args(a, s, axes) itl = range(len(axes)) itl.reverse() for ii in itl: a = function(a, n=s[ii], axis=axes[ii]) return a
def real_fftnd(a, s=None, axes=None): """real_fftnd(a, s=None, axes=None) The n-dimensional discrete Fourier transform of a real array a. A real transform as real_fft is performed along the axis specified by the last element of axes, then complex transforms as fft are performed along the other axes.""" a = num.asarray(a).astype(num.Float) s, axes = _cook_nd_args(a, s, axes) a = real_fft(a, s[-1], axes[-1]) for ii in range(len(axes)-1): a = fft(a, s[ii], axes[ii]) return a
def real_fftnd(a, s=None, axes=None): """real_fftnd(a, s=None, axes=None) The n-dimensional discrete Fourier transform of a real array a. A real transform as real_fft is performed along the axis specified by the last element of axes, then complex transforms as fft are performed along the other axes.""" a = num.asarray(a).astype(num.Float) s, axes = _cook_nd_args(a, s, axes) a = real_fft(a, s[-1], axes[-1]) for ii in range(len(axes) - 1): a = fft(a, s[ii], axes[ii]) return a
def inverse_real_fftnd(a, s=None, axes=None): """inverse_real_fftnd(a, s=None, axes=None) The inverse of real_fftnd. The transform implemented in inverse_fft is applied along all axes but the last, then the transform implemented in inverse_real_fft is performed along the last axis. As with inverse_real_fft, the length of the result along that axis must be specified if it is to be odd.""" a = num.asarray(a).astype(num.Complex) s, axes = _cook_nd_args(a, s, axes, invreal=1) for ii in range(len(axes) - 1): a = inverse_fft(a, s[ii], axes[ii]) a = inverse_real_fft(a, s[-1], axes[-1]) return a
def inverse_real_fftnd(a, s=None, axes=None): """inverse_real_fftnd(a, s=None, axes=None) The inverse of real_fftnd. The transform implemented in inverse_fft is applied along all axes but the last, then the transform implemented in inverse_real_fft is performed along the last axis. As with inverse_real_fft, the length of the result along that axis must be specified if it is to be odd.""" a = num.asarray(a).astype(num.Complex) s, axes = _cook_nd_args(a, s, axes, invreal=1) for ii in range(len(axes)-1): a = inverse_fft(a, s[ii], axes[ii]) a = inverse_real_fft(a, s[-1], axes[-1]) return a
def inverse_hermite_fft(a, n=None, axis=-1): """hermite_fft(a, n=None, axis=-1) inverse_hermite_fft(a, n=None, axis=-1) These are a pair analogous to real_fft/inverse_real_fft, but for the opposite case: here the signal is real in the frequency domain and has Hermite symmetry in the time domain. So here it's hermite_fft for which you must supply the length of the result if it is to be odd. inverse_hermite_fft(hermite_fft(a), len(a)) == a within numerical accuracy.""" a = num.asarray(a).astype(num.Float) if n == None: n = num.shape(a)[axis] return num.conjugate(real_fft(a, n, axis)) / n
def inverse_hermite_fft(a, n=None, axis=-1): """hermite_fft(a, n=None, axis=-1) inverse_hermite_fft(a, n=None, axis=-1) These are a pair analogous to real_fft/inverse_real_fft, but for the opposite case: here the signal is real in the frequency domain and has Hermite symmetry in the time domain. So here it's hermite_fft for which you must supply the length of the result if it is to be odd. inverse_hermite_fft(hermite_fft(a), len(a)) == a within numerical accuracy.""" a = num.asarray(a).astype(num.Float) if n == None: n = num.shape(a)[axis] return num.conjugate(real_fft(a, n, axis))/n
def real_fft(a, n=None, axis=-1): """real_fft(a, n=None, axis=-1) Will return the n point discrete Fourier transform of the real valued array a. n defaults to the length of a. n is the length of the input, not the output. The returned array will be the nonnegative frequency terms of the Hermite-symmetric, complex transform of the real array. So for an 8-point transform, the frequencies in the result are [ 0, 1, 2, 3, 4]. The first term will be real, as will the last if n is even. The negative frequency terms are not needed because they are the complex conjugates of the positive frequency terms. (This is what I mean when I say Hermite-symmetric.) This is most efficient for n a power of two.""" a = num.asarray(a).astype(num.Float) return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftf, _real_fft_cache)
def real_fft(a, n=None, axis=-1): """real_fft(a, n=None, axis=-1) Will return the n point discrete Fourier transform of the real valued array a. n defaults to the length of a. n is the length of the input, not the output. The returned array will be the nonnegative frequency terms of the Hermite-symmetric, complex transform of the real array. So for an 8-point transform, the frequencies in the result are [ 0, 1, 2, 3, 4]. The first term will be real, as will the last if n is even. The negative frequency terms are not needed because they are the complex conjugates of the positive frequency terms. (This is what I mean when I say Hermite-symmetric.) This is most efficient for n a power of two.""" a = num.asarray(a).astype(num.Float) return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftf, _real_fft_cache)
def inverse_real_fft(a, n=None, axis=-1): """inverse_real_fft(a, n=None, axis=-1) Will return the real valued n point inverse discrete Fourier transform of a, where a contains the nonnegative frequency terms of a Hermite-symmetric sequence. n is the length of the result, not the input. If n is not supplied, the default is 2*(len(a)-1). If you want the length of the result to be odd, you have to say so. If you specify an n such that a must be zero-padded or truncated, the extra/removed values will be added/removed at high frequencies. One can thus resample a series to m points via Fourier interpolation by: a_resamp = inverse_real_fft(real_fft(a), m). This is the inverse of real_fft: inverse_real_fft(real_fft(a), len(a)) == a within numerical accuracy.""" a = num.asarray(a).astype(num.Complex) if n == None: n = (num.shape(a)[axis] - 1) * 2 return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb, _real_fft_cache) / n
def inverse_fft(a, n=None, axis=-1): """inverse_fft(a, n=None, axis=-1) Will return the n point inverse discrete Fourier transform of a. n defaults to the length of a. If n is larger than a, then a will be zero-padded to make up the difference. If n is smaller than a, then a will be truncated to reduce its size. The input array is expected to be packed the same way as the output of fft, as discussed in it's documentation. This is the inverse of fft: inverse_fft(fft(a)) == a within numerical accuracy. This is most efficient for n a power of two. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's.""" a = num.asarray(a).astype(num.Complex) if n == None: n = num.shape(a)[axis] return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n
def inverse_fft(a, n=None, axis=-1): """inverse_fft(a, n=None, axis=-1) Will return the n point inverse discrete Fourier transform of a. n defaults to the length of a. If n is larger than a, then a will be zero-padded to make up the difference. If n is smaller than a, then a will be truncated to reduce its size. The input array is expected to be packed the same way as the output of fft, as discussed in it's documentation. This is the inverse of fft: inverse_fft(fft(a)) == a within numerical accuracy. This is most efficient for n a power of two. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's.""" a = num.asarray(a).astype(num.Complex) if n == None: n = num.shape(a)[axis] return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftb, _fft_cache) / n
def inverse_real_fft(a, n=None, axis=-1): """inverse_real_fft(a, n=None, axis=-1) Will return the real valued n point inverse discrete Fourier transform of a, where a contains the nonnegative frequency terms of a Hermite-symmetric sequence. n is the length of the result, not the input. If n is not supplied, the default is 2*(len(a)-1). If you want the length of the result to be odd, you have to say so. If you specify an n such that a must be zero-padded or truncated, the extra/removed values will be added/removed at high frequencies. One can thus resample a series to m points via Fourier interpolation by: a_resamp = inverse_real_fft(real_fft(a), m). This is the inverse of real_fft: inverse_real_fft(real_fft(a), len(a)) == a within numerical accuracy.""" a = num.asarray(a).astype(num.Complex) if n == None: n = (num.shape(a)[axis] - 1) * 2 return _raw_fft(a, n, axis, fftpack.rffti, fftpack.rfftb, _real_fft_cache) / n
def shape(a): a = num.asarray(a) return a.getshape()
def shape(a): a = num.asarray(a) return a.getshape()