7 views (last 30 days)

I convoluted gamma distributed having x axis range from 1 to 100 (m=100) and normal distribution with x axis range from -25 to 24 (n=50). By using conv function in MATLAB I got m+n-1 = 149 values. How can I determine the corresponding X axis range, as I need corresponding x axis values for these 149 values obtained after convolution. I have attached the sample code for reference.

x= -25:1:24; x1 = 1:1:100;

normal = normpdf(x,0,1); gamma = gampdf(x1,20,2);

w = conv(gamma,normal);

David Goodmanson
on 11 Oct 2020

Hi dinesh,

Here is an example with two normal (gaussian) pdfs. Arrays x and f(x) describe one of them, and arrays y and g(y) describe the other. To make it general, x and y have different ranges and different number of total points, However, to keep things sensible each of the x and y arrays have the same spacing. The convolution of f and g, called fOg here, is a function fOg(z) of the array z. The key point is that the starting point of the z array is the sum of the starting points of the x and y arrays.

In this example, f(x) peaks at x = 5 and g(y) peaks at y = 9 so you would expect the convolution, which describes the pdf of (x+y), to peak at z = 14 which it does. (Since a gaussian is symmetric about the peak, the peak value and the mean value are the same. And the convolution of gaussians is still a gaussian). If the array limits of x and y are changed, the peak remains at z = 14 (unless the array boundaries start to crowd into the tails of the gaussians and make them not gaussians).

I didn't pay attention to normalization of the pdfs here since the main point is to describe the convolution position. However it should still be true that the integrals described in the last two lines are equal, which they are.

del = .001; % array spacing

xa = 1; % x array min, max

xb = 7;

nx = (xb-xa)/del; % number of x arrray intervals

x = xa + del*(0:nx);

f = exp(-5*(x-5).^2); % mean = 5

ya = 5; % y array min, max

yb = 12;

ny = (yb-ya)/del;

y = ya + del*(0:ny);

g = exp(-4*(y-9).^2); % mean = 9

fOg = conv(f,g)*del; % multiply by del so conv sum --> riemann integral

z = xa+ya+del*(0:nx+ny);

figure(1)

plot(x,f,y,g,z,fOg)

grid on

% these two normalization-type integrals should agree,

% even if none of the functions are normalize to 1

trapz(x,f)*trapz(y,g)

trapz(z,fOg)

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1048611

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1048611

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1049821

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1049821

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1049831

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1049831

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1050521

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609596-x-axis-for-convoluted-function#comment_1050521

Sign in to comment.