%% Discrete-Time Convolution Using Toeplitz
% Perform discrete-time convolution by using toeplitz to form the arrays for convolution.
% Define the input x and system response h.

x = [1 8 3 2 5];
h = [3 5 2];

%
% Form r by padding x with zeros. The length of r is the convolution length x + h - 1.

r = [x zeros(1,length(h)-1)]

%
% Form the column vector c. Set the first element to x(1) because the column determines the diagonal. Pad c because length(c) must equal  length(h) for convolution.

c = [x(1) zeros(1,length(h)-1)]

%
% Form the convolution matrix xConv using toeplitz. Then, find the convolution using h*xConv.

xConv = toeplitz(c,r)
h*xConv

%
% Check that the result is correct using conv.

conv(x,h)

% Copyright 2015 The MathWorks, Inc.