scipy.signal.

单位脉冲#

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

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

参数:
形状int 或 int 的元组

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

索引None 或 int 或 int 的元组 或 ‘mid’,可选

值为1的索引。如果为None,默认是第0个元素。如果``idx=’mid’,脉冲将在所有维度上居中于``shape // 2。如果是整数,脉冲将在所有维度上的`idx`处。

dtype数据类型,可选

数组所需的数据类型,例如 numpy.int8 。默认是 numpy.float64

返回:
yndarray

输出包含脉冲信号的数组。

注释

一维情况也被称为克罗内克δ函数。

Added in version 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.])

二维脉冲,居中:

>>> 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.]])

绘制一个4阶巴特沃斯低通滤波器的脉冲响应:

>>> imp = signal.unit_impulse(100, 'mid')
>>> b, a = signal.butter(4, 0.2)
>>> response = signal.lfilter(b, a, imp)
>>> import numpy as np
>>> 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