function rate = compute_ZF_rate(H, P)
% rate = compute_ZF_rate(H, P)
%
% Computes Zero-forcing rate for channels H and SNR P.
%
% H must be of dimension (Number of users) X (Number of base station antennas).
%
%   Part of mud_vs_csi package.
%
%   Reference:  "Multi-User Diversity vs. Accurate Channel State Information in MIMO Downlink Channels"
%                       by Niranjay Ravindran and Nihar Jindal, Submitted to IEEE Transactions on Communications, 2009.
%

num_users = size(H, 1);

%Compute ZF beamformers
V = (H' * inv(H * H'));
for k = 1:num_users
    V(:,k) = sqrt(P/num_users) * V(:,k)/norm(V(:,k));  %Normalize BF vectors with equal power allocation (waterfilling is optimal)
end;

%Compute sum rate for computed BF vectors
gain_matrix = abs(H * V).^2;
temp = 1+ sum(gain_matrix,2);
temp = diag(temp) * ones(num_users);
int_power = temp - gain_matrix;
SINR_matrix = gain_matrix ./ int_power;
rate = sum(log2(1 + diag(SINR_matrix)));

%__EOF__
