==================== 持续更新,敬请指正 =================
1. 线性卷积的基本理论
线性卷积是对线性移不变(LSI)系统的输入输出关系的描述,体现系统的特性。
线性卷积的表达式为
一般情况,现实的系统为因果系统,有k<0时,恒有h(k)=0,则
此时输出y(n)也为因果信号。
若x(n)是一个N点序列,h(n)是一个m点序列,则卷积的结果y(n)将是L=N+M-1点的序列。
卷积是一种典型的乘累加运算,非常适合在DSP处理器上实现。
2. 线性卷积的matlab实现
function y=conv(x,h,show_flag)
% 线性卷积的实现 y=x*h
% if show_flag=1 plot x and result in matlab
%
% Author: xiahouzuoxin
% Date: 2013-11-21
if nargin < 3
show_flag = 0;
end
N = length(x);
M = length(h);
L = M+N-1;
y = zeros(L,1);
for n=1:N
for k=1:M
y(n+k-1) = y(n+k-1) + x(n)*h(k);
end
end
if show_flag == 1
figure,
max_val = max([max(y),max(x),max(h)]);
subplot(2,2,1),stem(x);title('x(n)');grid on;axis([0 L 0 max_val])
subplot(2,2,2),stem(h);title('h(n)');grid on;axis([0 L 0 max_val])
subplot(2,2,3),stem(y);title('y(n)');grid on;axis([0 L 0 max_val])
end
设x=[1 2 3],h=[1 3 5 6],则调用conv([1 2 3], [1 3 5 6], 1)后,在matlab中绘制出如下图,
在matlab的库函数中已有实现好的卷积算法,使用help conv查阅,
>> help conv
CONV Convolution and polynomial multiplication.
C = CONV(A, B) convolves vectors A and B. The resulting vector is
length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]). If A and B are
vectors of polynomial coefficients, convolving them is equivalent to
multiplying the two polynomials.
C = CONV(A, B, SHAPE) returns a subsection of the convolution with size
specified by SHAPE:
'full' - (default) returns the full convolution,
'same' - returns the central part of the convolution
that is the same size as A.
'valid' - returns only those parts of the convolution
that are computed without the zero-padded edges.
LENGTH(C)is MAX(LENGTH(A)-MAX(0,LENGTH(B)-1),0).