Question

In: Statistics and Probability

write a program in matlab to produce a discrete event simulation of a switching element with...

write a program in matlab to produce a discrete event simulation of a switching element with 10 inputs and 3 outputs. Time is slotted on all inputs and outputs. Each input packet follows a Bernoulli process. In a given slot, the independent probability that a packet arrives in a slot is p and the probability that a slot is empty is (1– p). One packet fills one slot. For a switching element if 3 or less packets arrives to some inputs, they are forwarded to the switching element outputs without a loss. If more than 3 packets arrive to the inputs of the switching element, only 3 packets are randomly chosen to be forwarded to the switching element outputs and the remaining ones are discarded. In your simulation the program will mimic the operation of the switch and collect statistics. That is, in each time slot the program randomly generates packets for all inputs of the switching element and counts how many packets can be passed to the output of the switching element (causing throughput) and, alternatively counts how many packets are dropped (when the switching element has more than 3 input packets at a given time slot) . Your task is to collect throughput statistics for different values of p (p = 0.05, 0.1 up to 1.0 in steps of 0.05), by running the procedure described above for each value of p and for many slots (at least a thousand slots per value of p). The more simulated slots, the more accurate the results will be. Based on this statistics, plot two graphs: 1) the average number of busy outputs versus p, and 2) the average number of dropped packets versus p.

Solutions

Expert Solution

outputs:

code in text format:

//Include the required header files.

#include <iostream>

#include <random>

#include <iomanip>

#include<time.h>

using namespace std;

//Define the array and variables

float p1[10]={};

float d1[10]={};

int l=0;

//Define the function BernoulliProcess()

int BernoulliProcess(float p, int packetGen)

{

//Define the variables

int passed =0;

int count=0, drop =0;

//Use the bernoulli's distribution.

default_random_engine generator;

bernoulli_distribution distribution(p);

//Iterate and generate the distribution.

//Increase the count.

for (int i=0; i<packetGen; ++i)

{

if (distribution(generator))

{

++count;

}

}

//Evaluate the passed packets from the count.

if(count >3)

passed = 3;

else

passed =count;

//Evaluate the dropped packets from the passed packets.

drop = packetGen-passed;

//Display the Probability, passed and dropped packets.

cout<<"Probability:"<<p<<endl;

cout<<"passed:"<<passed<<endl;

cout<<"Drop:"<<drop<<endl<<endl;

//Return the passed packets.

return passed;

}

//Define the main function.

int main()

{

//Generate the numbewr of packets in range 1 to 10.

srand(time(NULL));

int packetGen = rand() % (10 - 1 + 1) + 1;

//Dispaly the packet generated.

cout<<"Packet generated:"<<packetGen<<endl<<endl;

//Define the variables and array.

float p =0.05,d=0.5;

int p2[50]={},d2[50]={};

//collect throughput statistics for different values

//of p (p = 0.05, 0.1 up to 1.0 in steps of 0.05),

for(int j=0; j<50;j++)

{

//Evaluate the passed and dropped packets.

//and Probabilities.

p2[j]=BernoulliProcess(p, packetGen);

d2[j]= 10-p2[j];

p= p+0.05;

d =1-p;

}

int k=0;

//Display the average number of busy outputs versus p.

cout<<"The average number of busy outputs versus p:"<<endl;

for (float i=0.05; i<0.95; i=i+0.05)

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.05) << ": ";

for(int j=0;j<p2[k];j++)

cout<<"*";

cout<<endl;

}

cout<<endl;

k=0;

//Display the average number of dropped packets versus p.

cout<<"The average number of dropped packets versus p:"<<endl;

for (float i=0.05; i<0.95; i=i+0.05 )

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.05) << ": ";

for(int j=0;j<d2[k];j++)

cout<<"*";

cout<<endl;

}

//Return the value 0.

return 0;

}


Related Solutions

Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
In a discrete event simulation, a physical system, such as a galaxy or solar system, is...
In a discrete event simulation, a physical system, such as a galaxy or solar system, is modeled as it changes over time based on simulated forces. The objects being modeled define events that are scheduled to occur in the future. Each event, e, is associated with a time, te,in the future. To move the simulation forward,the event,e,that has smallest time,te,in the future needs to be processed. To process such an event, e is removed from the set of pending events,...
Record your voice signal in mp3  or .dat format. Write a Matlab program to produce an echo...
Record your voice signal in mp3  or .dat format. Write a Matlab program to produce an echo signal. Critically analyze the system and find out the value of delay in milli seconds required to get a good echo effect on the recorded voice. Demonstrate the results by playing the signal using sound command in Matlab. I need command in matlab from recorded signal to eco-signal and delay and play
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with...
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with integer values ranging between −100 to +100. Using LOOP command, determine the number of negative elements in the vector. For example, given A = [15 −6 0 -8 −2 5 4 −10 -3 −5], the number of negative numbers are 6.
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Write a program with the aim of performing an audiometry test at MATLAB. The program should...
Write a program with the aim of performing an audiometry test at MATLAB. The program should be as interactive as possible. For example, at first, which ear is to be tested should be chosen so that the sound is only given to that channel of the ear. In addition, whether the test frequency increases automatically or manually should be asked as a parameter. The frequencies of the person being tested should be entered by the user as well as whether...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures and create the signal after that add noise to it and finally demodulate it .. Please help me to do this project.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT