% Example code demonstrating the use of mud_vs_csi.m.
%
% System Parameters:
%     Number of base station antennas = 4, System SNR = 10 dB.
% Schemes compared:
%     1. ZF with RVQ, Norm CQI feedback and Greedy user selection
%     2. PU2RC
% Plots:
%     1. Sum rates for feedback budgets of 100 - 500 bits.
%     2. Sum rates with various feedback loads (per user) for a feedback budget of 300 bits. 
%
%   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.
%

% Dependencies: mud_vs_csi.m

%Compute the optimized sum rate for ZF with RVQ (Norm CQI feedback with Greedy
%user selection) as well as PU2RC where Number of BS antennas Nt = 4,
% system SNR = 10 dB, for feedback budgets T of 100, 200, 300, 400 and 500 bits.
T_values = [100 200 300 400 500];
rate_ZF_T = zeros(length(T_values), 1);
rate_PU2RC_T = zeros(length(T_values), 1);

for t = 1:length(T_values)
    T = T_values(t);
    rate_ZF_T(t) = mud_vs_csi(T, 4, 10, 'ZF', 'RVQ', 'Norm', 'Greedy');
    rate_PU2RC_T(t) = mud_vs_csi(T, 4, 10, 'PU2RC', NaN, NaN, NaN);
end

%Plot sum rate vs T
figure; hold on;
plot(T_values, rate_ZF_T, 'b--', 'LineWidth', 2);
plot(T_values, rate_PU2RC_T, 'r-.', 'LineWidth', 2);
xlabel('Total Feedback Load T (bits)'); ylabel('Sum Rate (bps/hz)');
title(['Nt = 4, SNR = 10 dB']);
legend('ZF with RVQ', 'PU^2RC');

%Compute sum rates for ZF and PU2RC when T = 300 bits at various per-user
%feedback loads.
[dummy, dummy, per_user_load_ZF_300, rate_ZF_300] = mud_vs_csi(300, 4, 10, 'ZF', 'RVQ', 'Norm', 'Greedy');
[dummy, dummy, per_user_load_PU2RC_300, rate_PU2RC_300] = mud_vs_csi(300, 4, 10, 'PU2RC', NaN, NaN, NaN);

%Plot sum rate vs B
figure; hold on;
plot(per_user_load_ZF_300, rate_ZF_300, 'b--', 'LineWidth', 2);
plot(per_user_load_PU2RC_300, rate_PU2RC_300, 'r-.', 'LineWidth', 2);
xlabel('Per-user Feedback Load B (bits)'); ylabel('Sum Rate (bps/hz)');
title(['Nt = 4, SNR = 10 dB, T = 300 bits']);
legend('ZF with RVQ', 'PU^2RC');

%__EOF__