%Function [ox,oy,odx]=ResampleData(x1,x2,y2)
%Resamples function y2 to match the sample spacing of x1 over the common
%region of support of x1 and x2
function [ox,oy,dox]=ResampleData(x1,x2,y2)

%Extract Calibration and System Data Where The Two Data Sets Intersect
dox=x1(2)-x1(1);   
[m1,n1]=size(x1);
[m2,n2]=size(x2);
minox=max([x1(1) x2(1)]);
minox=dox*ceil(minox/dox);
maxox=min([x1(m1) x2(m2)]);
maxox=dox*floor(maxox/dox);
ox=1:1:m1;
ox=minox+(dox.*(ox-1));
ox=ox';
[m,n]=size(ox);
oy=zeros(m,n);
for k=1:m,
  	lower=max(find(x2<=ox(k)));
  	upper=min(find(x2>ox(k)));
  	if isempty(upper),
  	   oy(k)=oy(k-1);
  	else,
     	oy(k)=(((ox(k)-x2(lower))/(x2(upper)-x2(lower)))*(y2(upper)-y2(lower)))+y2(lower);
  	end;
end;
