function Ap = zero_pad_2d(A,NfftX,NfftY)
% ZERO_PAD_2D  applies zero-phase-zero padding
% (https://ccrma.stanford.edu/~jos/sasp/Zero_Phase_Zero_Padding.html) for
% two dimensions (first apply ZERO_PAD_2D, then FFTSHIFT, then FFT2 and
% then again FFTSHIFT
%   A:      matrix to be padded
%   NfftX:  number of samples in first dimension after padding
%   NfftY:  number of samples in second dimension after padding
    Ap = zeros(NfftX,NfftY);
    [x,y] = size(A);
    center = [floor(NfftX/2), floor(NfftY/2)];
    startPoint = center - [floor(x/2),floor(y/2)];
    Ap(startPoint(1)+1:startPoint(1)+x,startPoint(2)+1:startPoint(2)+y)=A;
end

