Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Random Project 222

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Department of Electrical and Computer Engineering & Computer Science

ELEC 3320: Random Signal Analysis


Project: Monte Carlo Simulations

Directions:

Read carefully the complete assignment


Research and implement the simulation methods outlined in the handout
Explain thoroughly your work and provide justification of your approach
Your scripts must be unique and well documented

Keywords:

1. Monte Carlo simulations


2. Seed number
3. Bins
4. Histogram
5. Sample mean and variance
6. Congruence relations
7. Pseudo-random variates
8. Central limit theorem
9. Linear congruential algorithm

Introduction:

Because the impacts of new technology are not as well understood as the outcomes of a coin toss, we
often prefer to simulate new technological outcomes. To simulate means literally to imitate; simulation,
therefore, imitate practical events. It is naturally desirable to find out through simulations that the
engine of a new airplane is likely to fail under certain combination of factors, rather than discover the
failure under actual conditions. Simulations have therefore, become a very crucial aspect of modern
technology. Simulations are usually based on a random number sequence, and often known as Monte
Carlo simulations.

Pseudo-random number generators:

The subject of producing random numbers through digital computers began in the 1940s with John Von
Newmans famous middle of the squares algorithm. Since John Von Newmans algorithm there has
been much research into random number generation algorithm as well as tests to determine if the
resulting sequence is truly random.

Almost all computer systems have a random number generator, which are subroutines that provide a
new random number with each call. The names of the random generator depend on the computing
environment. To generate truly random numbers is a complex task, as soon as one uses a program to
generate them, they can no longer be called truly random. This is why they are more correctly referred
to as pseudo-random numbers. These numbers pass all the essential properties of random numbers,
but in fact are deterministic and reproducible, and thus can only approximate a true random sequence.

Three criteria are usually employed to evaluate the suitability of random number generation techniques:

Page 1 of 5
1. Length of the period
2. Uniformity
3. Correlation

The first criterion means that the generator should be of long period, much longer than the amount of
random numbers needed for simulation. The second criterion means that each value should occur
roughly an equal number of times, presuming the sample size is sufficiently large. The third criterion
means no discernible correlation between elements of the sequence.

Part-1:

Linear Congruential Algorithm:

One of the most common approaches for generating sequences of pseudo-random values is called the
linear congruential method, proposed by D. H. Lehmer in 1948. This algorithm is based on the following
recursive formula:

x n 1 A x n C mod M , n 0,1,2,..., M 1 (1.1)

Where

x n 1 Next element of the sequence

x n Current element of the sequence


A Constant multiplier, 0 A M
C Constant increment, 0 C M
M Constant modulus, M 0

The algorithm is based on congruence relations, an example of which is, 3=13 mod 10, which means that
3 is the remainder obtained when 13 is divided by 10.

Random number generators require that the user specify an initial value, x 0 , called the seed number
and is a value chosen between 0 and M 1 . The subsequent numbers in the sequence are obtained
by iterating equation 1.1 . The parameters M, C, and M are carefully chosen constants. A poor choice
for the constants can lead to sequences with poor random properties. There are well-established rules
on the selection of these parameters; one fairly obvious goal is to make the period (the number of
integers before the sequence repeats) long, this implies a large value for M (the period of the sequence).
The recursion equation 1.1 produces a sequence of numbers which lie between 0 and (M-1). The
linear congruential algorithm is very fast, requiring only a few operations per call, and thus suitable for
programmable digital signal processing chips.

Selection of Parameters:

The parameters M, C, and A in the linear congruential generator are chosen to make the sequence as
random as possible. Choices for these values must meet the following necessary and sufficient
conditions contained in the theorem proved by Hull-Dobell (1962).

Page 2 of 5
1. C must be relatively prime to M (thats, their greatest common divisor is 1)
2. B=A-1 is a multiple of p, for every prime p that divides M
3. B is a multiple of 4 if M is a multiple of 4.

Deliverables:

