scipy.special.diric

scipy.special.diric(x, n)[源代码]

周期sinc函数,也称为Dirichlet函数。

Dirichlet函数定义为::

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

哪里 n 是正整数。

参数
xarray_like

输入数据

n集成

定义周期的整数。

退货
diricndarray

示例

>>> 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()
../../_images/scipy-special-diric-1_00_00.png

下面的示例演示了 diric 给出矩形脉冲的傅里叶系数的幅度(对符号和比例取模)。

禁止输出有效值为0的值:

>>> np.set_printoptions(suppress=True)

创建信号 x 长度的 m 使用 k 其中几个:

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

用快速傅立叶变换计算的傅里叶变换 x ,并检查系数的大小:

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

现在使用以下命令查找相同的值(最高可达SIGN) 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])