clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
%****************************************************************************
%更多关于matlab和fpga的搜索“fpga和matlab”的CSDN博客:
%matlab/FPGA项目开发合作
%https://blog.csdn.net/ccsss22?type=blog
%****************************************************************************
tic
SNR_dB=[-30:5:0]; SNR_linear=10.^(SNR_dB/10.);
N_iter=30; % earlier taken for 100 iterations
Num_cells=3; % Number of cells
Num_users=4; % Number of users
Nt_RF=8; % number of RF chains at TX = number of data streams at Tx
Nr_RF=2; % number of RF chains in each user(u) at Rx=no. of data streams at each u
Nt=64; % number of Tx antennas
Nt_w=Nt_RF; Nt_h=Nt/Nt_RF;
ind_Nt_w=reshape(repmat([0:1:Nt_w-1],Nt_h,1),1,Nt_w*Nt_h);
ind_Nt_h=repmat([0:1:Nt_h-1],1,Nt_w);
Nr=8; % number of Rx antennas
Nr_w=Nr_RF; Nr_h=Nr/Nr_RF;
ind_Nr_w=reshape(repmat([0:1:Nr_w-1],Nr_h,1),1,Nr_w*Nr_h);
ind_Nr_h=repmat([0:1:Nr_h-1],1,Nr_w);
L=3; % number of rays(paths)
M=Nt/Nt_RF; % number of antennas connected to one RF chains at Tx side
Mu=Nr/Nr_RF; % number of antennas connected to one RF chains at Rx side
%cell=1;
i_bs=1; % cell for which capacity has to be found
fc=28e9; % Frequencey
lamada=3e8/fc; % wavelegenth;
for i_snr=1:length(SNR_linear)
i_snr
SNR=SNR_linear(i_snr);
temp1=0;temp2=0;temp3=0; temp4=0;
for iter=1:N_iter
[H,H_eff,A_BS,A_MS]=mmWave_channel4(Num_cells,Num_users,Nr_w,Nr_h,Nt_w,Nt_h,L,lamada);
%syms i_bs
%%%%%% Optimal precoding - fully connected %%%%%%%%%%%%%%%%%%%%
[Precoder4,Combiner4]= optimal_precoding_fully_connected4(Num_cells,Num_users,Nt_RF,Nr_RF,Nt,Nr,H,H_eff);
if Num_cells==1
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*0*0'*H_eff(:,:,i_bs,cell)'), 1:Num_cells, 'UniformOutput', false));
else
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*(Precoder4(:,:,cell,cell))*Precoder4(:,:,cell,cell)'*H_eff(:,:,i_bs,cell)'), setdiff(1:Num_cells, i_bs), 'UniformOutput', false));
end
temp4=temp4+log2(det(eye(Num_users*Nr_RF)+(SNR/(Num_users*Nr_RF))*inv(Combiner4(:,:,i_bs,i_bs)'*(eye(Num_users*Nr)+(sum(cat(3,interference{:}),3)))*Combiner4(:,:,i_bs,i_bs))*Combiner4(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)*(Precoder4(:,:,i_bs,i_bs))*Precoder4(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)'*Combiner4(:,:,i_bs,i_bs)));
%%%%%% SIC-based hybrid precoding - fully connected %%%%%%%%%%%%%%%
[Precoder3,Combiner3]= SIC_based_precoding_fully_connected4(Num_cells,Num_users,Nt_RF,Nr_RF,Nt,Nr,H,H_eff);
if Num_cells==1
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*0*0'*H_eff(:,:,i_bs,cell)'), 1:Num_cells, 'UniformOutput', false));
else
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*(Precoder3(:,:,cell,cell))*Precoder3(:,:,cell,cell)'*H_eff(:,:,i_bs,cell)'), setdiff(1:Num_cells, i_bs), 'UniformOutput', false));
end
temp3=temp3+log2(det(eye(Num_users*Nr_RF)+(SNR/(Num_users*Nr_RF))*inv(Combiner3(:,:,i_bs,i_bs)'*(eye(Num_users*Nr)+(sum(cat(3,interference{:}),3)))*Combiner3(:,:,i_bs,i_bs))*Combiner3(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)*(Precoder3(:,:,i_bs,i_bs))*Precoder3(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)'*Combiner3(:,:,i_bs,i_bs)));
%%%%%% Optimal precoding - sub connected %%%%%%%%%%%%%%%%%%%%
[Precoder1,Combiner1]= optimal_precoding_sub_connected4(Num_cells,Num_users,Nt_RF,Nr_RF,Nt,Nr,M,Mu,H,H_eff,SNR);
if Num_cells==1
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*0*0'*H_eff(:,:,i_bs,cell)'), 1:Num_cells, 'UniformOutput', false));
else
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*(Precoder1(:,:,cell,cell))*Precoder1(:,:,cell,cell)'*H_eff(:,:,i_bs,cell)'), setdiff(1:Num_cells, i_bs), 'UniformOutput', false));
end
temp1=temp1+log2(det(eye(Num_users*Nr_RF)+(SNR/(Num_users*Nr_RF))*inv(Combiner1(:,:,i_bs,i_bs)'*(eye(Num_users*Nr)+(sum(cat(3,interference{:}),3)))*Combiner1(:,:,i_bs,i_bs))*Combiner1(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)*(Precoder1(:,:,i_bs,i_bs))*Precoder1(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)'*Combiner1(:,:,i_bs,i_bs)));
%%%%%% SIC-based hybrid precoding - sub connected %%%%%%%%%%%%%%%
[Precoder2,Combiner2]= SIC_based_precoding_sub_connected4(Num_cells,Num_users,Nt_RF,Nr_RF,Nt,Nr,M,Mu,H,H_eff,SNR);
if Num_cells==1
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*0*0'*H_eff(:,:,i_bs,cell)'), 1:Num_cells, 'UniformOutput', false));
else
interference=(arrayfun(@(cell) ((SNR/(Num_users*Nr))*H_eff(:,:,i_bs,cell)*(Precoder2(:,:,cell,cell))*Precoder2(:,:,cell,cell)'*H_eff(:,:,i_bs,cell)'), setdiff(1:Num_cells, i_bs), 'UniformOutput', false));
end
temp2=temp2+log2(det(eye(Num_users*Nr_RF)+(SNR/(Num_users*Nr_RF))*inv(Combiner2(:,:,i_bs,i_bs)'*(eye(Num_users*Nr)+(sum(cat(3,interference{:}),3)))*Combiner2(:,:,i_bs,i_bs))*Combiner2(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)*(Precoder2(:,:,i_bs,i_bs))*Precoder2(:,:,i_bs,i_bs)'*H_eff(:,:,i_bs,i_bs)'*Combiner2(:,:,i_bs,i_bs)));
end
C4(i_snr)= real(temp4/N_iter);
C3(i_snr)= real(temp3/N_iter);
C1(i_snr)= real(temp1/N_iter);
C2(i_snr)= real(temp2/N_iter);
end
plot(SNR_dB,C4,'r','Linewidth',1.5);
hold on
plot(SNR_dB,C3,'b','Linewidth',1.5);
hold on
plot(SNR_dB,C1,'g','Linewidth',1.5);
hold on
plot(SNR_dB,C2,'y','Linewidth',1.5);
legend('optimal precoding(fully-connected)','SIC-based hybrid precoding(fully-connected)','optimal precoding(sub-connected)','SIC-based hybrid precoding(sub-connected)')
xlabel('SNR (dB)')
ylabel('Achievable rate (bps/Hz)')
grid on
title('NtxNr=128x8, NtRF=16, NrRF=4, L=3, users=4, cells=3 - [2.7 min]')
%whitebg(figure,'white')
set(gcf,'color','white')
toc
% -----------------------------------------------------------------------
% --------------------------------------------------------------------------------
% -------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------