clear all
close all

n     = 64;    % The number of sensors
T     = 1000;  % The number of samples
nv    = 2;     % Variance of noise

g = sin(5*2*pi*[1:T]/T);   % Global signal
g = g/std(g);
a = rand(n,1);         % Coefficient vector
L = diag(rand(1,n)*sqrt(nv))*randn(n,T);

X = a*g + L;

[ea esnr] = getA(X);
[eg w] = extg(ea,X);

figure;
subplot(2,1,1);
bar(a);
axis([0 n+1 0 max(a)]);
title('given a');
subplot(2,1,2);
bar(ea);
axis([0 n+1 0 max(a)]);
title('estimated a');



figure;
subplot(3,1,1);
title('given g');
plot(g);
subplot(3,1,2);
plot(mean(X)/std(mean(X)));
title(sprintf('Normal averaged signal SNR=%.2f',10*log10(var(mean(a*g))/var(mean(L)))));
subplot(3,1,3);
plot(eg/std(eg));
title(sprintf('Optimal averaged signal SNR=%.2f',10*log10(var(w'*a*g)/var(w'*L))));







