what you want is called "padarray", immediately after defining DFT_A:
padsize= [round(0.5*size(DFT_A,1)-0.5*size(F,1)) round(0.5*size(DFT_A,2)-0.5*size(F,2))]; F = padarray(F, padsize); DFT_A_F=DFT_A.*F; ...
But why don't you just (given that A is a two-dimensional matrix, so rgb2gray if necessary):
DFT_A_F = conv2(A,B,'same');
This is faster because you do not need to multiply all these zeros and should get the same result.
source share