1. Write a MATLAB script using the linear congruential algorithm to generate 10000 pseudo-random
numbers in the interval (0, 1). Make sure that the parameters are properly selected.
2. Obtain the sample mean and standard deviation of generated numbers using the MATLAB functions
mean and std.
3. Plot the histogram of the sequence generated in part (1). Experiment with different bins, and
describe the impact.
4. Use the rand function of MATLAB to generate 10000 pseudo-random numbers and plot the
histogram including the sample mean and standard deviation
5. Compare the congruential algorithm to the algorithm used in rand

Part-2:

The standard pseudo-random number generator that is built-in into most high-level language compilers,
such as FORTRAN, Pascal, C, or JAVA is a uniform number generator. Under MATLAB, the function rand
generates pseudo-random numbers that are uniformly distributed over the interval (0, 1). The
generator can in turn be used to obtain variates from a variety of distributions. In this exercise, we shall
tackle the generation of random variates that fit the Gaussian distribution.

The Gaussian distribution is perhaps the most frequently used distribution. It is widely used in all
branches of science and engineering. The reason for its practical importance stems from a cornerstone
result known as the central limit theorem, proved by Laplace in the late 18th century. It is called the
Gaussian distribution, after the mathematician who first described it; it is also known as the bell curve,
because of its shape. The Gaussian distribution is used to depict the distribution of such things as
heights of male or female adults; numerical results of academic tests; lifetime of things subject to
wearing out, such as light bulbs, automobiles, or most importantly to model noise.

There are various ways of obtaining Gaussian pseudo-random variates on a computer. Some of the
popular methods are:

1. The method based on the central limit theorem


2. The Box-Muller algorithm

Method based on the central limit theorem:

I will fully describe the method based on the central limit theorem, which simply states that if many
independent, identically distributed (IID) random variables (typically uniform) are added, their sum
tends to have a Gaussian distribution. The trouble with this approach is that the tails of the distribution
tend not to be accurate. For the simulation of communication systems, this can be quite problematic
since it is precisely the tails in which we are interested. Alternate methods are available for getting
variates whose distribution yields a better approximation of the Gaussian tails.

The algorithm:

Page 3 of 5
Suppose we wish to generate a sequence x n from a Gaussian distribution with a specified mean m and
standard deviation s. The procedure involves taking the sum of K random variables U1 ,U 2 ,...,U K ,
where each U i is uniformly distributed over the interval (0, 1). According to the central limit theorem,
the random variable
K
X U i (1.2)
i 1

Tends to be Gaussian for K sufficiently large.

Since,

Ui U 0,1 E U i 1 2 and V U i 1 12
E X K 2 and V X K 12

The random variable Z defined by


K
K
X m U i
2
Z i 1
N 0,1 (1.3)
s K
12

Therefore, Gaussian variates xi with mean m and standard deviation s can be generated via the
following equation
1
12 2 K K
xi s ui m (1.4)
K i 1 2

The value of K can vary from 10 to any higher number, however, K=12 offers some computational
advantage. The higher the value of K, the more accurate the result will be and the longer it will take to
compute the desired variates.

Deliverables:

1. Write a MATLAB script to generate 10000 Gaussian variates according to the procedure based on
the central limit theorem (use m=2 and s=5). To generate the uniform variates make use of the
MATLAB function rand.
2. Compute the sample mean and the standard deviation using the MATLAB functions mean and std
respectively. Compare these parameters to the actual mean and standard deviation. Is the
difference significant? Does the difference vary as the sample size changes?
3. Draw the histogram of the Gaussian variates generated in part (1). Use K=20, and K=100.
Investigate the impact of K.
4. MATLAB has a standard function called randn which generates random numbers selected from a
Gaussian distribution with mean 0 and standard deviation of unity. Use a linear transformation to

Page 4 of 5
generate Gaussian variates with mean m=2 and standard deviation s=5. Draw the histogram of the
resulting variates and compare to the histogram obtained in part (3).

The Box-Muller approach:

Deliverables:

1. Research and document the Box-Muller method


2. Write a MATLAB script to generate Gaussian pseudo-random numbers according to the Box-Miller
method
3. Draw the histogram of the generated data
4. Compare the method based on the central limit theorem to the Box-Muller method

Page 5 of 5

You might also like