% Blind multiuser detector for K = 2 users

N = 4;   % Number of chips per bit
T = 5;   % Number of bits per block

% Matrix r contains N x T chip observations

Rd = r*r'/T;    % Correlation matrix

[V,S] = eig(Rd);
s = diag(S);
[ss,si] = sort(s);
ss = flipud(ss);  si = flipud(si);
S = diag(ss);
V = V(:,si);

wBL = pinv( V(:,1:2) * sqrt(S(1:2,1:2)) );   % Capon (blind) MUD

fprintf('BLIND ESTIMATES OF BITS FOR USERs 1 and 2:\n')
bhatBL = sign(wBL*r)
