Вот код, который мне нужен для моего докторского исследования, которое, как я знаю, правильно выполняет заполнение нулями.Надеюсь, это поможет.
function conv_out=F_convolve_FFT(f,g,dw,flipFlag),
if(nargin<4), flipFlag==0; end;
% length of function f to be convolved, initialization of conv_out, and padding p
N=length(f); conv_out=zeros(1,N); p=zeros(1,N);
% uncomment if working with tensor f,g's of rank 3 or greater
% f=F_reduce_rank(f); g=F_reduce_rank(g);
% padding. also, this was commented out: EN=length(fp);
fp = [f p]; gp = [g p];
% if performing convolution of the form c(w) = int(f(wp)g(w+wp),wp) = int(f(w-wp)gbar(wp),wp) due to reverse-order domain on substitution
if(flipFlag==1), gp=fliplr(gp); end;
% perform the convolution. You do NOT need to multiply the invocation of "F_convolve_FFT(f,g,dw,flipFlag)" in your program by "dx", the finite-element.
c1 = ifft(fft(fp).*fft(gp))*dw;
% if performing "reverse" convolution, an additional circshift is necessary to offset the padding
if(flipFlag==1), c1=circshift(c1',N)'; end;
% offset the padding by dNm
if(mod(N,2)==0), dNm=N/2; elseif(mod(N,2)==1), dNm=(N-1)/2; end;
% padding. also, this was commented out: EN=length(fp);
conv_out(:)=c1(dNm+1:dNm+N);
return