Project1_sol_f08

Project1_sol_f08 - ECE 547 Project #1 – Fall 2008 1a) 1b)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 547 Project #1 – Fall 2008 1a) 1b) P(U > x) for values of x (0.5,1) can be plotted as the following: Figure 1 P(U>x) In order to calculate P (U>x), the interval [0, 1] is divided into intervals of width 0.01. For each value of xi the corresponding frequency fi out of a total of N=105 numbers such that U> xi was calculated. Then using P (U> xi) = fi / N, the probabilities were calculated at each of the xi.. The pairs of points (xi, P (U> xi)) were plotted Note that P(U>x) = 1‐x. The plot is as expected. 2a) Generation of Exponentially Distributed Random Numbers The cumulative distribution function of the exponentially distributed random variable is FX ( x) = ∫ f X ( x)dx 0 x where f X ( x) = λ e− λ x is the pdf of the exponentially distributed random variable with parameter λ . Choose a function G ( ) such that G (x) = FX ( x) = ∫ f X ( x)dx 0 x Now we can generate an exponentially distributed random variable X by passing the output of the uniform random number generator through G −1 (.) . G (x) = 1 − e− λ x X = G −1 (U ) = −1 λ log(1 − U ) Since U is a uniformly distributed random variable in [0, 1] hence (1‐U) is also a uniformly distributed random variable in [0, 1]. Hence an exponentially distributed random variable can be obtained from a uniformly distributed random variable by using X= G −1 (U ) = −1 λ log(U ) Generation of Random Numbers with Poisson Distribution The technique used above for the generation of an exponentially distributed random variable from a uniformly distributed random variable using the inverse CDF method works well for functions that are easily invertible. The problem that we encounter while using this technique to generate a Poisson distributed random variable Y is that the PMF of a Poisson random variable is not easily invertible. In order to circumvent this problem, we can us the special property of Poisson random variables according to which if an arrival process is Poisson, the interarrival times are exponentially distributed. Consider a Poisson process with parameter λ and let X0 be the time of the first arrival and Xk be the interarrival time between the (k‐1)th and kth arrival. We know that each of the Xk is independent, identically, distributed exponential random variables with parameter λ . Considering a time duration of 1 second in which n Poisson arrivals have occurred, we have the following relation P({N (1) = n}) = P({ X 0 + X1 + X 2 + ......... + X n } > 1) = where the PMF of the Poisson process is given by e− λ λ n n! P({N (t ) = n}) = e − λ t (λ t ) n n! Thus from the above relation we obtain that the minimum n ∈ N where N is the set of natural numbers for which the relation { X 0 + X1 + X 2 + ......... + X n } > 1 holds, is Poisson distributed with parameter λ . But knowing that each of the Xk be i.i.d. exponential random variable, we can write the above expression to be equal to Xk = −1 λ log(U k ) −1 { −1 λ log(U 0 ) + −1 λ log(U1 ) +…………… + λ log(U n ) }>1 { −1 λ log(U 0U1U 2 .......U n ) }>1 U 0U1U 2 .......U n < e − λ Y=n where Uk is an i.i.d uniform random variable in [0, 1]. So the minimum value of n is a Poisson random variable Y with rate parameter λ . Thus by using the above relation we were able to generate Poisson random variable from uniformly distributed random variables. As in the earlier case the Matlab routine rand ( ) was used to generate uniform random numbers. 2b) Plot P(X>x) for E(X) = 10 .Since the mean of an exponential random variable with rate parameter λ is equal to λ −1 , the rate parameter λ was determined to be 0.1. The plot of P(X>x) Vs x for E(X) = 10 was plotted for x ∈ [0, 20] where the entire interval was divided into equispaced intervals each of width 0.01. For each value of xi the corresponding frequency fi out of a total of N=105 numbers such that X> xi was calculated. Then using P (X> xi) = fi / N, the discretized probabilities were calculated at each of the xi. Using the plot ( ) command in Matlab the pairs of points (xi, P (X> xi)) were plotted. There were two plots obtained in which the vertical axis was in normal scale as well as in logarithmic scale. Plot of P(X > x) Vs x with E(X)=10 1 0.9 0.8 P(X > x) in logarithmic scale 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 Plot of P(X > x) Vs x with E(X)=10 P(X > x) in normal scale 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.2 0 2 4 6 8 10 x 12 14 16 18 20 0.1 0 2 4 6 8 10 x 12 14 16 18 20 Figure 2 P(X>x) for Exponential Distribution – normal and log scale Note that P(X>x) in Figure 2 is linear in log‐scale. P(Y>y) can be plotted as the following (Note that Y can have only discrete values): Figure 3 P(Y>y) for Poisson Distribution ‐ normal and log scale 3a) For problem 1 and 2 of the project we built random number generators to generate exponentially distributed and Poisson distributed random numbers from uniform random numbers. In order to simulate an M/M/1 queue, we use the property of Poisson arrivals, that the interarrival times are exponentially distributed. The queue and the server are initially empty. The simulation basically simulates two events: i)Arrival of a packet and ii) departure of a packet. The simulation is started by considering an arrival of a packet at time t=0. We assign it a service time that is chosen from the exponential distribution with rate μ=10 and choose a new time for arrival of the next packet from the exponential distribution with rate λ=9. The time for arrival or the time for departure is denoted by a variable called, say time of last event. 3b) The probability of the queue being in state n is just equal to the fraction of total simulation time that has n number of packets in the queue. So we record the number of packets in the system in between arrival and departure events and add the differential interval dt to the corresponding state n. Hence Pn vs. n can be plotted as the following: Figure 4 Pn vs n Plot of Pn vs. n for LAMBDA=5 and MU=6 in a M/M/1 queue 0.18 0.16 0.14 0.12 0.1 Pn 0.08 0.06 0.04 0.02 0 Simulation Result Theoretical Value 0 5 10 15 n 20 25 30 35 From theory we know that the probability of states in an M/M/1 queue is given by Pn = ρ n (1 − ρ ) where ρ = λ / μ , We can compare theoretical values and simulation results (Figure 4). 3c) In our simulation, E [N] and E [W] can be calculated by: E [N] = ∑N k T k where N k is the number of customers in the system at step k in our simulation and T is the actual time, when the simulation is finished (not the step number). Λ (T ) E [W] = ∑ wj j =0 Λ(T ) where Λ(T ) is the total number of arrivals by time T and w j is the waiting time of the jth packet. We calculate the waiting time of the jth packet by storing the arrival and the departure times of the jth packet in two separate arrays and obtaining the difference and summing them. From theory we know that the expected number and expected delay in a M/M/1 queue with ρ is given by =λ/μ E[ N ] = 1− ρ ρ =5 and E[ w] = 1− ρ μ 1 =1 The expected number in the system and the expected delay obtained from one run of our simulation is E[N]=4.969 and E[ w] = 1.004 s, which are very close to the theoretical values. 4a) In an M/Ek/1 queue the arrival process is Poisson, the service times are Erlang‐k. The Erlang‐k phase distributed random numbers with parameter (k, μ) are just the sum of k i.i.d exponentially distributed random variable each with a rate parameter of kμ. Hence we obtain an Erlang‐k phase random number with rate μ from exponentially distributed random number with rate kμ. Ek = X1 + X 2 + X 3 + ........ + X k Using the relationship obtained earlier between exponential random variable and uniform random variable we can write Ek = −1 log U1 + −1 log U i + ......... + −1 log U k = −1 log(U1U 2 ........U k ) kμ kμ kμ kμ where each of the U i is an i.i.d uniform random variable in [0,1]. 4b) Figure 5 M/E4/1 ‐ Queue M/E /1 Queue E(N)=3.656347 E(W)=0.726729 4 0.2 0.18 0.16 0.14 0.12 P n 0.1 0.08 0.06 0.04 0.02 0 0 5 10 15 20 n 25 30 35 40 E [N] = 3.656 and E [W] =0.727 s. From the plot we observe that the probability of states in an M/Ek/1 Queue increases and then decreases exponentially. We find that the expected number in the system for M/Ek/1 queue E [N] = 3.656 which is less than the expected number in the system for M/M/1 queue. Furthermore, the expected waiting time E [W] is also smaller. One of the reasons for this can be attributed to the fact that as we increase k from 1 we move from the M/M/1 case to the more deterministic M/D/1 case. The variance of an Erlang‐k random variable with parameter (k , μ) is given by Var ( E (k , μ )) = 1 kμ2 Thus we see that for large values of k the variance is almost zero which yields an M/D/1 queue because the variance of an M/D/1 queue zero. According to P‐K formula, E[ N ] = ρ⎡ ρ 2 2⎤ ⎢1 − 2 (1 − μ σ ) ⎥ 1− ρ ⎣ ⎦ So for M/E4/1 queue, the theoretical value of E[N] and E[w] is E[N]=55/16=3.4375 E[w]=11/16=0.6875 4c) In the Problem 4c we were asked to plot the expected number in the system for different values of utilization for the case k=40 in a M/Ek/1 queue and a M/D/1 queue. 10 9 8 7 6 E(N) 5 4 3 2 1 0 M/E50/1 from Simulation M/D/1 from Simulation 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 ρ From the plot we can observe that the M/Ek/1 queue converges to the M/D/1 queue in case of large k. The expected number for M/D/1 queue is obtained from the P‐K formulas that were discussed in class. Using the P‐K formulas, we have for the M/D/1 queue: E[ N ] = The variance of Erlang‐k random variable is: (1 − ) 1− ρ 2 ρ ρ Var ( E (k , μ )) = 1 kμ2 Thus we see that for large values of k the variance is almost zero, which yields an M/D/1 queue because the variance of an M/D/1 queue zero. Furthermore, for large k E[N] of M/Ek/1 is also E[ N ] = since the variance becomes 0. (1 − ) 1− ρ 2 ρ ρ ...
View Full Document

This note was uploaded on 01/27/2010 for the course ECE 547 taught by Professor Xiaojunlin during the Spring '09 term at Purdue University.

Ask a homework question - tutors are online