當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy special.diric用法及代碼示例

本文簡要介紹 python 語言中 scipy.special.diric 的用法。

用法:

scipy.special.diric(x, n)#

周期正弦函數,也稱為狄利克雷函數。

狄利克雷函數定義為:

diric(x, n) = sin(x * n/2) / (n * sin(x / 2)),

其中 n 是一個正整數。

參數

x array_like

輸入數據

n int

定義周期性的整數。

返回

diric ndarray

例子

>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-8*np.pi, 8*np.pi, num=201)
>>> plt.figure(figsize=(8, 8));
>>> for idx, n in enumerate([2, 3, 4, 9]):
...     plt.subplot(2, 2, idx+1)
...     plt.plot(x, special.diric(x, n))
...     plt.title('diric, n={}'.format(n))
>>> plt.show()
scipy-special-diric-1_00_00.png

以下示例演示diric 給出矩形脈衝的傅裏葉係數的幅度(對符號和縮放進行模)。

抑製實際上為 0 的值的輸出:

>>> np.set_printoptions(suppress=True)

創建一個長度為 m 的信號 x 和 k 個:

>>> m = 8
>>> k = 3
>>> x = np.zeros(m)
>>> x[:k] = 1

使用 FFT 計算 x 的傅裏葉變換,並檢查係數的大小:

>>> np.abs(np.fft.fft(x))
array([ 3.        ,  2.41421356,  1.        ,  0.41421356,  1.        ,
        0.41421356,  1.        ,  2.41421356])

現在使用diric.我們乘以k考慮到不同的縮放約定numpy.fft.fftdiric

>>> theta = np.linspace(0, 2*np.pi, m, endpoint=False)
>>> k * special.diric(theta, k)
array([ 3.        ,  2.41421356,  1.        , -0.41421356, -1.        ,
       -0.41421356,  1.        ,  2.41421356])

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.special.diric。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。