当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。