📄 constsirsca.m
字号:
clear
time=cputime
KS=25;
KA=3;
NF=3;
KSM=NF*KA*KS;
KM=NF*KA;
r=4;
alpha=3.0;
hotspotfactor=16; % hotspotfactor<=KS
NN=500;
warning off
rand('seed',0);
randn('seed',0);
targetSIR=10; % target SIR=10dB
SIR=zeros(NN,KSM,NF)-inf;
nouser=zeros(NN,KSM,NF);
ActiveFlag=zeros(NN,KSM);
% SIR=zeros(NN,KM*hotspotfactor,NF)-inf;
% ActiveFlag=zeros(NN,KM*hotspotfactor);
% nouser=zeros(NN,KM*hotspotfactor,NF);
for nn=1:NN % number of scenarios
% G=channelmodel(KA,KM,KS,r,alpha);
% rayleigh=(randn(NF,KA*KS,KM*KS)+sqrt(-1)*randn(NF,KA*KS,KM*KS))*sqrt(1/2);
% for nF=1:NF
% H(nF,:,:)=transpose(sqrt(G).*squeeze(rayleigh(nF,:,:)));
% end
% SA_index=[ones(1,KM) 2*ones(1,KM) 3*ones(1,KM) 4*ones(1,KM) 5*ones(1,KM) 6*ones(1,KM) 7*ones(1,KM) 8*ones(1,KM) 9*ones(1,KM)];
% seq=[1:KSM];
% seq2=[];
% for kk=1:KSM
% rr=floor(rand*length(seq))+1;
% seq2=[seq2 seq(rr)];
% seq(rr)=[];
% end
%
% H=H(:,seq2,:);
% SA_index=SA_index(seq2);
kM_center=0;
[SA_index, G]=singleMTpathgain(KSM, KA, KS, r, NF, alpha, hotspotfactor);
rayleigh=(randn(NF,KSM,KA*KS)+sqrt(-1)*randn(NF,KSM,KA*KS))*sqrt(1/2);
for nF=1:NF
H(nF,:,:)=sqrt(G).*squeeze(rayleigh(nF,:,:));
end
INDEX=zeros(1,KSM)-1; % MT specific subcarrier index
counter=zeros(KS,NF);
load=zeros(1,KS);
V=zeros(NF,1,KS*KA);
W=zeros(NF,KS*KA,KS*KA);
OUT_pre=zeros(1,NF);
for kSM=1:KSM % system wide sequential DCA
%sprintf('>>>>>>>>>>>>>>>>>>>> the %d-th MT arrives <<<<<<<<<<<<<<<<<<<<', kSM)
t=zeros(NF,KS*KA);
V_tmp=V;
W_tmp=W;
kS=SA_index(kSM); % SA index of the kSM-th MT
if load(kS) < NF*KA % not fully loaded in SA kS
load(kS)=load(kS)+1;
ActiveFlag(nn,kSM)=1;
MTs_i=find(SA_index(1:kSM)==kS); % the MTs located in SA kS up to the (kSM)-th MT
%--------------------
% FCA
%--------------------
flag=1;
while(flag)
index_nF=floor(rand*NF)+1;
if counter(kS,index_nF) < KA
counter(kS,index_nF)=counter(kS,index_nF)+1;
INDEX(kSM)=index_nF;
flag=0;
end
end
index_i=find(INDEX(MTs_i)==index_nF); % the MTs active at subcarrier nF up to the (kSM-1)-th MT
K=length(index_i); % the number of MTs active at subcarrier nF in SA i
H_SA=reshape(H(index_nF,MTs_i(index_i), (kS-1)*KA+1:kS*KA), [K,KA]);
V(index_nF,(kS-1)*KA+1:(kS-1)*KA+K)=diag(inv(H_SA*H_SA')); % (K)-by-1
for j=1:KS
if j~=kS
MTs_j=find(SA_index(1:kSM)==j);
index_j=find(INDEX(MTs_j)==index_nF); % the MTs in the co-channel SAs
KK=length(index_j);
H_inter = reshape(H(index_nF,MTs_i(index_i),(j-1)*KA+1:j*KA),[K,KA]); %K-by-KA
H_temp = reshape(H(index_nF,MTs_j(index_j),(j-1)*KA+1:j*KA),[KK,KA]); %KK-by-KA
HH = inv(H_temp*H_temp'); % KK-by-KK
M=H_temp'*HH*diag(1./sqrt(diag(HH)));%KA-by-KK
w=power(abs(H_inter*M),2); % (K)-by-KK
W(index_nF,(kS-1)*KA+1:(kS-1)*KA+K,(j-1)*KA+1:(j-1)*KA+KK)=w;
H_inter = reshape(H(index_nF,MTs_j(index_j),(kS-1)*KA+1:kS*KA),[KK,KA]); %KK-by-KA
HH = inv(H_SA*H_SA'); % (K)-by-(K)
M=H_SA'*HH*diag(1./sqrt(diag(HH)));%KA-by-(K)
w=power(abs(H_inter*M),2); % KK-by-(K)
W(index_nF,(j-1)*KA+1:(j-1)*KA+KK,(kS-1)*KA+1:(kS-1)*KA+K)=w;
end
end %of for j
A=V(index_nF,:);
B=squeeze(W(index_nF,:,:));
index_tmp=find(A~=0);
A=A(index_tmp);
B=B(index_tmp,:);
B=B(:,index_tmp);
[T,lambda]=eig(diag(abs(A))*B);
[MAX,index]=max(diag(lambda));
if MAX<0
MAX=-MAX;
end
%gamma(index_nF)=1/MAX;
t(index_nF,index_tmp)=T(:,index);
if kSM>1
SIR(nn,kSM,:)=SIR(nn,kSM-1,:);
nouser(nn,kSM,:)=nouser(nn,kSM-1,:);
end
SIR(nn,kSM,index_nF)= 10*log10(1/MAX);
%V(index_nF,:)=V_tmp(index_nF,:);
%W(index_nF,:,:)=W_tmp(index_nF,:,:);
nouser(nn,kSM,index_nF)=sum(counter(:,index_nF));
%--------------------
% fast DCA
%--------------------
% for nF=1:NF
% %sprintf('++++++++++++++++ subcarrier %d ++++++++++++++++', nF)
% if counter(kS,nF)<KA % not fully loaded at subcarrier nF in SA kS
% index_i=find(INDEX(MTs_i)==nF); % the MTs active at subcarrier nF up to the (kSM-1)-th MT
% K=length(index_i); % the number of MTs active at subcarrier nF in SA i
%
% H_SA=reshape(H(nF,MTs_i(index_i), (kS-1)*KA+1:kS*KA), [K,KA]);
% H_SA=[H_SA; reshape(H(nF,kSM,(kS-1)*KA+1:kS*KA), [1,KA])]; % the MTs at subcarrier nF in SA kS up to the kSM-th MT
% V_tmp(nF,(kS-1)*KA+1:(kS-1)*KA+K+1)=diag(inv(H_SA*H_SA')); % (K+1)-by-1
%
% for j=1:KS
%
% if j~=kS
% %sprintf('----- j=%d ----',j)
% MTs_j=find(SA_index(1:kSM-1)==j);
% index_j=find(INDEX(MTs_j)==nF); % the MTs in the co-channel SAs
% KK=length(index_j);
%
% H_inter = reshape(H(nF,MTs_i(index_i),(j-1)*KA+1:j*KA),[K,KA]); %K-by-KA
% H_inter = [H_inter; reshape(H(nF,kSM,(j-1)*KA+1:j*KA),[1,KA])]; %(K+1)-by-KA
% H_temp = reshape(H(nF,MTs_j(index_j),(j-1)*KA+1:j*KA),[KK,KA]); %KK-by-KA
% HH = inv(H_temp*H_temp'); % KK-by-KK
% M=H_temp'*HH*diag(1./sqrt(diag(HH)));%KA-by-KK
% w=power(abs(H_inter*M),2); % (K+1)-by-KK
% W_tmp(nF,(kS-1)*KA+1:(kS-1)*KA+K+1,(j-1)*KA+1:(j-1)*KA+KK)=w;
%
% H_inter = reshape(H(nF,MTs_j(index_j),(kS-1)*KA+1:kS*KA),[KK,KA]); %KK-by-KA
% HH = inv(H_SA*H_SA'); % (K+1)-by-(K+1)
% M=H_SA'*HH*diag(1./sqrt(diag(HH)));%KA-by-(K+1)
% w=power(abs(H_inter*M),2); % KK-by-(K+1)
% W_tmp(nF,(j-1)*KA+1:(j-1)*KA+KK,(kS-1)*KA+1:(kS-1)*KA+K+1)=w;
% end
%
% end %of for j
% A=V_tmp(nF,:);
% B=squeeze(W_tmp(nF,:,:));
% index_tmp=find(A~=0);
% A=A(index_tmp);
% B=B(index_tmp,:);
% B=B(:,index_tmp);
% [T,lambda]=eig(diag(abs(A))*B);
% [MAX,index]=max(diag(lambda));
% if MAX<0
% %sprintf('MAX<0!!!!!:MAX=%d',MAX)
% MAX=-MAX;
% end
% gamma(nF)=1/MAX;
% t(nF,index_tmp)=T(:,index);
%
% if 10*log10(gamma(nF))<targetSIR
% OUT(nF)=sum(counter(:,nF))+1;
% else
% OUT(nF)=0;
% end
% OUT_inc(nF)=OUT(nF)-OUT_pre(nF);
%
% else % fully loaded at subcarrier nF in SA kS
% gamma(nF)=-inf;
% t(nF,:)=0;
% OUT_inc(nF)=inf;
% end % if counter(kS,nF)<KA
% %pause
%
%
% end % of nF
% %gamma
%
%
% [MAX,index_nF]=max(gamma);
% if all(OUT_inc==0 | OUT_inc==inf) % all users at all subcarrier are not in outage
% [MAX,index_nF]=max(gamma);
% elseif all(OUT_inc==1 | OUT_inc==inf) % all users at all subcarriers are in outage
% [MAX,index_nF]=max(gamma);
% else
% [MIN,index_nF]=min(OUT_inc);
% end
%
% if 10*log10(gamma(index_nF))>=10
%
% OUT_pre(index_nF)=OUT(index_nF);
% counter(kS,index_nF)=counter(kS,index_nF)+1;
% INDEX(kSM)=index_nF;
%
% V(index_nF,:)=V_tmp(index_nF,:);
% W(index_nF,:,:)=W_tmp(index_nF,:,:);
%
%
% if kSM>1
% SIR(nn,kSM,:)=SIR(nn,kSM-1,:);
% nouser(nn,kSM,:)=nouser(nn,kSM-1,:);
% % SIR(nn,kM_center,:)=SIR(nn,kM_center-1,:);
% % nouser(nn,kM_center,:)=nouser(nn,kM_center-1,:);
% end
% SIR(nn,kSM,index_nF)= 10*log10(gamma(index_nF));
% nouser(nn,kSM,index_nF)=sum(counter(:,index_nF));
% % SIR(nn,kM_center,index_nF)= 10*log10(gamma(index_nF));
% % nouser(nn,kM_center,index_nF)=sum(counter(:,index_nF));
%
%
% else
% ActiveFlag(nn,kSM)=-1;
% SIR(nn,kSM,:)=SIR(nn,kSM-1,:);
% nouser(nn,kSM,:)=nouser(nn,kSM-1,:); % no of users at different subcarriers up to the kSM-th MT
% end
else % load(kS) >= NF*KA
ActiveFlag(nn,kSM)=-1; % the MT is will not be supported
SIR(nn,kSM,:)=SIR(nn,kSM-1,:);
nouser(nn,kSM,:)=nouser(nn,kSM-1,:); % no of users at different subcarriers up to the kSM-th MT
% SIR(nn,kM_center,:)=SIR(nn,kM_center-1,:);
% nouser(nn,kM_center,:)=nouser(nn,kM_center-1,:);
end % of load(kS)<NF*KA
xx=sum(counter);
OUT=find(-Inf<SIR(nn,kSM,:) & SIR(nn,kSM,:)<targetSIR); % the subcarriers on which the target SIR is not achieved
Pout(nn,kSM)=( sum(xx(OUT)) + length(find(ActiveFlag(nn,1:kSM)==-1)) ) / kSM;
if kS==1 % in the central SA
kM_center=kM_center+1;
Pout_cen(nn,kM_center)=Pout(nn,kSM);
end
%Pout(nn,kM_center)= ( sum(xx(OUT)) + length(find(ActiveFlag(nn,1:kM_center)==-1)) ) / kSM;
end % of kSM
end % of nn
% for kSM=1:KSM
% Pout(kSM)=(length(find(-Inf<SIR(:,kSM,:) & SIR(:,kSM,:)<targetSIR))*load(kSM) + length(find(ActiveFlag(:,1:kSM)==-1))) / (length(find(-Inf<SIR(:,kSM,:)))+length(find(ActiveFlag(:,1:kSM)==-1)));
% end
figure
plot(mean(Pout_cen,1))
cputime-time
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -