當前位置: 首頁>>代碼示例>>Python>>正文


Python fftpack.rfft方法代碼示例

本文整理匯總了Python中scipy.fftpack.rfft方法的典型用法代碼示例。如果您正苦於以下問題:Python fftpack.rfft方法的具體用法?Python fftpack.rfft怎麽用?Python fftpack.rfft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.fftpack的用法示例。


在下文中一共展示了fftpack.rfft方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _centered

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def _centered(arr, newsize):
    # Return the center newsize portion of the array.
    newsize = numpy.asarray(newsize)
    currsize = numpy.array(arr.shape)
    startind = (currsize - newsize) // 2
    endind = startind + newsize
    myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
    return arr[tuple(myslice)]


#def _rfftn(a, s=None, axes=None):
#    s, axes = _cook_nd_args(a, s, axes);
#    a = fft.rfft(a, s[-1], axes[-1], overwrite_x = True)
#    for ii in range(len(axes)-1):
#        a = fft.fft(a, s[ii], axes[ii], overwrite_x = True)
#    return a

#def _irfftn(a, s=None, axes=None):   
#    #a = asarray(a).astype('complex64')
#    s, axes = _cook_nd_args(a, s, axes, invreal=1)
#    for ii in range(len(axes)-1):
#        a = fft.ifft(a, s[ii], axes[ii], overwrite_x = True);
#    a = fft.ifft(a, s[-1], axes[-1], overwrite_x = True);
#    a = a.real;
#    return a 
開發者ID:ChristophKirst,項目名稱:ClearMap,代碼行數:27,代碼來源:Convolution.py

示例2: test_size_accuracy

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
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 = irfft(rfft(x))
            self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
                            (size, self.rdt))
            y = rfft(irfft(x))
            self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
                            (size, self.rdt))

# self.ndec is bogus; we should have a assert_array_approx_equal for number of
# significant digits 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:21,代碼來源:test_basic.py

示例3: stft

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def stft(X, fftsize=128, step="half", mean_normalize=True, real=False,
         compute_onesided=True):
    """
    Compute STFT for 1D real valued input X
    """
    if real:
        local_fft = fftpack.rfft
        cut = -1
    else:
        local_fft = fftpack.fft
        cut = None
    if compute_onesided:
        cut = fftsize // 2 + 1
    if mean_normalize:
        X -= X.mean()
    if step == "half":
        X = halfoverlap(X, fftsize)
    else:
        X = overlap(X, fftsize, step)
    size = fftsize
    win = 0.54 - .46 * np.cos(2 * np.pi * np.arange(size) / (size - 1))
    X = X * win[None]
    X = local_fft(X)[:, :cut]
    return X 
開發者ID:kastnerkyle,項目名稱:tools,代碼行數:26,代碼來源:audio_tools.py

示例4: run_mgc_example

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def run_mgc_example():
    import matplotlib.pyplot as plt
    fs, x = wavfile.read("test16k.wav")
    pos = 3000
    fftlen = 1024
    win = np.blackman(fftlen) / np.sqrt(np.sum(np.blackman(fftlen) ** 2))
    xw = x[pos:pos + fftlen] * win
    sp = 20 * np.log10(np.abs(np.fft.rfft(xw)))
    mgc_order = 20
    mgc_alpha = 0.41
    mgc_gamma = -0.35
    mgc_arr = win2mgc(xw, order=mgc_order, alpha=mgc_alpha, gamma=mgc_gamma, verbose=True)
    xwsp = 20 * np.log10(np.abs(np.fft.rfft(xw)))
    sp = mgc2sp(mgc_arr, mgc_alpha, mgc_gamma, fftlen)
    plt.plot(xwsp)
    plt.plot(20. / np.log(10) * np.real(sp), "r")
    plt.xlim(1, len(xwsp))
    plt.show() 
開發者ID:kastnerkyle,項目名稱:tools,代碼行數:20,代碼來源:audio_tools.py

示例5: stft

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def stft(X, fftsize=128, step="half", mean_normalize=True, real=False,
         compute_onesided=True):
    """
    Compute STFT for 1D real valued input X
    """
    if real:
        local_fft = fftpack.rfft
        cut = -1
    else:
        local_fft = fftpack.fft
        cut = None
    if compute_onesided:
        cut = fftsize // 2
    if mean_normalize:
        X -= X.mean()
    if step == "half":
        X = halfoverlap(X, fftsize)
    else:
        X = overlap(X, fftsize, step)
    size = fftsize
    win = 0.54 - .46 * np.cos(2 * np.pi * np.arange(size) / (size - 1))
    X = X * win[None]
    X = local_fft(X)[:, :cut]
    return X 
開發者ID:dagbldr,項目名稱:dagbldr,代碼行數:26,代碼來源:audio_tools.py

示例6: bench_random

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def bench_random(self):
        from numpy.fft import rfft as numpy_rfft
        print()
        print('Fast Fourier Transform (real data)')
        print('==================================')
        print(' size |  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, end=' ')
            sys.stdout.flush()

            x = random([size]).astype(double)
            print('|%8.2f' % measure('rfft(x)',repeat), end=' ')
            sys.stdout.flush()

            print('|%8.2f' % measure('numpy_rfft(x)',repeat), end=' ')
            sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))
        sys.stdout.flush() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:29,代碼來源:bench_basic.py

