scipy.signal.upfirdn

scipy.signal.upfirdn(h, x, up=1, down=1, axis=- 1, mode='constant', cval=0)[源代码]

上采样、冷杉过滤和下采样。

参数
harray_like

一维FIR(有限脉冲响应)过滤系数。

xarray_like

输入信号阵列。

up整型,可选

上采样率。默认值为1。

down整型,可选

下采样率。默认值为1。

axis整型,可选

要沿其应用线性过滤的输入数据数组的轴。过滤沿此轴应用于每个子阵列。默认值为-1。

mode字符串,可选

要使用的信号扩展模式。布景 {{"constant", "symmetric", "reflect", "edge", "wrap"}} 对应于由提供的模式 numpy.pad"smooth" 通过基于阵列两端最后两个点的坡度进行延伸来实现平滑延伸。 "antireflect""antisymmetric" 是反对称版本的 "reflect""symmetric" 。该模式 "line" 根据由沿线的第一个点和最后一个点定义的线性趋势扩展信号 axis

1.4.0 新版功能.

cval浮动,可选

在以下情况下使用的常量值 mode == "constant"

1.4.0 新版功能.

退货
yndarray

输出信号阵列。尺寸将与 x 除了沿着 axis ,它将根据 hup ,以及 down 参数。

注意事项

该算法是Vaidyanathan文本第129页所示挡路图的实现 [1] (图4.3-8d)。

长度为零插入FIR滤波的P因子上采样的直接方法 N Q因子的下采样为每个输出样本O(N*Q)。这里使用的多阶段实现是O(N/P)。

0.18 新版功能.

参考文献

1

韦德亚纳坦著,“多利率系统与过滤银行”,普伦蒂斯·霍尔,1993年。

示例

操作简单:

>>> from scipy.signal import upfirdn
>>> upfirdn([1, 1, 1], [1, 1, 1])   # FIR filter
array([ 1.,  2.,  3.,  2.,  1.])
>>> upfirdn([1], [1, 2, 3], 3)  # upsampling with zeros insertion
array([ 1.,  0.,  0.,  2.,  0.,  0.,  3.,  0.,  0.])
>>> upfirdn([1, 1, 1], [1, 2, 3], 3)  # upsampling with sample-and-hold
array([ 1.,  1.,  1.,  2.,  2.,  2.,  3.,  3.,  3.])
>>> upfirdn([.5, 1, .5], [1, 1, 1], 2)  # linear interpolation
array([ 0.5,  1. ,  1. ,  1. ,  1. ,  1. ,  0.5,  0. ])
>>> upfirdn([1], np.arange(10), 1, 3)  # decimation by 3
array([ 0.,  3.,  6.,  9.])
>>> upfirdn([.5, 1, .5], np.arange(10), 2, 3)  # linear interp, rate 2/3
array([ 0. ,  1. ,  2.5,  4. ,  5.5,  7. ,  8.5,  0. ])

将单个过滤应用于多个信号:

>>> x = np.reshape(np.arange(8), (4, 2))
>>> x
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7]])

沿的最后一个维度应用 x

>>> h = [1, 1]
>>> upfirdn(h, x, 2)
array([[ 0.,  0.,  1.,  1.],
       [ 2.,  2.,  3.,  3.],
       [ 4.,  4.,  5.,  5.],
       [ 6.,  6.,  7.,  7.]])

沿的第0维应用 x

>>> upfirdn(h, x, 2, axis=0)
array([[ 0.,  1.],
       [ 0.,  1.],
       [ 2.,  3.],
       [ 2.,  3.],
       [ 4.,  5.],
       [ 4.,  5.],
       [ 6.,  7.],
       [ 6.,  7.]])