% circonvs2.m
% usage: Y = circconvs2(X,hpp,hpn,hnp,hnn)
% sparse 2D circular convolution
% by a causal anti-causal filter pair
% Performs 2D circular convolution by h on X, 
% the result has the same size as X.
% It is assumed that both the row dimension 
% and column dimension % of h do not exceed those of X. 
% The result is the same as circular convolution by
% h = [hpp,0,...,0,hpn,
%          0,...,0,
%      hnp,0...,0,hnn] zero-padded out to the size of X 

% S. Allen Broughton - 28 Oct 10
  
function Y=circconvs2(X,hpp,hpn,hnp,hnn)
[m,n] = size(X);
[u,v] = size(hnn);

Ypp = circconv2(X,hpp);
Ypn = circconv2(X,hpn); Ypn = [Ypn(:,(v+1):n),Ypn(:,1:v)];
Ynp = circconv2(X,hnp); Ynp = [Ynp((u+1):m,:);Ynp(1:u,:)];
Ynn = circconv2(X,hnn); Ynn = [Ynn(:,(v+1):n),Ynn(:,1:v)]; Ynn = [Ynn((u+1):m,:);Ynn(1:u,:)];
Y = Ypp+Ypn+Ynp+Ynn;
         


