def test_random_real(self): for size in [1, 51, 111, 100, 200, 64, 128, 256, 1024]: x = random([size]).astype(self.rdt) y1 = ifft(fft(x)) y2 = fft(ifft(x)) assert_equal(y1.dtype, self.cdt) assert_equal(y2.dtype, self.cdt) assert_array_almost_equal(y1, x) assert_array_almost_equal(y2, x)
def test_definition(self): x = np.array([1, 2, 3, 4 + 1j, 1, 2, 3, 4 + 2j], self.cdt) y = ifft(x) y1 = direct_idft(x) assert_equal(y.dtype, self.cdt) assert_array_almost_equal(y, y1) x = np.array([1, 2, 3, 4 + 0j, 5], self.cdt) assert_array_almost_equal(ifft(x), direct_idft(x))
def test_definition_real(self): x = np.array([1, 2, 3, 4, 1, 2, 3, 4], self.rdt) y = ifft(x) assert_equal(y.dtype, self.cdt) y1 = direct_idft(x) assert_array_almost_equal(y, y1) x = np.array([1, 2, 3, 4, 5], dtype=self.rdt) assert_equal(y.dtype, self.cdt) assert_array_almost_equal(ifft(x), direct_idft(x))
def direct_shift(x, a, period=None): n = len(x) if period is None: k = fftfreq(n) * 1j * n else: k = fftfreq(n) * 2j * pi / period * n return ifft(fft(x) * exp(k * a)).real
def direct_itilbert(x, h=1, period=None): fx = fft(x) n = len(fx) if period is None: period = 2 * pi w = fftfreq(n) * h * 2 * pi / period * n w = -1j * tanh(w) return ifft(w * fx)
def direct_tilbert(x, h=1, period=None): fx = fft(x) n = len(fx) if period is None: period = 2 * pi w = fftfreq(n) * h * 2 * pi / period * n w[0] = 1 w = 1j / tanh(w) w[0] = 0j return ifft(w * fx)
def test_size_accuracy(self): # Sanity check for the accuracy for prime and non-prime sized inputs if self.rdt == np.float32: rtol = 1e-5 elif self.rdt == np.float64: rtol = 1e-10 for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES: np.random.seed(1234) x = np.random.rand(size).astype(self.rdt) y = ifft(fft(x)) _assert_close_in_norm(x, y, rtol, size, self.rdt) y = fft(ifft(x)) _assert_close_in_norm(x, y, rtol, size, self.rdt) x = (x + 1j * np.random.rand(size)).astype(self.cdt) y = ifft(fft(x)) _assert_close_in_norm(x, y, rtol, size, self.rdt) y = fft(ifft(x)) _assert_close_in_norm(x, y, rtol, size, self.rdt)
def direct_diff(x, k=1, period=None): fx = fft(x) n = len(fx) if period is None: period = 2 * pi w = fftfreq(n) * 2j * pi / period * n if k < 0: w = 1 / w**k w[0] = 0.0 else: w = w**k if n > 2000: w[250:n - 250] = 0.0 return ifft(w * fx).real
def direct_idftn(x): x = asarray(x) for axis in range(len(x.shape)): x = ifft(x, axis=axis) return x
def _test(x, xr): y = irfft(np.array(x, dtype=self.rdt)) y1 = direct_irdft(x) assert_equal(y.dtype, self.rdt) assert_array_almost_equal(y, y1, decimal=self.ndec) assert_array_almost_equal(y, ifft(xr), decimal=self.ndec)
def direct_hilbert(x): fx = fft(x) n = len(fx) w = fftfreq(n) * n w = 1j * sign(w) return ifft(w * fx)