% Experiment 10 ECE 376 2013
clear;clc;close all;

e1 = [-1 -1 1 1 1 -1 1];e2 = [-1 -1 1 -1 1 1 1]; % Spreading PN sequences of max length
R11 = e1*e1';R12 = e1*e2';R22 = e2*e2';Rc = [R11 R12;R12 R22];
a10 = -1;a20 = 1;A1 = 1;A2 = -1/30;
Symbols = [-1 -1;-1 1;1 -1;1 1];
z = [R11*A1*a10 + R12*A2*a20 + 0.5*A1 + 0.7*A2;R12*A1*a10 + R22*A2*a20 + 0.5*A1 + 0.7*A2];
%%% Evaluation of correlation metrics

C1 = 2*[-A1 -A2]*z - [-A1 -A2]*Rc*[-A1; -A2]; % Testing for the case of [-1 -1]
C2 = 2*[-A1 +A2]*z - [-A1 +A2]*Rc*[-A1; +A2]; % Testing for the case of [-1 +1]
C3 = 2*[+A1 -A2]*z - [+A1 -A2]*Rc*[+A1; -A2]; % Testing for the case of [+1 -1]
C4 = 2*[+A1 +A2]*z - [+A1 +A2]*Rc*[+A1; +A2]; % Testing for the case of [+1 +1]
[col, ro] = max([C1, C2, C3, C4]);
Detsyms = Symbols(ro,:);
Err = symerr([a10;a20],Detsyms')