I have a somewhat messy piece-wise function that I need to convolve with a Gaussian function. Solving the problem analytically is taking forever so I would like to solve the problem numerically. However, I am having a few issues and any help would be greatly appreciated.

Here is an example of simplified version of what I am trying to implement using ListConvolve.

Following is a convolution between a simple trig function and Gaussian function done analytically.

response[t_] := 1/Sqrt[2 Pi  .2^2)] Exp[-(t^2/(2* .2^2))]
func[t_] := (Sin[3*t])^2
val = Integrate[response[t-Tau]*func[t], {t, -10, 10}];
Plot[{func[Tau], val}, {Tau, -5, 5}, PlotLegends -> {"Original", "Convolved"}]

Plot from the above calculation

The result is what I expected. Now I would like to do the same problem numerically (i.e. find convolution). I tried using ListConvolve, a built in function

unconvfunc = Table[{t, func[t]}, {t, -10, 10, 0.01}];
resdata =  Table[{t, response[t]/100}, {t, -2, 2, 0.01}];
convfunc = ListConvolve[resdata[[All, 2]], unconvfunc[[All, 2]], 1];
ListLinePlot[{unconvfunc, Transpose[{unconvfunc[[All, 1]], convfunc}]}, 
 PlotRange -> {{-5, 5}, {0, 1}}, PlotLegends -> {"Original", "Convolved"}]

I run into two problems. First the time axis is shifted for the convolved data. In the specific example if I pick the argument for ListConvolve[#,#,97] to be 97 instead of 1, the convolved plot seems to be more or less aligned with my original data. Also to get the normalization of the convfunc properly I divide the resdata by 1/stepsize. How would I pick those two parameters intelligently such that the numerical convolution would agree with the analytical one.

Numerically convolved plot

Thank you


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.