Simple question about plotting a convolution

41 ビュー (過去 30 日間)
aurc89
aurc89 2015 年 3 月 25 日
編集済み: Bruno Luong 2019 年 9 月 26 日
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!

採用された回答

Hamza OUDICH
Hamza OUDICH 2019 年 9 月 25 日
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 件のコメント
Bruno Luong
Bruno Luong 2019 年 9 月 25 日
編集済み: Bruno Luong 2019 年 9 月 26 日
+1, if the data does not have constant step, using CONV gives incorrect result.
You probably need to interpolate the y data with a constant step, THEN apply conv.
Can't believe such answer was accepted.
Hamza OUDICH
Hamza OUDICH 2019 年 9 月 25 日
true! i forgot that one as well thanks!

サインインしてコメントする。

その他の回答 (1 件)

Andrew Newell
Andrew Newell 2015 年 3 月 25 日
編集済み: Andrew Newell 2015 年 3 月 25 日
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.
  1 件のコメント
aurc89
aurc89 2015 年 3 月 25 日
Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by