You are on page 1of 15

# Introduction to Random Processes

Project 2
Problem 1:
Mean and variances of various distributions:
1) Normal
Mean: 0.0015
Variance: 16.0306
2) Bernoulli:
Mean: 0.5007
Variance: 0.2500
3) Binomial:
Mean: 0.9008
Variance: 0.9025
4) Erlang:
Mean: 2.9917
Variance: 2.9744
5) Exponential:
Mean: 0.9954
Variance: 0.9958
6) Poission:
Mean: 2.0035
Variance: 2.0187

## Source code for each pdf:

% code plots different random variables
% initialization of variables
clear all
clc
x=-14:0.1:14;
n=60;
lambda=2;
k1=0:n;
k=0:15;
a=1;
n=3;
q=factorial(n);
p=0.5;
pdf1=normpdf(x,0,4);
pdf2=binopdf(k,10,0.9);
t1=0:0.1:5;
pdf3=exppdf(t1,1);
pdf4=poisspdf(k1,lambda);
t5=[0:10];
t=(t5./a).^(n-1);
pdf5=(t).*(exp(-(t5./a))).*(1./(a.*q));
t6=[0:1];
pdf6=bernpdf(p);
figure
plot(x,pdf1);

## xlabel('x' );ylabel('pdf');title('Normal distribution')

figure
plot(k,pdf2);
xlabel( 'x');ylabel( 'pdf' );title('binomial distribution')
figure
plot(t5,pdf5);
xlabel('x' );ylabel( 'pdf' );title('Erlang distribution')
figure
plot(t1,pdf3);
xlabel(' x ');ylabel( 'pdf' );title('Exponential distribution')
figure
plot(t6,pdf6);
xlabel( 'x' );ylabel(' pdf ');title('Bernoulli distribution')
figure
plot(k1,pdf4);
xlabel( 'x' );ylabel(' pdf ');title('poisson distribution')

## Histograms for each random variable

Outputs:
Normal distribution

0.1

0.09

0.08

0.07

pdf

0.06

0.05

0.04

0.03

0.02

0.01

0
-15

-10

-5

0
x

10

15

binomial distribution

0.4

0.35

0.3

pdf

0.25

0.2

0.15

0.1

0.05

10

15

Erlang distribution

0.1

0.09

0.08

0.07

pdf

0.06

0.05

0.04

0.03

0.02

0.01

5
x

10

Exponential distribution

0.9

0.8

0.7

pdf

0.6

0.5

0.4

0.3

0.2

0.1

0.5

1.5

2.5
x

3.5

4.5

0.6

0.7

0.8

0.9

Bernoulli distribution

1.5

pdf

0.5

-0.5

0.1

0.2

0.3

0.4

0.5
x

poisson distribution

0.35

0.3

0.25

pdf

0.2

0.15

0.1

0.05

10

20

## Histograms for each random variable:

Code2: plotting histograms
clc
clear all
y1 = randraw('norm', [0, 4], 1, 1e5);
y2 = randraw('erlang', [1, 3], [1 1e5]);
y3 = randraw('binom', [10 0.9], [1 1e5]);
y4 = randraw('exp', 1, [1 1e5]);
y5 = randraw('bern', 0.5, [1 1e5]);
y6 = randraw('po', , [1 1e5]);
disp('Value of Normal mean=');
disp(mean(y1));
disp('Value of Normal variance=');
disp(var(y1));
disp('Value of Erlang mean=');
disp(mean(y2));
disp('Value of Erlang variance=');
disp(var(y2));
disp('Value of Binomial mean=');
disp(mean(y3));
disp('Value of Binomial variance=');
disp(var(y3));
disp('Value of Exponential mean=');
disp(mean(y4));
disp('Value of Exponential variance=');
disp(var(y4));

30
x

40

50

60

## disp('Value of Bernoulli mean=');

disp(mean(y5));
disp('Value of Bernoulli variance=');
disp(var(y5));
disp('Value of poisson mean=');
disp(mean(y6));
disp('Value of poisson variance=');
disp(var(y6));
figure
histfit(y1);
xlabel('x' );
ylabel('pdf');
title('Normal')
figure
histfit(y2);
xlabel( 'x');
ylabel( 'pdf' );
title('erlang')
figure
histfit(y3);
xlabel('x' );
ylabel( 'pdf' );
title('binomial')
figure
histfit(y4);
xlabel(' x ');
ylabel( 'pdf' );
title('Exponential')
figure
histfit(y5);
xlabel( 'x' );
ylabel(' pdf ');
title('Bernoulli')
figure
histfit(y6);
xlabel( 'x' );
ylabel(' pdf ');
title('poisson')

Outputs:
Normal

1200

1000

pdf

800

600

400

200

0
-20

-15

-10

-5

0
x

10

15

20

erlang

1600
1400
1200

pdf

1000
800
600
400
200
0
-5

10

15

20

binomial

x 10

3.5
3

pdf

2.5
2
1.5
1
0.5
0

10

11

12

Exponential

4000
3500
3000

2000
1500
1000
500
0
-4

-2

10

12

14

Bernoulli

x 10

pdf

pdf

2500

0
-1

-0.5

0.5

1.5

2.5

poisson

x 10

2.5

pdf

1.5

0.5

0
-4

-2

Output Values:
Value of Normal mean=
-0.0056

16.1526

2.9923

2.9612

4
x

10

12

8.9998

0.8984

1.0036

1.0006

0.4955

0.2500

1.9915

## Value of poisson variance=

1.9920

>>

Problem 2:
Source code:
fy=(2*pi)-(2*pi)*rand(1,1000);
for t=0:10;
x=cos((2.*pi.*t)+fy);
m=mean(x);
valueofm(t+1)=m;
end
valueofm
hist(fy,10);
xlim([-10 10])
title('Histogram of Random variable');
%correlation plot
st=1/1000;
t=[0:999]*st;
s1=cos(2*pi*t+fy);
t1=t-(3*st);
s2=cos(2*pi*t1+fy);
[c,lags]=xcorr(s1,s2);
figure
plot(lags,c/max(c))

Outputs:

120

100

80

60

40

20

0
-10

-8

-6

-4

-2

10

1.2

0.8

autocorelation

0.6

0.4

0.2

-0.2
-1000

-800

-600

-400

-200

0
x values

200

400

600

800

1000

Output:

valueofm =

## -0.0180 -0.0180 -0.0180 -0.0180

-0.0180 -0.0180 -0.0180 -0.0180

-0.0180

-0.0180

-0.0180

## It is WSS because the mean is -0.0180 which is constant.

The Correlation remains similar for the window size, as can be seen in the
figure.