One of the properties of convolution is that the centroids of the functions being convolved should add. See equation (18) of Wolfram Alpha's section on convolution Convolution Properties.

For example, if we have a Gaussian centered at t1=300, and we convolute it another Gaussian centered at t2=200, the resulting Gaussian peak after convolution is centered at 500. MATLAB works fine for that.

I was trying to convolute Gaussian functions, one centered at 0 (orange), and other one at 500 (blue), but the resulting function is not centered at 500 in MATLAB but appears much later (yellow). How can one circumvent this problem in MATLAB? I want to keep one Gaussian at 0. Thanks.

'''W=[0:1:2500]'; % bin numbers

g1= normpdf(W, 500, 100); % First Gaussian with unit area (x, mu, sigma)

g2= normpdf(W, 0, 100); % Second Gaussian with unit area (x, mu, sigma)


plot ( g1) hold on plot( g2) hold on plot(Convg1g2)'''

enter image description here


The reason is g1 is not a complete Gaussian pdf since you limited the range to not extend past 0.

The following will work for you:

g1= normpdf(W, 500, 100);
g2= normpdf(W, 0, 100);  
ConvG1G2 = conv(g1,g2, "same");
hold on

Results in:


  • $\begingroup$ Thanks, so does the convolution of half g1 considers the centroid to be non-zero and that is why it is shifted forward? I am trying to understand the mathematical reason for the forward shift as shown in the original post. $\endgroup$ – M. Farooq Apr 29 '20 at 23:05
  • $\begingroup$ Yes the centroid can no longer be at 0 if the other half is missing, right? (It is treating the negative side as 0 valued, and it is no longer a balanced function). $\endgroup$ – Dan Boschen Apr 29 '20 at 23:13
  • $\begingroup$ Right, thanks. It makes the connection now. $\endgroup$ – M. Farooq Apr 29 '20 at 23:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.