示例7: test_definition

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_definition(self):
        for t in [[1, 2, 3, 4, 1, 2, 3, 4], [1, 2, 3, 4, 1, 2, 3, 4, 5]]:
            x = np.array(t, dtype=self.rdt)
            y = rfft(x)
            y1 = direct_rdft(x)
            assert_array_almost_equal(y,y1)
            self.assertTrue(y.dtype == self.rdt,
                    "Output dtype is %s, expected %s" % (y.dtype, self.rdt)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:10,代碼來源:test_basic.py

示例8: test_random_real

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_random_real(self):
        for size in [1,51,111,100,200,64,128,256,1024]:
            x = random([size]).astype(self.rdt)
            y1 = irfft(rfft(x))
            y2 = rfft(irfft(x))
            self.assertTrue(y1.dtype == self.rdt,
                    "Output dtype is %s, expected %s" % (y1.dtype, self.rdt))
            self.assertTrue(y2.dtype == self.rdt,
                    "Output dtype is %s, expected %s" % (y2.dtype, self.rdt))
            assert_array_almost_equal(y1, x, decimal=self.ndec,
                                       err_msg="size=%d" % size)
            assert_array_almost_equal(y2, x, decimal=self.ndec,
                                       err_msg="size=%d" % size) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:test_basic.py

示例9: test_rfft

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_rfft(self):
        overwritable = self.real_dtypes
        for dtype in self.real_dtypes:
            self._check_1d(rfft, dtype, (16,), -1, overwritable)
            self._check_1d(rfft, dtype, (16, 2), 0, overwritable)
            self._check_1d(rfft, dtype, (2, 16), 1, overwritable) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_basic.py

示例10: test_definition

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_definition(self):
        for t in [[1, 2, 3, 4, 1, 2, 3, 4], [1, 2, 3, 4, 1, 2, 3, 4, 5]]:
            x = np.array(t, dtype=self.rdt)
            y = rfft(x)
            y1 = direct_rdft(x)
            assert_array_almost_equal(y,y1)
            assert_equal(y.dtype, self.rdt) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:9,代碼來源:test_basic.py

示例11: test_invalid_sizes

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_invalid_sizes(self):
        assert_raises(ValueError, rfft, [])
        assert_raises(ValueError, rfft, [[1,1],[2,2]], -5)

    # See gh-5790 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_basic.py

示例12: test_non_ndarray_with_dtype

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_non_ndarray_with_dtype(self):
        x = np.array([1., 2., 3., 4., 5.])
        xs = _TestRFFTBase.MockSeries(x)

        expected = [1, 2, 3, 4, 5]
        out = rfft(xs)

        # Data should not have been overwritten
        assert_equal(x, expected)
        assert_equal(xs.data, expected) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_basic.py

示例13: test_random_real

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def test_random_real(self):
        for size in [1,51,111,100,200,64,128,256,1024]:
            x = random([size]).astype(self.rdt)
            y1 = irfft(rfft(x))
            y2 = rfft(irfft(x))
            assert_equal(y1.dtype, self.rdt)
            assert_equal(y2.dtype, self.rdt)
            assert_array_almost_equal(y1, x, decimal=self.ndec,
                                       err_msg="size=%d" % size)
            assert_array_almost_equal(y2, x, decimal=self.ndec,
                                       err_msg="size=%d" % size) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:13,代碼來源:test_basic.py

示例14: test_size_accuracy

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
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 = irfft(rfft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)
            y = rfft(irfft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_basic.py

示例15: stft

# 需要導入模塊: from scipy import fftpack [as 別名]
# 或者: from scipy.fftpack import rfft [as 別名]
def stft(X, windowsize=None, fftsize=None, step="half", mean_normalize=True, real=False,
         window_type="hann", periodic=True, compute_onesided=True):
    """
    Compute STFT for 1D real valued input X
    """
    if real:
        raise ValueError("real=True needs debug")
        local_fft = fftpack.rfft
        cut = None
    else:
        local_fft = fftpack.fft
        cut = None

    if fftsize == None:
        assert windowsize is not None
        enclosing_fftsize = int(2 ** np.ceil(np.log(windowsize) / np.log(2.0)))
        fftsize = enclosing_fftsize
    else:
        windowsize = fftsize

    if compute_onesided or real:
        cut = fftsize // 2 + 1

    if mean_normalize:
        X -= X.mean()

    if step == "half":
        X = halfoverlap(X, windowsize)
    else:
        X = overlap(X, windowsize, step)

    size = fftsize
    if window_type == "hann" and periodic:
        win = _raised_cosine_window(size, True, 0.5, 0.5)
    else:
        raise ValueError("No other windows currently supported")
        #win = 0.54 - .46 * np.cos(2 * np.pi * np.arange(size) / (size - 1))
    #win = 0.54 - .46 * np.cos(2 * np.pi * np.arange(size) / (size - 1))
    X = X * win[None]
    X = local_fft(X.astype(np.float64))[:, :cut]
    return X 
開發者ID:kastnerkyle,項目名稱:representation_mixing,代碼行數:43,代碼來源:audio.py


注:本文中的scipy.fftpack.rfft方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。