示例#1
0
 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)
示例#2
0
    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))
示例#3
0
    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))
示例#4
0
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
示例#5
0
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)
示例#6
0
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)
示例#7
0
    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)
示例#8
0
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
示例#9
0
def direct_idftn(x):
    x = asarray(x)
    for axis in range(len(x.shape)):
        x = ifft(x, axis=axis)
    return x
示例#10
0
 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)
示例#11
0
def direct_hilbert(x):
    fx = fft(x)
    n = len(fx)
    w = fftfreq(n) * n
    w = 1j * sign(w)
    return ifft(w * fx)