scipy.special.
diric#
- scipy.special.diric(x, n)[原始碼]#
週期性 sinc 函數,也稱為狄利克雷函數。
狄利克雷函數定義為
diric(x, n) = sin(x * n/2) / (n * sin(x / 2)),
其中 n 是一個正整數。
- 參數:
- xarray_like
輸入資料
- nint
定義週期性的整數。
- 回傳:
- diricndarray
範例
>>> 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()
以下範例示範了
diric
給出了矩形脈衝的傅立葉係數的量值(模數為符號和縮放)。抑制有效值為 0 的輸出
>>> np.set_printoptions(suppress=True)
建立一個長度為 m 且有 k 個 1 的訊號 x
>>> 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.fft
和diric
的不同縮放慣例>>> 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])