ba=round(rand);
bb=round(rand);

if ba==1
    ca=1;
elseif ba==0
    ca=-1;
end
if bb==1
    cb=1;
elseif bb==0
    cb=-1;
end

C=[ca;cb]
ga=[1;1];
gb=[1;-1];
G=[ga,gb];
S=G*C;
eta1=0.8+0.2*rand;
eta2=0.8+0.2*rand;
phi1=0;
phi2=0;
ha=eta1*exp(i*phi1);
hb=eta2*exp(i*phi2);
H=[ha,hb;ha,hb]
phi=2*pi*randn(2,1);
W=0.1*exp(i*phi).*randn(2,1);
X=H.*G*C+W;

c00=0;
c01=0;
c10=0;
c11=0;

if abs(real(X(1)))<=1
    c01=c01+1;
    c10=c10+1;
elseif real(X(1))<-1

   c00=c00+1;
else real(X(1))>1
    c11=c11+1;
end

if abs(real(X(2)))<=1
    c00=c00+1;
    c11=c11+1;
elseif real(X(2))<-1
    c01=c01+1;
else real(X(2))>1
    c10=c10+1;
end

if max([c00 c01 c10 c11]) == c00
    c1 = -1
    c2 = -1
    sa1=-1;
    sa2=-1;
    sb1=-1;
    sb2=1;
elseif max([c00 c01 c10 c11]) == c01
    c1 = -1
    c2 = 1
    sa1=-1;
    sa2=-1;
    sb1=1;
    sb2=-1;
elseif max([c00 c01 c10 c11]) == c10
    c1 = 1
    c2 = -1
    sa1=1;
    sa2=1;
    sb1=-1;
    sb2=1;
else max([c00 c01 c10 c11]) == c11
    c1 = 1
    c2 = 1
    sa1=1;
    sa2=1;
    sb1=1;
    sb2=-1;
end

etaa=0.5*(real(X(1))*sa1+real(X(2))*sa2)
etab=0.5*(real(X(1))*sb1+real(X(2))*sb2)

figure
p1=plot(real(X(1)),imag(X(1)),'bx');
hold on
p2=plot(real(X(2)),imag(X(2)),'rx');
axis([-3 3 -2 2])
line([0,0], ylim, 'Color', 'k', 'LineWidth', 0.5); % Draw line for Y axis.
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 0.5); % Draw line for X axis.
line([1,1], ylim, 'Color', 'r', 'LineWidth', 0.5); 
line([-1,-1], ylim, 'Color', 'r', 'LineWidth', 0.5); % Draw line for decision regions
axis([-3 3 -2 2])
xlabel('Re');
ylabel('Im');
title('Decision regions')
legend([p1 p2],{'x1','x2'})
hold off