Matlab - FFT Gaussian equivalence

simple problem:

I am drawing a two-dimensional Gaussian function with some resolution in Matlab. I am testing with dispersion or sigma = 1.0. I want to compare it with the result of the FFT (Gaussian), which should lead to another Gaussian with dispersion (1./sigma). Since I'm testing sigma = 1.0, I think I should get two equivalent 2D kernels.

i.e.

g1FFT = buildKernel(rows, cols, mu, sigma)    % uses normpdf over arbitrary resolution (rows, cols, 3) with the peak in the center

buildKernel:

function result = buildKernel(rows, cols, mu, sigma)  

result = zeros(rows, cols, 3);

center_w = floor(cols / 2);
center_h = floor(rows / 2);

for i = 1:rows
    for j = 1:cols
        distance = sqrt((center_w - j).^2 + (center_h - i).^2);
        g_val = normpdf(distance, mu, sigma);
        result(i, j, :) = g_val;
    end
end

% normalize so that kernel sums to 1
sumKernel = sum(result(:));
result = result ./ sumKernel;    

end

I am testing with mu = 0.0 (always) and variance or sigma = 1.0. I want to compare it with the result of the FFT (Gaussian), which should lead to another Gaussian with dispersion (1./sigma).

i.e.

g1FFT = circshift(g1FFT, [rows/2, cols/2, 0]);       % fft2 expects center to be in corners 
freq_G1 = fft2(g1FFT);
freq_G1 = circshift(freq_G1, [-rows/2, -cols/2, 0]); % shift back to center, for comparison sake

Since I'm testing sigma = 1.0, I think I should get two equivalent 2D cores, because if sigma = 1.0, then 1.0 / sigma = 1.0. So g1FFT will be equal to freq_G1.

. , . - ?

+4
1

, . .

, . , , mu = 0 = 1/sqrt (2π) ( a = 1/(2 * sigma ^ 2) = π ),

enter image description here

( ):

enter image description here

, , . , wikipedia, , , . , - ( , , ​​ , , , true ). ( N)

enter image description here

mu = 0 sigma = sqrt (N/2π) ( ):

enter image description here

buildKernel sqrt (rows/2π) sqrt (cols/2π) :

function result = buildKernel(rows, cols, mu, sigma)  

  if (length(mu)>1)
    mu_h = mu(1);
    mu_w = mu(2);
  else
    mu_h = mu;
    mu_w = mu;
  endif
  if (length(sigma)>1)
    sigma_h = sigma(1);
    sigma_w = sigma(2);
  else
    sigma_h = sigma;
    sigma_w = sigma;
  endif

  center_w = mu_w + floor(cols / 2);
  center_h = mu_h + floor(rows / 2);

  r = transpose(normpdf([0:rows-1],center_h,sigma_h));
  c = normpdf([0:cols-1],center_w,sigma_w);
  result = repmat(r * c, [1 1 3]);

  % normalize so that kernel sums to 1
  sumKernel = sum(result(:));
  result = result ./ sumKernel;    

end

, FFT . , ,

g1FFTin = buildKernel(rows, cols, mu, [sqrt(rows/2/pi) sqrt(cols/2/pi)]);

, freq_G1 ( ) g1FFTin * sqrt(rows*cols).

, , , , ​​FFT () , FFT sigma , . , , ​​ :

g1FFTin = buildKernel(rows, cols, mu, sigma);

, :

g1FFT   = circshift(g1FFTin, [rows/2, cols/2, 0]);
freq_G1 = fft2(g1FFT);
freq_G1 = circshift(freq_G1, [-rows/2, -cols/2, 0]);

freq_G1 , :

freq_G1_approx = (rows*cols/(2*pi*sigma^2))*buildKernel(rows, cols, mu, [rows cols]/(2*pi*sigma));
0

All Articles