Why convolution of two functions changes with changing the range of x axis ?

35 次查看(过去 30 天)
Dear friends,
Could anyone kindly help me regrading a confusion during finding convolution of two functions.
I am trying to calculate convolution of two Gaussian function using 'conv' function in MATLAB.e.g.
f = @(x) gaussmf(x,[0.4,0]);
h = @(x) gaussmf(x,[0.8,0]);
Now if I consider three different cases with different xrange
(I) x = -4:.01:4;
y1 = conv(h(x),f(x));
xp=-8:0.01:8
plot(xp,y1)
(II) x=-1:0.01:4;
y2= conv(h(x),f(x));
xp=-2:0.01:8
plot(xp,y2)
(III) x=0:0.01:4;
y3=conv(f(x),h(x))
xp=0:0.01:8
plot(xp,y3)
Don't you think these above three plots (y1,y2,y3 vs x) should lay on top of each other except the starting point of the plots will be different. I expected something like this
Because the convolution of two Gaussians is another Gaussian and we can calculate the convolution numerically very easily. I have calculated the convolution numerically an got the above ans.
But in MATLAB using conv function I am getting different ans
My question is why changing the xrange of two function changing the convolution results although according to theory, convolution function will not change. As my knowledge in this field is limited and may be I am conceptually wrong.
Any help will be highly appreciated.
Thanks
Deb

回答(2 个)

Image Analyst
Image Analyst 2015-4-8
Why do you think there won't be more elements when you convolve? The output length will be the sum of the two signal lengths because they just start overlapping when the right tail of the sliding function overlaps the left tail of the "still" function, and then they don't stop overlapping until the left tail of the sliding function just barely overlaps the right tail of the "still" function. Now if you look at where the left element of the sliding function is when those events happen, you'll realize that the left element (and of course all the elements) of the sliding signal moves twice as far.
  1 个评论
Debdas
Debdas 2015-4-8
Thanks for your answer
I am agree with the fact that there will be more elements and the output length will be sum of the length of the two signal. Even if we compare the convolution got from analytical solutions with which I got from matlab for case 1 (x-range -4 to 4) we can see from the two figures that both are same and agree with what you are saying. but in 2nd or third case (when the x-range is from -1 to 4 or 0 to 4) why the nature of the convolution plot is significantly different ? there is no issue with the moving the signal twice far along x. Here my concern is convolution with same function my second and 3rd case should reproduce -2 to 8 and 0 to 8 part of the -8 to 8 range figure which numerical solution does but not from MATLAB.
Thanks Again
Deb
P.S: In the 2nd figure, case 2 and case 3 has been wrongly exchanged.

请先登录,再进行评论。


Stephen23
Stephen23 2015-4-8
编辑:Stephen23 2015-4-8
The conv documentation clearly explains how the second argument shape changes the output length:
shape — Subsection of convolution 'full' (default) | 'same' | 'valid'
Subsection of the convolution, specified as 'full', 'same', or 'valid'.
  • 'full' Full convolution (default).
  • 'same' Central part of the convolution of the same size as u.
  • 'valid' Only those parts of the convolution that are computed without the zero-padded edges. Using this option, length(w) is max(length(u)-length(v)+1,0), except when length(v) is zero. If length(v) = 0, then length(w) = length(u).
  3 个评论
Stephen23
Stephen23 2015-4-8
"This means the nature of the function obtained after convolution will change depending on x-range": yes indeed, and this appears to be the confusion here. Numerical convolution is not the same as a "mathematical" or function convolution. For a start it is not possible to perform it from -Inf to +Inf, and selecting the endpoints will make a big difference to the output.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by