Sie sind auf Seite 1von 6

Functions

of Random Variables
by Laurence G. Hassebrook
1-27-2013

Using only the uniformly distributed sample values from the pseudo random number generator
rand() of MATLAB, generate Gaussian and Rayleigh distributions using techniques from
functions of random variables Generate noise sequences of length N. Bin them in Nbin=100
bins and normalize to represent pdf estimates.

1. Uniform Distributions

Generate two uniform distributions, [0,1] and the other with 0 mean and unit standard deviation.
The initial Matlab code is

%% func of 2 rv and associated pdf estimation


clear all;
N=10000;
Nbin=100;

which clears all the values and sets the vector length and histogram resolution. The pseudo-
random vector is generated as

%% uniformly distributed noise


urv=rand(1,N);
figure(1);
plot(urv);
title('Uniform Noise (0,1)');
xlabel('n');
ylabel('x');
print -djpeg Fig1_UniformNoisefigure(1);

Figure 1.1: Uniform Noise Sequence.

1
xu ,1 ~ U 0,1 is 0.5 and the = 1/sqrt(12). To generate a uniform r.v. with 0
The mean value of ~
mean and unit variance we subtract the mean value and then divide by the STD such that:

~ x 0.5
xu , Norm u ,1 (1)

The Matlab code for this is

urv1=(urv-0.5)*sqrt(12);

2. Gaussian Distributions from Uniform Distributions

Generate two uniform distributions, [0,1] that are independent and identically distributed.
The Matlab code is

ur1=rand(1,N);
ur2=rand(1,N);

xu ,1 n and the second as ~


If we represent the first sequence as ~ xu , 2 n , then two iid Gaussian
sequences can be generated as:

g~1 n 2 ln ~
xu ,1 n cos2 ~
xu , 2 n (2)

g~2 n 2 ln ~
xu ,1 n sin 2 ~
xu , 2 n (3)

One of these sequences is plotted in Fig. 2.1.

Figure 2.1: Gaussian sequence generated from two uniform sequences.

The mean value of this Gaussian sequence is 0 and the =1;

2
3. Rayleigh Distributions from Gaussian Distributions

Generate Rayleigh distribution from the two Gaussian sequences generated in Section 2. The
function used to generate a Rayleigh r.v is

r n g~12 n g~22 n
~ (4)

The resulting Rayleigh sequence is shown in Fig. 3.2.

Figure 3.1: Rayleigh distributed sample sequence.

Note that the Rayleigh samples are always positive. The mean value of a Rayleigh r.v. is related
to the standard deviation, = 1, of the Gaussian r.v.s used to generate it such that


r (5)
2

and the Rayleigh standard deviation is

4
r (6)
2

where the Rayleigh pdf is given by

r 2
f ~r r
r 2 2
e , for r > 0 (7)
2

3
4. Normalizing the Distributions to have zero Mean and unit Variance

If often happens that we will be presented with signal data in the way of a picture, photograph or
image as seen in Figs. 1.1, 2.1 or 3.1. Usually these noise signals are added to an underlying
signal of some sort. It is helpful to be able to visually estimate the relative noise level compared
with the signal level as well as the type of noise that it is. In this section, we normalize the
uniform, Gaussian and Rayleigh noise sequences to have zero mean and unit variance. We then
view them side by side and note the similarities and differences between the noise signals.

The non-normalized signal distributions are shown in Fig. 4.1.

Figure 4.1: The three histogrammed distributions superimposed to show range and amplitude of their estimated
distributions.

The normalization, of the signals in Sections 1 through 3, requires that (1) the known ensemble
mean value is first subtracted from the signal values (2) followed by division by the standard
deviation. The resulting signals are plotted in Fig. 4.1.

4
Figure 4.2: Normalized distributions. (left) Uniform, (center) Gaussian and (right) Rayleigh.

If you squint your eyes and look at Fig. 4.2, you should see a band of darkness that ranges from
about -1.5 to 1.5. Knowing this, you would know an estimate of the STD as 1.0 or 2/3s of what
you visualize as the dense data band. Another thing you note is the sharpness of the top and
bottom edge. A uniform edge is sharp on top and bottom, Gaussian is fuzzy top and bottom
and Rayleigh is sharp on the bottom edge and fuzzy on the top. This gives you an approximation
of the distribution shape. If you were to see this noise added to a deterministic binary signal, you
should be able to estimate the signal amplitude divided by the standard deviation which is the
square root of the Signal-to-Noise Ratio (SNR). We can see even more if we were to histogram
the 4 signals (ie., 2 of them are iid Gaussian sequences) as shown in Fig. 4.3.

5
Figure 4.3: Histograms of normalized sequences.

Das könnte Ihnen auch gefallen