How to create and plot a Gaussing function?

27 ビュー (過去 30 日間)
Gn Gnk
Gn Gnk 2020 年 12 月 7 日
コメント済み: Gn Gnk 2020 年 12 月 7 日
Hello ,
i want to create a 2D Gaussian function 9x9 and sigma =0.7 using this type :
Here is my code:
sigma=0.7;
nx=9;
ny=9;
[x,y]=meshgrid(1:nx,1:ny);
G=(0.5/(pi.*(sigma.^2))).*exp(-0.5.*((y.^2+x.^2)./(sigma.^2)));
Then i was asked to take the Gaussian function G and compute its fast fourier transform by using fft2()
G_fft=fft2(G);
Finally by using mesh() i was asked to compare the 2 results .
figure();
mesh(G);
figure();
mesh(G_fft);
The problem here is that in the first case (mesh(G)) i am getting a big edge(which i dont know if its right) and in the second case i am getting this error : X, Y, Z, and C cannot be complex. (problem in the line mesh(G_fft) because G_fft has complex numbers due to fourier transform).
Can comeone tell me what is wrong here?
  1 件のコメント
Gn Gnk
Gn Gnk 2020 年 12 月 7 日
This is what i get using mesh() for ploting the Gaussian function

サインインしてコメントする。

採用された回答

VBBV
VBBV 2020 年 12 月 7 日
編集済み: VBBV 2020 年 12 月 7 日
%true
sigma=0.7;
nx=9;
ny=9;
[x,y]=meshgrid(-nx:0.5:nx,-ny:0.5:ny);
G=(0.5./(pi.*(sigma.^2))).*exp(-0.5.*((y.^2+x.^2)./(sigma.^2)));
G_fft=fft2(G);
figure(1);
mesh(x,y,G);
figure(2);
mesh(x,y,abs(G_fft));
Use both positive and negative values for meshgrid to get Gaussian shape as above. Use also _abs_instead of real value e
  1 件のコメント
Gn Gnk
Gn Gnk 2020 年 12 月 7 日
Perfect thank you so much !!
Just a quick notice :
nx and ny should be equal to 2 in order for G to be 9x9 .
Can you explain why the plots appear to be opposite (i think)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by