ex5m3_6.doc

advertisement
Random Signals for Engineers using MATLAB and Mathcad
Copyright  1999 Springer Verlag NY
Example 3.6 Transformation of Discrete Random Variables
In this example we will use a discrete distribution to demonstrate how we may transform the
distribution by a change in variable. This distribution is input by a table of PX = P[x = x i] and xi. We
perform a normalization check.
PX=[.1 .15 .2 .25 .1 .05 .15]
x=-3:3
PX =
0.1000
0.1500
0.2000
0.2500
0.1000
0.0500
0.1500
x =
-3
-2
-1
0
1
2
3
sum(PX)
ans =
1
The transformation formula is given below
y=x.^2;
This transformation maps positive and negative value of x into positive y values. The probabilities that are
associated with positive and negative values of xi must be summed because they map into the same values
of yi. We define a function that takes the yi that corresponds to each xi and sums the probabilities when
they are equal.
PY=zeros(1,4);
for j=4:7
for i=1:7
PY(j-3)=PX(i)*(y(i)==y(j))+PY(j-3);
end
end
We apply this function and only use the y values from 0 through 9 or yi with index values 3,4 .. 6.
function y=bin_dist(b,t,t0)
% BIN_DIST is the cumulative distribution for a
% Discrete distribution where b = vector probabilities
% t = time vector and t0 is where the steps take place
% b and t0 must be the same length
k=length(b);
y=zeros(1,length(t));
for i=1:k
y = b(i)*stepfun(t,t0(i))+y;
end
t=0:.01:7;
ti=t-3.5;
plot(ti,bin_dist(PX,ti,x))
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-4
-3
-2
-1
0
1
2
3
4
We plot the cumulative distribution function for x and the density function using the bar chart to represent
the impulses
bar(PX,.1)
xlabel('x index')
0.25
0.2
0.15
0.1
0.05
0
1
2
3
4
x index
5
6
7
A similar procedure is followed for y
figure
t=0:.01:10;
ti=t-0.5;
plot(ti,bin_dist(PY,ti,y(4:7)))
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-2
0
2
4
6
8
10
bar(y(4:7),PY,0.1)
xlabel('y index')
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
0
1
4
y index
9

Download