scipy.signal.unit_impulse

scipy.signal.unit_impulse(shape, idx=None, dtype=<class 'float'>)[源代码]

单位脉冲信号(离散增量函数)或单位基向量。

参数
shape整型或整型元组

输出中的样本数(1-D),或表示输出形状的元组(N-D)。

idx无或int或int或‘mid’的元组,可选

值为1的索引。如果没有,则默认为第0个元素。如果 idx='mid' ,冲量将集中在 shape // 2 在所有维度上。如果为int,则脉冲将为 idx 在所有维度上。

dtype数据类型,可选

阵列的所需数据类型,例如, numpy.int8 。默认值为 numpy.float64

退货
yndarray

包含脉冲信号的输出阵列。

注意事项

1D案例也被称为Kronecker三角洲。

0.19.0 新版功能.

示例

第0元素处的冲量 (\(\delta[n]\) ):

>>> from scipy import signal
>>> signal.unit_impulse(8)
array([ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

脉冲偏移2个样本 (\(\delta[n-2]\) ):

>>> signal.unit_impulse(7, 2)
array([ 0.,  0.,  1.,  0.,  0.,  0.,  0.])

2维脉冲,居中:

>>> signal.unit_impulse((3, 3), 'mid')
array([[ 0.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  0.]])

(2,2)处的脉冲,使用广播:

>>> signal.unit_impulse((4, 4), 2)
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.]])

绘制四阶巴特沃斯低通过滤的冲激响应图:

>>> imp = signal.unit_impulse(100, 'mid')
>>> b, a = signal.butter(4, 0.2)
>>> response = signal.lfilter(b, a, imp)
>>> import matplotlib.pyplot as plt
>>> plt.plot(np.arange(-50, 50), imp)
>>> plt.plot(np.arange(-50, 50), response)
>>> plt.margins(0.1, 0.1)
>>> plt.xlabel('Time [samples]')
>>> plt.ylabel('Amplitude')
>>> plt.grid(True)
>>> plt.show()
../../_images/scipy-signal-unit_impulse-1.png