# Basic 2D convolution with mathematica

Can anyone tell me why the following keeps burning my CPU without ever producing the desired plot?

f[x_, y_] := If[Sqrt[x^2 + y^2] < 1, 1, 0];
test[t_, z_] := N[Convolve[f[x, y], f[x, y], {x, y}, {t, z}]];
Plot3D[test[t, z], {t, -5, 5}, {z, -5, 5}];


Thanks!

• Two reasons: 1. you re-compute the convolution for every plotted point; 2. Mathematica actually cannot do this convolution analytically anyway. (Not even if you rewrite it as f[x_, y_] := HeavisidePi[Sqrt[x^2 + y^2]/2].) – Oleksandr R. Jan 28 '16 at 14:31
• You may try to convolve in polar coordinates. – Dr. belisarius Jan 28 '16 at 17:55

If you need result at some sensible time frame vs quality...

f[x_, y_] := Piecewise[{{1, Sqrt[x^2 + y^2] < 1}}]

nconv[t_, z_] := NIntegrate[f[x, y] f[x - t, y - z],
{x, -Infinity, Infinity}, {y, -Infinity, Infinity}]

data = ParallelTable[nconv[t, z], {t, -3, 3, .2}, {z, -3, 3, .2}]; // AbsoluteTiming


{57.205376, Null}

ListPlot3D[data, PlotRange -> All]
`