function [Ae, Be] = fftextend2(A,B)
% FFTEXTEND2 Perform the necessary domain extension for FFT
%
%    [AE, BE] = FFTEXTEND2(A,B) extends for A and B
%    AE = FFTEXTEND2(A) extends A with size(B)=size(A)
%    AE = FFTEXTEND2(A,[Br Bc]) extends A with size(B)=[Br Bc] 
%
%    See also FFTCROP2, FFTCONV2.
  
% Jerod Weinman
% jerod@acm.org
% 6 December (c) 2004
 
% $Id: fftextend2.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2007, 2008, 2011
 
%    This file is part of Matlab SDMaxEnt.
%
%    Matlab SDMaxEnt is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    Matlab SDMaxEnt is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with Matlab SDMaxEnt.  If not, see <http://www.gnu.org/licenses/>.
  
  [ma,na] = size(A);

  if nargin==1
    mb = ma;
    nb = na;
  elseif size(B,1)==1 & size(B,2)==2
      mb = B(1);
      nb = B(2);
  else
    [mb,nb] = size(B);
  end;

  % Extend the functions
    Ae = zeros( ma+mb-1, na+nb-1 );
    Ae(1:ma,1:na) = A;
    
    if nargout>1
      Be = zeros( ma+mb-1, na+nb-1 );
      Be(1:mb,1:nb) = B;
    end;
    

    
