我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用numpy.fft.ifftshift()。
def test_definition(self): x = [0, 1, 2, 3, 4, -4, -3, -2, -1] y = [-4, -3, -2, -1, 0, 1, 2, 3, 4] assert_array_almost_equal(fft.fftshift(x), y) assert_array_almost_equal(fft.ifftshift(y), x) x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1] y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] assert_array_almost_equal(fft.fftshift(x), y) assert_array_almost_equal(fft.ifftshift(y), x)
def test_inverse(self): for n in [1, 4, 9, 100, 211]: x = np.random.random((n,)) assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x)
def test_axes_keyword(self): freqs = [[0, 1, 2], [3, 4, -4], [-3, -2, -1]] shifted = [[-1, -3, -2], [2, 0, 1], [-4, 3, 4]] assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted) assert_array_almost_equal(fft.fftshift(freqs, axes=0), fft.fftshift(freqs, axes=(0,))) assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs) assert_array_almost_equal(fft.ifftshift(shifted, axes=0), fft.ifftshift(shifted, axes=(0,)))
def delayseq(x, delay_sec:float, fs:int): """ x: input 1-D signal delay_sec: amount to shift signal [seconds] fs: sampling frequency [Hz] xs: time-shifted signal """ assert x.ndim == 1, 'only 1-D signals for now' delay_samples = delay_sec*fs delay_int = round(delay_samples) nfft = nextpow2(x.size+delay_int) fbins = 2*pi*ifftshift((arange(nfft)-nfft//2))/nfft X = fft(x,nfft) Xs = ifft(X*exp(-1j*delay_samples*fbins)) if isreal(x[0]): Xs = Xs.real xs = zeros_like(x) xs[delay_int:] = Xs[delay_int:x.size] return xs
def test_CenteredFFT(backend, M, N, K, B ): from numpy.fft import fftshift, ifftshift, fftn, ifftn b = backend() A = b.FFTc( (M,N,K), dtype=np.dtype('complex64') ) # forward ax = (0,1,2) x = b.rand_array( (M*N*K,B) ) y = b.rand_array( (M*N*K,B) ) x_h = x.to_host().reshape( (M,N,K,B), order='F' ) A.eval(y, x) y_act = y.to_host().reshape( (M,N,K,B), order='F' ) y_exp = fftshift( fftn( ifftshift(x_h, axes=ax), axes=ax, norm='ortho'), axes=ax) npt.assert_allclose(y_act, y_exp, rtol=1e-2) # adjoint x = b.rand_array( (M*N*K,B) ) y = b.rand_array( (M*N*K,B) ) x_h = x.to_host().reshape( (M,N,K,B), order='F' ) A.H.eval(y, x) y_act = y.to_host().reshape( (M,N,K,B), order='F' ) y_exp = fftshift( ifftn( ifftshift(x_h, axes=ax), axes=ax, norm='ortho'), axes=ax) npt.assert_allclose(y_act, y_exp, rtol=1e-2)
def ift2(G, dfx, dfy): Nx = G.shape[1] Ny = G.shape[0] return ifftshift(ifft2(ifftshift(G))) * Nx * Ny * dfx * dfy