Random Signals for Engineers using MATLAB and Mathcad Copyright 1999 Springer Verlag NY Example 4.8 Convolution of Uniform Distributions We will show how the convolution integral can be used to compute the density function of the sum of two independent random variables. In particular, the convolution integral will be used to compute the density function of the sum of 0 -1 uniform density functions. We will show, by example, that the resulting density function approaches a gaussian shape with the mean and variance of the sum of the uniform distributions as we sum more independently distributed uniform random variables. Let us begin by analytically computing the density function of the sum of two random variable that each has a 0 - 1 uniform density function. Using the convolution formula we have syms w x u fw1=int(1,u,0,w) fw2=int(1,u,w-1,1) fw1 = w fw2 = 2-w This result was obtained by dividing the integral into two regions. The resultant density function, fx=fw1+fw2, can be rewritten using the step function for plotting purposes. xp=-.1:.05:2.1; fx=xp.*(stepfun(xp,0)-stepfun(xp,1))+(2-xp).*(stepfun(xp,1)stepfun(xp,2)); The uniform density function can be expressed in using the step function as y = (stepfun(x,0)-stepfun(x,1)) The convolution f1(w) alternately can be computed numerically. 2 f 1nw f u f w u du 0 We first form the integrand into a function f4_8_1.m function y=f4_8_1(x,u) % integrand for convolution % y=f4_8(x,[0 1]).*f4_8(u-x,[0 1]); y=(stepfun(x,0)-stepfun(x,1)).*(stepfun(u-x,0)-stepfun(u-x,1)); This is a lengthy computation since the entire integral must be computed for each time step and should be executed directly in the Matlab window and the messages ignored f1n=[]; for i=1:length(xp) f1n(i)=quad8('f4_8_1',0,2,[1.e-4 1.e-4],[],xp(i)); end The two forms of the convolution can be plotted to show that they are identical. A gaussian with the mean value of ax = 0.5 + 0.5 and a variance of x2 = 1/12 + 1/12 is also plotted for comparison fg=gauss_den(xp,1,sqrt(2/12)); plot(xp,fx,xp,f1n,xp,fg) 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -0.5 0 0.5 1 1.5 2 2.5 The summation of three uniformly distributed random variables can be found by summing the result of two random variables as we have done above, with the additional variable. The convolution of the f1(x) and f(x) can be computed analytically by setting up the integral for each of the three regions. The first region where 0 w 1 is shown in the figure 1.5 fx y 1 0.5 0 0 1 xi The integral for this region is 0 x 1 f21=int(u,u,0,w) f21 = 1/2*w^2 2 For the second region where 1 < w 2 we set up two integrals as 1.5 fx y 1 0.5 0 0 1 x 2 i Evaluating each integral and combining the results we have f22=int(u,u,w-1,1)+int(2-u,u,1,w) f22 = -w^2+3*w-3/2 For the third region we have the integral. 2 w 3 1.5 fx y 1 0.5 0 0 1 2 x 3 i f23=int(2-u,u,w-1,2) f23 = 9/2-3*w+1/2*w^2 The plotting formulas use step functions to set up the valid regions of each segment function y=f4_8(x,u) % unit uniform density function % u is a 2 vector with u(1) starting ans u(2) stopping y=stepfun(x,u(1))-stepfun(x,u(2)); xp=-.1:.05:3.1; f2=subs(f21,w,xp).*f4_8(xp,[0 1]) + subs(f22,w,xp).*f4_8(xp,[1 2]) + subs(f23,w,xp).*f4_8(xp,[2 3]); A gaussian with the mean value of ax = 0.5 + 0.5 + 0.5 and a variance of x2 = 1/12 + 1/12+ 1/12 is plotted for comparison fg=gauss_den(xp,3/2,sqrt(3/12)); plot(xp,f2,xp,fg) 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 The process can be continued a good approximation to a gaussian achieved. For the second case the numerical integral was not set up since it would take a long time to evaluate. function y=gauss_den(x,a,sx) % gaussian probability density function % a, sx are mean and std deviations % and x is the input variable fp=-1/2*((x-a).^2/sx^2); y=1/(2*pi*sx^2)^(1/2)*exp(fp);