3

Recently I have asked the question about convolution and how to calculate it numerically.

I still misunderstand the following moment: if I have two functions defined on a grid {x,y}, so I have two arrays f[x,y] and g[x,y]. Then, I use Fourier to obtain Fourier transforms of my functions, FTf and FTg, respectively, and compute

listw=InverseFourier[FTf*FTg]

The question is following: if initial functions were defined in domain {x,y} can I assume that values of convolution $w=f*g$ are defined on the same domain? Can I just use ListPlot3D with input {x,y,w[x,y]} where x and y correspond to original grid?

Consider the example with f[x,y]=g[x,y]=Exp[-(x^2+y^2)] evaluated for x and y from [0,1] with step 0.1.

Numerical evaluation is:

center[array_] := 
 RotateRight[Map[RotateRight[#, Floor[Length[array]/2]] &, array], 
  Floor[Length[array]/2]];
s=0.1;
a = 1.;
f[x_, y_] := Exp[-(x^2 + y^2)];
g[x_, y_] := Exp[-(x^2 + y^2)];
n = Table[x, {x, -a, a, s}] // Length;
fdata = Table[f[x, y], {x, -a, a, s}, {y, -a, a, s}];
gdata = Table[g[x, y], {x, -a, a, s}, {y, -a, a, s}];
FTf = center[Fourier[fdata]];
FTg = center[Fourier[gdata]];
listw = Abs[1/Total@Flatten[gdata, 1]*Sqrt[n]*center[InverseFourier[FTf*FTg]]];

List density plot of listw with mentioned {x,y} values gives

enter image description here

Then, "exact" calculation,

FTf1 = FourierTransform[f[x, y], {x, y}, {w1, w2}];
FTf2 = FourierTransform[g[x, y], {x, y}, {w1, w2}];
wfunction = 2*Pi*InverseFourierTransform[FTf1*FTf2, {w1, w2}, {x, y}]

gives the following density plot,

enter image description here

I do not understand how it happens. I try to take into account scaling factors using this question

Artem Alexandrov
  • 803
  • 4
  • 11
  • 3
    It will give you a grid from which you can extract values and integer coordinates {x,y} into a flat list using flat = Flatten[MapIndexed[Append[#2,#1]&, listw,{2}],1]. If you need to rescale the integer coordinates back into some other domain, use Map[{Rescale[#[[1]], {xmin,xmax}],Rescale[#[[2]], {ymin,ymax}],#[[3]]}&, flat] – flinty Jun 19 '20 at 15:10
  • Thank you! But does it work for domain, for instance, {xmin,xmax}={-1,1}? Seems not – Artem Alexandrov Jun 19 '20 at 15:28
  • @flinty I would like to emphasize that I understand how to obtain flat list from listw but I am not sure that this function is defined on the the same lattice – Artem Alexandrov Jun 19 '20 at 15:29
  • 2
    Fourier and InverseFourier don't know about the "lattice" - they just process 2d arrays. Please expain what's wrong with using Rescale to {xmin,xmax}={-1,1} after the invert. Is your grid regular? – flinty Jun 19 '20 at 15:31
  • 2
    In order to find out just make an experiment with 1 function. Make direct and inverse transform, plot as you suggest, and see what happens. From this, you will get an idea on what happens with two functions. See also ListCorrelate. – yarchik Jun 19 '20 at 16:19
  • @yarchik I add the example with simple functions and provide plots – Artem Alexandrov Jun 19 '20 at 17:14
  • There are some mistakes when I execute your code: Delta is not defined, is it ok to have s=1? – yarchik Jun 20 '20 at 18:08
  • @yarchik yes, I have checked my code. – Artem Alexandrov Jun 20 '20 at 20:37

0 Answers0