Exercise 4.3: Compute the circular convolution z = x*y when x = (1,1,-1,-2,2) and y = (3,1,4,5,1).

We wrote a little MATLAB function:

function z = circonv(x,y)
% returns the circular convolution of the vectors x and y
n = length(x);
for i=1:n
  z(i) = 0;
  for j=1:n
    if (i+1-j > 0)
      z(i) = z(i) + x(j)*y(i+1-j);
    else
      z(i) = z(i) + x(j)*y(n+i+1-j);
    end;
  end;
end;
and executed this script on the data:
>> x = [1 1 -1 -1 2]

x =

     1     1    -1    -1     2

>> y = [3 1 4 5 1]

y =

     3     1     4     5     1

>> circonv(x,y)

ans =

    -3     6    11     7     7