在泛函分析中,卷积、旋积或摺积(英语:Convolution)是通过两个函数f和g生成第三个函数的一种数学算子,表征函数f与g经过翻转和平移的重叠部分的面积。如果将参加卷积的一个函数看作区间的指示函数,卷积还可以被看作是“滑动平均”的推广。
卷积公式:
相关运算过程:
离散卷积是两个离散序列和之间按照一定的规则将它们的有关序列值分别两两相乘再相加的一种特殊的运算。在工程上离散卷积有着广泛的应用。例如为了将数字信号进行滤波,可以将表示成离散序列的该信号x(n)与数字滤波器的冲激响应h(n)进行卷积。
Returns the discrete, linear convolution of two one-dimensional sequences.
The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal [R17]. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions.
If v is longer than a, the arrays are swapped before computation.
Parameters: | a : (N,) array_like
v : (M,) array_like
mode : {‘full’, ‘valid’, ‘same’}, optional
|
---|---|
Returns: | out : ndarray
|
例子:
#python 3.5.3 #2017-03-09 蔡军生 http://blog.csdn.net/caimouse # import numpy as np import matplotlib.pyplot as plt f = [1,2,3,4] g = [1,1,3] cnn = np.convolve([1,2,3,4],[1,1,3],'full') print(f) print(g) print(cnn) cnn = np.convolve([1,2,3,4],[1,1,3],'same') print(cnn) plt.plot(f, 'r-') plt.plot(g, 'g-') plt.plot(cnn, 'b-') plt.show()
[1, 2, 3, 4]
[1, 1, 3]
[ 1 3 8 13 13 12]
[ 3 8 13 13]