%% Create Circulant Matrices Using toeplitz Function
% You can create circulant matrices using toeplitz. Circulant matrices are used in applications such as circular convolution.
% Create a circulant matrix from vector v using toeplitz.

v = [9 1 3 2];
toeplitz([v(1) fliplr(v(2:end))], v)

%
% Perform discrete-time circular convolution by using toeplitz to form the circulant matrix for convolution.
% Define the periodic input x and the system response h.

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

%
% Form the column vector c to create a circulant matrix where length(c) = length(h).

c = [x(1) fliplr(x(end-length(h)+2:end))]

%
% Form the row vector r from x.

r = x;

%
% Form the convolution matrix xConv using toeplitz. Find the convolution using h*xConv.

xConv = toeplitz(c,r)
h*xConv

% If you have the Signal Processing Toolbox™, you can use the cconv function to find the circular convolution.
% Copyright 2015 The MathWorks, Inc.