MATLAB: How to generate random numbers from a distribution which is the convolution of exponential distributions

generate random numbers speckle exponential distribution

Hello,
I would like to simulate two independent laser speckle intensities. Based on J. Goodman's book (Speckle Phenomena in Optics, p.39), the formula for the intensity distribution is the convolution of two exponential distributions:
p(i) = i/(I^2) exp(-i/I)
with I being the average intensity.
Is there already a function doing this? If not, how should I proceed to write it myself?
Thanks for the answer!
Cheers Guillaume

Best Answer

i = 0:0.1:10; I1 = 1; I2 = 1; % define as per your requirment
p1 = i/(I1^2).*exp(-i/I1); % first exponential function
p2 = i/(I2^2).*exp(-i/I2); % second exponential function
y = conv(p1,p2); % convolution of two functions
N = length(y);
r = randi(N,[1 N]); % generate random indices, uniform in this case
yourRandomNumber = y(r) % access y data at random indices