function [POS1, POS2]=cooperativecomm(v)
a=v(1);b=v(2);c=v(3);d=v(4);e=v(5);
%Signal power is fixed as 2
%a is the standard deviation associated with the Rayleigh distribution link
%between user 1 and user2
%b is the standard deviation associated with the Rayleigh distribution link
%between user 1 and basestation
%c is the standard deviation associated with Rayleigh distribution link
%between user 2 and basestation
%d is the standard deviation associated with the additive
%complex random variable
%to model imperfect CSI
%e is the standard deviation associated with the
%additive complex gaussian noise model.
POS1=[]; POS2=[];
for attempt=1:1:100
x=(round(rand(1,1000))*2-1)+j*(round(rand(1,1000))*2-1);
h12=a*(randn(1,1000)+j*randn(1,1000));
h1R=b*(randn(1,1000)+1i*randn(1,1000));
h2R=c*(randn(1,1000)+j*randn(1,1000));
%Imperfect CSI is obtained as additive noisy perfect CSI
DETCO=[];
DETD=[];
for i=1:1:1000
y1R=h1R(i)*x(i)+d*(randn+j*randn);
y12=h12(i)*x(i)+d*(randn+j*randn);
h12cap(i)=h12(i)+e*(randn+j*randn);
h1Rcap(i)=h1R(i)+e*(randn+j*randn);
h2Rcap(i)=h2R(i)+e*(randn+j*randn);
x12cap=h12cap(i)'*y12;
if(real(x12cap)>0)
x12detr=1;
else
x12detr=-1;
end
if(imag(x12cap)>0)
x12deti=1;
else
x12deti=-1;
end
x12=x12detr+j*x12deti;
%Retransmission
y2R=h2R(i)*x12+e*(randn+j*randn);
if(abs(h1Rcap(i))>abs(h2Rcap(i)))
det=h1R(i)'*y1R;
else
det=h1R(i)'*y1R;
end
if(real(det)>0)
xcapr=1;
else
xcapr=-1;
end
if(imag(det)>0)
xcapi=1;
else
xcapi=-1;
end
DETCO=[DETCO xcapr+j*xcapi];
x1Rcap=h1Rcap(i)'*y1R;
if(real(x1Rcap)>0)
xcap12r=1;
else
xcap12r=-1;
end
if(imag(x1Rcap)>0)
xcap12i=1;
else
xcap12i=-1;
end
DETD=[DETD xcap12r+j*xcap12i];
end
[P1,Q1]=find((x-DETCO)==0);
Rate1=length(P1)/10;
[P2,Q2]=find((x-DETD)==0);
Rate2=length(P2)/10;
POS1=[POS1 Rate1];
POS2=[POS2 Rate2];
end
