# Simple question about plotting a convolution

88 views (last 30 days)
aurc89 on 25 Mar 2015
Edited: Bruno Luong on 26 Sep 2019
I have two sets of data (x,y1) and (x,y2).I need to calculate the convolution between y1 and y2 and plot it vs x. Is it correct to do simply like this?
convol=conv(y1,y2);
plot(x,convol)
I've never used the command conv and I'm not sure about it. Thanks!

Andrew Newell on 25 Mar 2015
Edited: Andrew Newell on 25 Mar 2015
Your code will give you a vector of length length(y1)+length(y2)-1, so you'll get an error if you plot it against x (which is presumably the same length as y1 and y2). Instead, use
convol = conv(y1,y2,'same')
which gives you the central part of the convolution of the same size as y1. Then you'll be able to plot it.
aurc89 on 25 Mar 2015
Thanks a lot!

Hamza OUDICH on 25 Sep 2019
Be careful, the amplitude given by conv is not correct, it should be multiplied by the step difference in x since conv is an summation approximation of the integral in Matlab. Besides, 'same' removes the first elements to get a list with the same length as x..... so you lose SO MUCH information which can give you complete false result.
##### 2 CommentsShowHide 1 older comment
Hamza OUDICH on 25 Sep 2019
true! i forgot that one as well thanks!