% spcnvmat.m % returns sparse matrix that performs circular convolution % usage: A = convomat(f) % A*X will convolve each column of X with the function f function A = spcnvmat(f); n = length(f); I = []; J = []; S = []; K = find(~(f==0)); for i = K J = [J 1:n]; I = [I rem((1:n)+(i-2)*ones(1,n),n)+ones(1,n)]; S = [S,f(i)*ones(1,n)]; A = sparse(I,J,S,n,n); end;