% RES = CCONV2(MTX1,MTX2) % % Circular convolution of two matrices. Result will be of size of % LARGER vector. % % EPS, 6/96. function c = cconv(a,b) if (( size(a,1) >= size(b,1) ) & ( size(a,2) >= size(b,2) )) large = a; small = b; elseif (( size(a,1) <= size(b,1) ) & ( size(a,2) <= size(b,2) )) large = b; small = a; else error('one arg must be larger than the other in both dimensions!'); end ly = size(large,1); lx = size(large,2); sy = size(small,1); sx = size(small,2); sy2 = floor(sy/2); sx2 = floor(sx/2); % pad: clarge = [ large(ly-sy2+1:ly,lx-sx2+1:lx), large(ly-sy2+1:ly,:), ... large(ly-sy2+1:ly,1:sx-sx2-1); ... large(:,lx-sx2+1:lx), large, large(:,1:sx-sx2-1); ... large(1:sy-sy2-1,lx-sx2+1:lx), ... large(1:sy-sy2-1,:), ... large(1:sy-sy2-1,1:sx-sx2-1) ]; c = conv2(clarge,small,'valid');