示例#1
0
 def check_definition(self):
     x = [1, 2, 3, 4, 1, 2, 3, 4]
     x1 = [1, 2 + 3j, 4 + 1j, 2 + 3j, 4, 2 - 3j, 4 - 1j, 2 - 3j]
     y = irfft(x)
     y1 = direct_irdft(x)
     assert_array_almost_equal(y, y1)
     assert_array_almost_equal(y, ifft(x1))
     x = [1, 2, 3, 4, 1, 2, 3, 4, 5]
     x1 = [1, 2 + 3j, 4 + 1j, 2 + 3j, 4 + 5j, 4 - 5j, 2 - 3j, 4 - 1j, 2 - 3j]
     y = irfft(x)
     y1 = direct_irdft(x)
     assert_array_almost_equal(y, y1)
     assert_array_almost_equal(y, ifft(x1))
示例#2
0
 def check_definition(self):
     x = [1, 2, 3, 4 + 1j, 1, 2, 3, 4 + 2j]
     y = ifft(x)
     y1 = direct_idft(x)
     assert_array_almost_equal(y, y1)
     x = [1, 2, 3, 4 + 0j, 5]
     assert_array_almost_equal(ifft(x), direct_idft(x))
     x = [1, 2, 3, 4, 1, 2, 3, 4]
     y = ifft(x)
     y1 = direct_idft(x)
     assert_array_almost_equal(y, y1)
     x = [1, 2, 3, 4, 5]
     assert_array_almost_equal(ifft(x), direct_idft(x))
示例#3
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
示例#4
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)
示例#5
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)
示例#6
0
    def bench_random(self, level=5):
        from numpy.fft import ifft as numpy_ifft

        print
        print "       Inverse Fast Fourier Transform"
        print "==============================================="
        print "      |     real input    |    complex input   "
        print "-----------------------------------------------"
        print " size |  scipy  |  numpy  |  scipy  |  numpy  "
        print "-----------------------------------------------"
        for size, repeat in [
            (100, 7000),
            (1000, 2000),
            (256, 10000),
            (512, 10000),
            (1024, 1000),
            (2048, 1000),
            (2048 * 2, 500),
            (2048 * 4, 500),
        ]:
            print "%5s" % size,
            sys.stdout.flush()

            for x in [
                random([size]).astype(double),
                random([size]).astype(cdouble) + random([size]).astype(cdouble) * 1j,
            ]:
                if size > 500:
                    y = ifft(x)
                else:
                    y = direct_idft(x)
                assert_array_almost_equal(ifft(x), y)
                print "|%8.2f" % self.measure("ifft(x)", repeat),
                sys.stdout.flush()

                assert_array_almost_equal(numpy_ifft(x), y)
                print "|%8.2f" % self.measure("numpy_ifft(x)", repeat),
                sys.stdout.flush()

            print " (secs for %s calls)" % (repeat)
        sys.stdout.flush()
示例#7
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
示例#8
0
def direct_hilbert(x):
    fx = fft(x)
    n = len (fx)
    w = fftfreq(n)*n
    w = 1j*sign(w)
    return ifft(w*fx)
示例#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 check_random_real(self):
     for size in [1, 51, 111, 100, 200, 64, 128, 256, 1024]:
         x = random([size]).astype(double)
         assert_array_almost_equal(ifft(fft(x)), x)
         assert_array_almost_equal(fft(ifft(x)), x)