Random Signals for Engineers using MATLAB and Mathcad Copyright 1999 Springer Verlag NY Example 5.4 Random Process for A + B t In this example we will compute the density function of the Random Process X(t) = A + B t where A and B are two Random Variables that are selected from uniform density function in the range -2 .. 2. We will first compute the density function of x(t) so that we can determine whether this Random Process is stationary or not. Since the Random Process is the sum of two uncorrelated Random Variables A and B t we must convolve the two uniform density functions to obtain the density function for x(t). The density function for A or a(x) is given as uniform in the range -2 < x < 2. The density function for B is uniform with the range -2 .. 2 but the density function of B t must be scaled for t so the density function, b(x,t) is a function of t. The two density function are plotted below xp=-7:.1:7; a=.25*(stepfun(xp,-2)-stepfun(xp,2)); t=1.5; b=.25/t*(stepfun(xp,-2*t-2)-stepfun(xp,2*t-2)); plot(xp,a,xp,b) axis([-7 7 0 .3]) 0.3 0.25 0.2 0.15 0.1 0.05 0 -6 -4 -2 0 2 4 6 The desired density function is the convolution of these two density functions and is computed by the integral of f5_4, which can be evaluated numerically by Matlab quad function. This numerical integration should be executed in the Matlab window and the error messages ignored. This integral may be evaluated numerically for different values of t. This is a lengthy computation and we have selected a nominal error tolerance in order to reduce the number of iterations needed by the numerical process of evaluating the integral and accepting the reduced accuracy of the results. The results are plotted below for t = 0.5, 1 and 1.5 and the analytic version for t=1.5. function y=f5_4(u,a,b,t,x) % f5_4 is the convolution density functions % where a,b = values of the two functions % t = time y1 = 1/(2*a)*(stepfun(u,-a)-stepfun(u,a)); y= y1.*(stepfun(x-u,-b*t)-stepfun(x-u,b*t))/(2*b*t); function y=stepfun(t,t0) %stepfun for i=1:length(t) y(i)=t(i)>t0; end figure for t=.5:.5:1.5 for i=1:length(xp) f(i)=quad('f5_4',-(2+2*t),2+2*t,[],[],2,2,t,xp(i)); end plot(xp,f); hold on; end hold off 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 -8 -6 -4 -2 0 2 4 6 8 The integral can alternately be evaluated analytically by dividing the integral into regions and performing the analytical intergrations directly. We illustrate this procedure for the case where t = 1.5. The integral must be divided into three regions corresponding to the range of values of . The plot of a and b t above shows the first of the three integrals and the corresponding regions. For the this case the integrand is shown in the plot and the value of -5 < < -1. syms t u tau t=sym(1.5); p1=int(1/4*1/(4*t),u,-2,tau+3) p1 = 1/24*tau+5/24 Similarly when -1 < < 1 and the region of integration is constant corresponding to the nonzero value of the integrand, we have p2=int(1/4*1/(4*t),u,-2,2) p2 = 1/6 The third case when 1 < < 5 and the region of integration is the mirror image of case one, we have p3=int(1/4*1/(4*t),u,tau-3,2) p3 = 5/24-1/24*tau We now build a plotting function using the step functions to enforce the range of validity of each expression and plot the results and compare to the numerical integration result for t=1.5. This gives us confidence that we have not made any errors in the selection of the regions of integration for the analytical integration. figure p=subs(p1,tau,xp).*(stepfun(xp,-5)-stepfun(xp,-1)); p=p+p2*(stepfun(xp,-1)-stepfun(xp,1)); p=p+subs(p3,tau,xp).*(stepfun(xp,1)-stepfun(xp,5)); pp=double(p); plot(xp,pp,xp,f) 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0 -8 -6 -4 -2 0 2 4 6 8 The differences in the numerical and analytical results at the end of the interval are a result of the tolerance setting on the numerical integration. Examination of the probability density functions show that they are functions of t and therefore the process used in this example is not a first order stationary process. We next compute the E[X(t)] using the expectation operator rules. The expectation E[X(t)] is found by replacing X(t) by A + Bt and then applying the expectation operation to the result or E[X(t)] = E[A + B t] = E[A] + t E[B] = 0 We have made use of E[A] = E [B] = 0 by the problem definition. In this case the process is shown to be wide sense stationary in the mean even though we have found that it is not first order stationary. We now will compute the correlation function for this process. It is a difficult computation to determine a functional representation for the second order density function. We will therefore compute the correlation function directly from the expectation operator. The results we obtain by noting the E[A B] = 0 because A and B are uncorrelated. The correlation function R(t1, t2) = E[X(t1) X(t2)] is found by E[X(t1) X(t2)] = E[(A + B t1) (A + B t2)] = E[A2] + t1 t2 E[B2] The E[A2] = E[B2] evaluated for a uniform density function in the range {-2.. 2} is 42/12 and we have Rt1 , t 2 4 1 t1 t 2 3 This function is not second order wide sense stationary and is not a function of = t1 - t2 and is a function of two variables. This correlation function must now be plotted in a two dimensional space. Using Matlab, we first prepare two vectors that correspond to the domain of the two variable of the function that we wish to plot. In order to obtain a plot with a viewport that shows the function clearly, we must view the plot at the correct angle figure [x y]=meshgrid(0:.1:2, 0:.1:2); R=4/3*(1+x.*y); mesh(R)