function [max_rate, B_opt, B_vector, rate_vector] = mud_vs_csi(T, Nt, SNR_dB, BFType, QuantizType, CQIType, SelectionMethod, MaxIter, BStart, BEnd)
% [rate_vector, B_vector, max_rate, B_opt] = mud_vs_csi(T, Nt, SNR_dB, BFType, QuantizType, CQIType, SelectionMethod, MaxIter, BStart, BEnd)
%% Input Arguments:
% T - Total feedback budget in bits(返回总比特数)
% Nt - Number of base station antennas(基站天线数)
% SNR_dB - The system SNR in dB(信噪比dB)
% BFType - The type of beamforming, can be '0-ZF', '1-PU2RC' or '2-SUBF'(波束成形类型)
% QuantizType - The type of channel quantization used, can be '0-None', '1-RVQ', '2-QUB', or '3-Scalar' (ignored by PU2RC)
% For perfect CSI, use 'None'(量化类型)
% CQIType - The type of channel quality indicator used, can be '0-Norm' or '1-SINR' (ignored for PU2RC and SUBF)
% SelectionMethod - The type of user selection employed can be '0-Greedy' or '1-Norm' (ignored by PU2RC and SUBF)
% MaxIter - 【Optional】. Number of Monte-carlo iterations(defaults to 100)(蒙塔卡罗迭代次数)
% BStart/BEnd - 【Optional】. Range of values of B to simulate, omit for automatic calculation (ignored if QuantizType is 'None')
%
%% Output Variables:
% max_rate - The maximum optimized sum rate (bps/hz)
% B_opt - The feedback load per user that maximizes the sum rate (bits)
% B_vector - The values of feedback load per user corresponding to the rates in rate_vector (bits)
% rate_vector - A vector with sum rate values for each per-user feedback load in B_vector (bps/hz)
%
%
% 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.
%
% Dependencies: quantiz_channels.m, user_selection_ZF_greedy.m, compute_pu2rc_rate.m
%% Check input arguments
if strcmpi(BFType, 'ZF')
BFType = 0; %Zero-forcing
elseif strcmpi(BFType, 'PU2RC');
BFType = 1; %RBF/PU2RC
else
BFType = 2; %Single-user beamforming,SUBF
end
if strcmpi(QuantizType, 'None')
QuantizType = 0; %Perfect CSI
elseif strcmpi(QuantizType, 'RVQ');
QuantizType = 1; %Random vector quantization
elseif strcmpi(QuantizType, 'QUB');
QuantizType = 2; %Quantization upper bound
else
QuantizType = 3; %Scalar quantization
end
if strcmpi(CQIType, 'Norm')
CQIType = 0; %channel norm
else
CQIType = 1; %SINR feedback
end
if strcmpi(SelectionMethod, 'Greedy')
SelectionMethod = 0;
else
SelectionMethod = 1; %Selection of users with largest channel norms
end
if nargin < 8 %若未输入MaxIter值,默认为100
MaxIter = 100; %Use a larger number for smoother curves
end
%% Compute range of B values to simulate (automatically, if not specified)
if BFType == 0 %ZF,根据用户向量决定B的范围,B=T./K
if nargin < 10 %输入参数没有BStart,BEnd,用户向量的选取
K_vector = max(ceil(T/50), Nt):1:min(150, T);
else %输入参数有BStart,BEnd,用户向量的选取
K_vector = unique(round(T./(BStart:BEnd))); %unique(a):去掉a中的重复值,K=T/B
end
B_vector = T./K_vector; %B=T/K
[dummy, indices] = unique(floor(B_vector));%indices为所选值得序号
K_vector = K_vector(indices);
B_vector = B_vector(indices);%根据序号,决定所需的K向量与B向量
elseif BFType == 1 %PU2RC,根据B的范围决定用户向量,K=T./B
if nargin < 10
B_vector = [log2(Nt):1:7+log2(Nt)];%B=log2(Nt)时为RBF,即码本中只有一个正交向量集
else
B_vector = [BStart:1:BEnd];
end
K_vector = ceil(T./B_vector);
else %SUBF,根据用户向量决定B的范围,B=T./K
if nargin < 10
K_vector = max(1, ceil(T/50)):1:min(200, T);
else
K_vector = unique(round(T./(BStart:BEnd)));
end
B_vector = T./K_vector;
[dummy, indices] = unique(floor(B_vector));
K_vector = K_vector(indices);
B_vector = B_vector(indices);
end
P = 10^(SNR_dB/10);%转换snr的单位,dB→比值
rate_vector = zeros(1, length(B_vector));%初始化rate_vector为全零向量
%% Display friendly status information
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(['Feedback budget = ' num2str(T) ' bits, SNR = ' num2str(SNR_dB) ' dB, BS Antennas = ' num2str(Nt,'%02d') ', Beamforming type = ' num2str(BFType)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Compute rate vector
for B_its = 1:length(B_vector);
B = B_vector(B_its);
K = ceil(K_vector(B_its));
regions = 2^B;
if (QuantizType ==3 && BFType ~= 1 && B<2*2*(Nt-1) )
continue; %Too small a codebook for scalar quantization
%如果if中条件为真,B_its=B_its+1,即执行下一个for循环,直到B的值满足【B>2*2*(Nt-1)】时,if条件为假,跳过continue,开始执行之后的语句
%continue功能为省略continue之后的循环语句,开始执行for/while循环的下一次循环
end
rate_temp = 0;
for its = 1:MaxIter
%构建下行链路信道矩阵
H = 1/sqrt(2) * (randn(K, Nt) + i * randn(K, Nt)); %Downlink channels
if BFType == 0 %ZF
QuantH = quantiz_channels(H, regions, P, QuantizType, CQIType);
rate_temp = rate_temp + user_selection_ZF_greedy(H, QuantH, P, SelectionMethod);
elseif BFType == 1 %PU2RC
NumBeams = Nt;
NumOrthSets = ceil(2^(log2(regions)-log2(NumBeams)));%正交集数:2^(B-log2(Nt))
BFCodebook = zeros(Nt, NumBeams, NumOrthSets);
for OrthSet = 1:NumOrthSets
BFCodebook(:, :, OrthSet) = orth(randn(Nt, NumBeams) + i*randn(Nt, NumBeams));%构建BFCodebook,其中有NumOrthSets个正交集
end
rate_temp = rate_temp + compute_pu2rc_rate(H, BFCodebook, P);
else %SUBF
QuantH = quantiz_channels(H, regions, P, QuantizType, 0);%CQIType=0
temp_rate = 0;
for k = 1:K
SNR_eff = abs(H(k, :)*QuantH(k, :)')^2/norm(QuantH(k, :))^2;%|hk*hQk'|/norm(hQk)^2
if log2(1 + P*SNR_eff) > temp_rate %找出temp_rate的最大值
temp_rate= log2(1 + P*SNR_eff);
end
end
rate_temp = rate_temp + temp_rate;
end
end; %for MaxIter
if QuantizType == 0 && BFType ~= 1
rate_vector = rate_temp/MaxIter;
B_vector = inf;
break; %Quit of perfect CSI simulation, no need to cycle through B_vector
else
rate_vector(B_its) = rate_temp/MaxIter;
% Display friendly status information
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp([' Feedback load per user = ' num2str(floor(B),'%03d') ' bits, Users = ' num2str(K, '%03d') ', Sum Rate = ' num2str(rate_vector(B_its)) ' bps/hz']);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
%% Compute optimal B and throughput
[max_rate B_opt] = max(rate_vector);
B_opt = B_vector(B_opt)
%__EOF__
评论0