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

1.

Exponential
Code:
% pdf of exponential
R=rand(1,2000); %R represents the uniform random variable
X=-6*log(R); %X represents the exponential random variable with mean 6
M=mean(X) %Calculate mean of the random variable
Var=cov(X) %Calculate variance of the random variable
[p,q]=hist(X,50); %pdf of the exponential random variable
bar(q,p/2000);
xlabel('X');
ylabel('Probability Density Function');

Plot the probability density function of the random variables

Mean = 6.0099
Variance = 37.6312
2.Bernoulli
Code:
% pdf of Bernoulli
P = 0.4
n = 2000
A = randn(n, 1)
X = sum(A < p)
hist(X)
xlabel('X');
ylabel('Probability Density Function');

Plot the probability density function of the random variables


3.Binomial
Code:
% pdf of binomial
n = 2000;
A = randn(1, n);
t = (U < 0.5);
a = zeros(n + 1);
Av = zeros(n);
for i = 2 : n + 1
a(i) = a(i - 1) + t(i - 1);
Av(i - 1) = a(i)/(i - 1);
end
plot(Av)
x = 0:25;
pdf= binopdf(x,25,0.1);
bar(x,pdf,1,'w')
xlabel('X');
ylabel('Probability Density Function');

Plot the probability density function of the random variables


4.Geometric
Code:
% pdf of geometric
P = 1/5;
X0 = -1;
Bk=X0:10;
Z = geopdf(Bk,p); % geometric distribution
i=12;
while i>1
Z(i)=Z(i-1);
i=i-1;
end
Z(1)=0;
stem(Bk,Z)
title('pdf for p = 1/5')
xlabel('X');
ylabel('Probability Density Function');
Pr = 1 - sum(Z(1:5-X0+1))
5.Normal
Code:
% pdf of normal distribution
R = randn(1,2000);
[d,x] = hist(R,50);
figure;
bar(x,d/trapz(x,d));
xlabel('X');
ylabel('Probability Density Function');

Plot the probability density function of the random variables


6.Rayleigh
Code:
% pdf of Rayleigh
clear;
n = 2000;
Mean = 0;
Var = 1/5;
x1 = Mean+sqrt(Var)*randn(1,n);
x2 = Mean+sqrt(Var)*randn(1,n);
L = x1+j*x2; %complex Gaussian
z= abs(L);
nob = 100;
a = min(z);
b = max(z);
c = linspace(a,b,nob);
count(size(c))= 0;
for i= 1:length(c)-1
for j= 1:n
if z(j)>=c(i) && z(j)<c(i+1)
count(i) = count(i)+1;
end
end
y(i) = (c(i)+c(i+1))/2;
end
%plot
subplot(211);
bar(y,count(1:end-1)/n);
[bin val]= hist(z,y);
subplot(212);
bar(y,bin/n);
subplot(212);
bar(y,bin/n);

Plot the probability density function of the random variables


7.Lognormal
Code:
% pdf of Lognormal
L = 50;
t= 1/L;
t1=0:t:(2-t);
n = length(t1);
M = 0;
sigma=1;
y= lognrnd(M,sigma,n,1);
plot(t1,y);
axis([0 2 0 12]);
xlabel('X');
ylabel('Probability Density Function');
title('Lognormal pdf')

Plot the probability density function of the random variables


Project 3

Sittipong Ruangsang

G 01177205

ECE 528

Introduction to Random Processes in ECE

Bijan Jabbari

You might also like