0% found this document useful (0 votes)
338 views7 pages

EEE 554 Matlab Solutions

This document contains MATLAB code for solving problems related to random signal theory. The code generates random variables with different distributions, calculates their statistical properties like mean, variance and correlation, plots bivariate normal distributions, and generates samples from bivariate normal distributions.

Uploaded by

aravind_matrix
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
338 views7 pages

EEE 554 Matlab Solutions

This document contains MATLAB code for solving problems related to random signal theory. The code generates random variables with different distributions, calculates their statistical properties like mean, variance and correlation, plots bivariate normal distributions, and generates samples from bivariate normal distributions.

Uploaded by

aravind_matrix
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EEE 554 RANDOM SIGNAL THEORY

ASSIGNMENT : 5

Submitted by
ARAVINDAN RAMASAMY
1204160810

SOLUTIONS FOR MATLAB BASED PROBLEMS

7.49)

CODE:
rand('state',0) %#ok<RAND>
m=100000;
for i=1:m
u=rand(1,1);
if u<=1/8
x(i,1)=0;y(i)=0; %#ok<SAGROW>
elseif u>1/8&&u<=1/4
x(i,1)=1;y(i,1)=0;
else
x(i,1)=1;y(i,1)=1;
end
end
ex=mean(x);
ey=mean(y);
cov=mean(x.*y)-ex*ey;
ex2=mean(x.^2);
ey2=mean(y.^2);
varx=ex2-ex^2;
vary=ey2-ey^2;
rho=cov/sqrt(varx*vary);

7.51)

CODE:
rand('state',0) %#ok<RAND>
m=100000;
for i=1:m
u=rand(1,1);
if u<=3/8
x(i,1)=0;y(i)=0; %#ok<SAGROW>
elseif u>3/8&&u<=1/2
x(i,1)=0;y(i,1)=1;
elseif u>1/2&&u<=5/8
x(i,1)=1;y(i,1)=0;
else
x(i,1)=1;y(i,1)=1;
end
end
ex=mean(x);
ey=mean(y);
cov=mean(x.*y)-ex*ey;
w=x;
z=-x/2+y;
cov1=mean(w.*z)-mean(w)*mean(z);

12.35)

CODE:
clear all
u1=[0.95:0.01:1.05]';
u2=[1.95:0.01:2.05]'; %#ok<*NBRAK>
k=0;
for i=1:length(u1)
for j=1:length(u2)
k=k+1;
x(:,k)=[u1(i) u2(j)]'; %#ok<SAGROW>
w(:,k)=[u1(i)^2+5*u2(j)^2 -5*u1(i)^2+u2(j)^2]'; %#ok<NBRAK,SAGROW>
end
end
figure
plot(x(1,i),x(2,i),'.')
hold on
for i=2:k
plot(x(1,i),x(2,i),'.')
end

axis([0.5 1.5 1.5 2.5 ])


grid
hold off
figure
plot(w(1,i),w(2,i),'.')
hold on
for i=2:k
plot(w(1,i),w(2,i),'.')
end
grid
axis([15 25 -2 0])
hold off

12.50)

CODE:
clear all
c=[3 1;1 1];
xmax=5;
x=[-xmax:0.4:xmax]';y=x;
for i=1:length(x)
for j=1:length(y)
xx=[x(i)-1 y(j)-1]';
q=xx'*inv(c)*xx; %#ok<*MINV>
pxy(i,j)=(1/(2*pi*sqrt(det(c))))*exp(-.5*q); %#ok<*SAGROW>
end
end
figure
colormap(gray(1))
[C,H]=contour(x,y,pxy);
plot(x,x/3+2/3)

12.56)

CODE:
clear all
figure
xx=[-4:0.1:4]';yy=xx;
c=[1 -0.9;-0.9 1];
for i=1:length(xx)
for j=1:length(yy)
xv=[xx(i) yy(j)]';
q=(xv-1)'*inv(c)*(xv-1); %#ok<*MINV>
pxy(i,j)=(1/(2*pi*sqrt(det(c))))*exp(-.5*q); %#ok<*SAGROW>
end
end
colormap(gray(1))
contour(xx,yy,pxy,5);
axis('square')
axis([-4 4 -4 4])
hold on
randn('state',0) %#ok<*RAND>
g=[1 0;-0.9 sqrt(1-0.9^2)];
m=500;
for i=1:m
x=randn(1,1);
y=randn(1,1);
wz=g*[x y]'+[1 1]';
WZ(:,m)=wz;
plot(wz(1),wz(2),'.')
end
grid
hold off

You might also like