You are on page 1of 3

Mean of Z:

m_z =

0.0007
0.0009
-0.0016
0.0002
0.0016
-0.0013
-0.0012
-0.0019
0.0004
-0.0001

sigma_z_sq =

0.0101

g =

-0.9996
-0.0058
0.0035
-0.0008
0.0183
0.0127
0.0050
0.0028
-0.0166
0.0018

sigma_w_sq =

0.0349

h =

0.7075
0.7066
-0.0017
-0.0016
0.0015
0.0004
-0.0055
0.0011
0.0025
-0.0068
correct =

2274

% Homework 4, problem 5.

load('hw4-data/data.mat');

% Estimate sigma_z by estimating cov(Z) and then noting that K_z


should be
% of the form (sigma_z^2)*K_z.

% N is dimension of data
N = size(Y_z, 1);
% M is number of samples
M = size(Y_z, 2);
m_z = sum(Y_z, 2) / M;
fprintf('Mean of Z:\n');
m_z
K_z = zeros(N,N);
for i=1:M
K_z = K_z + Y_z(:,i)*Y_z(:,i)';
end
%fprintf('K_z estimate:\n');
K_z = K_z / M;
% Estimate of sigma_z^2 is mean of trace).
sigma_z_sq = trace(K_z) / N

% Part b -- estimate interferer.


M_w = size(Y_w, 2);
% Estimate g and sigma_w by estimating cov(g*W + Z), removing Z
component,
% and computing rank 1 reduction. Assuming W, Z zero-mean.
K_u = zeros(N,N);
for i=1:M_w
K_u = K_u + Y_w(:,i)*Y_w(:,i)';
end
%fprintf('K_u estimate:\n');
K_u = K_u / M_w;
% Remove Z component.
K_gw = K_u - eye(N)*sigma_z_sq;
[v, d] = eig(K_gw);
[sorted_eigs, ind] = sort(diag(d), 'descend');
g = v(:, ind(1))
sigma_w_sq = sorted_eigs(1)
% Sanity check.
K_u_est = g*g'*sigma_w_sq + eye(N)*sigma_z_sq;

% Part c -- estimate h. Should be just the mean of Y times 2 (half


the samples
% are X = 0).
m_h = size(Y_x, 2);
h = sum(Y_x, 2) / m_h;
h = h / norm(h)

% Part d -- MAP detection.


load('hw4-data/X_label.mat');
proj = h'*inv(sigma_w_sq*g*g' + sigma_z_sq*eye(N));
%proj = h'*inv(K_u);
maps = proj*Y_x;
decisions = maps > 0;
correct = sum(decisions == X)

You might also like