% gpconvEx1.m
%            06 Feb 2018
clear

R = 7; C = 5; r = 3; c = 2 ;
ac = (1:R)'*10 ;
ar = 1:C ;
[cc, rr] = meshgrid(ar,ac) ;
F = cc+rr;
num2str(F, '%2d ')

W = F(1:r, 1:c)/100 ;
num2str(W, '%0.2f ')

% left convolution matrix
lcmF = zeros(R+r-1, r*C) ;
for k = 1:r
    lcmF((1:R)+(k-1),(1:C)+(k-1)*C) = F;
end
num2str(lcmF, '%2d ')

% right convolution matrix
rcmW = [];
for k = 1:r
    rcmW = [rcmW ; convmtx(W(k, :),C)] ;
end
num2str(rcmW, '%0.2f ')

FW = conv2(F, W) ;
num2str(FW, '%2.2f ')
FWp = lcmF*rcmW ;
num2str(FWp, '%2.2f ')