1、代码:
function [y, H] = conv_tp(h, x)
% Linear Convolution using Toeplitz Matrix
% ----------------------------------------------------
% [y,H] = conv_tp(h, x)
% y = output sequence in column vector form
% H = Toeplitz matrix corresponding to sequence h so that y = Hx
% h = Impulse response sequence in length(h)*1 column vector form
% x = input sequence in length(x)*1 column vector form
%
for i = 1:length(h)
c(i) = h(i);
end for j=(length(h)+1):(length(x)+length(h)-1)
c(j)=0;
end r(1)=h(1); for k=2:length(x)
r(k)=0;
end H=toeplitz(c,r)
y=H*x;
end
2、用1小题中的函数验证习题2.17,代码如下:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 2.18 \n\n'); banner();
%% ------------------------------------------------------------------------ nx1 = [0:4]; x1 = [1, 2, 3, 4, 5];
nh1 = [0:3]; h1 = [6, 7, 8, 9]; [y1, H] = conv_tp(h1', x1'); y1
运行结果:
上图中H就是Toeplitz拓普利兹矩阵,可以看出除第一行、第一列外,每个元素都和其左上方元素相等。
每一行向量就是系统的脉冲响应序列的线性移位,h(n-k),其中n=0,1,2,.....,length(h)-1。
实际中,将序列h(n)摺叠,依次移位,得到Toeplitz矩阵。第一列就是h(n)加零补齐长度。