Hi, i am trying again and again but my plot is empty.

1 次查看(过去 30 天)
clc
clear all
close all
clc
clear all
close all
tt=100:100:200;
L=12; % IRS
element=10;
lambda=0.06;
l=lambda/2;
Sigma=db2pow(-90); %% -60dbm
a_db=-46;
alpha=db2pow(a_db);
K=4; % Number of users
radius=15;
X0=0; % x-coordinate of Centre of the circle
Y0=0; % y-coordinate of Centre of circle
%% Base stations
x_b=[0.7298; 3; -5.23; 11.86]; % x coordinates of base station
y_b=[12.48; -1.497; -6.139; -3.23]; %y coordiantes of base station
%% IRSs placement
X3=[-7.655; -6.189; -3.251; 2.926; 6.534; 10.79; 5.203; -4.465; 1.42; -8.66; -0.8748; 6.534] ;
Y3=[1.393; 10.42; 6.639; 5.821; 8.425; 2.924; 1.139; 0.7508; -7.917; -6.928; -10.01; -7.03];
p=0;
%% loop for the elements of irs
N=100:100:200; %% number of elements in an IRS
NN = length(N) ;
for n = 1:length(N)
nn=N(n);
for i=1:L
for j=1:element
for k=1:(nn)/(10)
x3(j,k,i) = X3(i,1) + p;
y3(j,k,i) = Y3(i,1);
p=k*l; % Each time lambda is added to the x-coordinate
x_e(j,k,i,n) = x3(j,k,i); % X coordinate of an element of IRS for plotting
y_e(j,k,i,n)= y3(j,k,i); % Y coordinate of an element of IRS for plotting
end
p=0;
Y3(i,1) = Y3(i,1) + l;
end
% plot(x3,y3,'bo','HandleVisibility','off')
end
end
%% Distances between the IRSs
for irs1 = 1:(L-1) % IRS1
for irs2 = (irs1+1):L % IRS2
di_i(irs1,irs2)=sqrt((X3(irs2)-X3(irs1))^2+(Y3(irs2)-Y3(irs1))^2); %% distance between the IRSs
di_i(irs2,irs1)=di_i(irs1,irs2);
end
end
%b(irs2,irs1)=cell2mat(hi_i(irs1,irs2));
rr=11;
%% capacity calculation
%% Capacity calculation
Sum=zeros(1,2);
for p=0:5:20 %loop for power
powerTx=db2pow(p);
for n_e = 1:length(N) % Iterations for different number of elements
nn=N(n_e); % Number of elements
nn_h=10;
nn_v=nn/10;
cc11=0;cc22=0;cc33=0;cc44=0;
for i=1:10
C11=0; C22=0; C33=0; C44=0;
% Users
t = 2*pi*rand(K,1);
R = radius*sqrt(rand(K,1));
x_u = X0 + R.*cos(t); % X-coordinate of the Users
y_u = Y0 + R.*sin(t); % Y-coordinate of the Users
%% Distance computation between IRSs and Base Station and IRSs and user
for bs = 1:4 % IRS1
phi_ab=2*pi*rand(L) ;
phi_eb=2*pi*rand(L) ;
for irs = 1:L % IRS2
%% BS and IRS
db_i(bs,irs)=sqrt((X3(irs)-x_b(bs))^2+(Y3(irs)-y_b(bs))^2); %% distance between bs and IRSs
db_i(irs,bs)=db_i(bs,irs);
ai_b=array_resp( nn_h,nn_v,phi_ab(irs),phi_eb(irs)); %steering vector1
hb_i{bs,irs}=(sqrt(alpha)/db_i(bs,irs))*(exp(-1j*(2*pi*db_i(bs,irs)./lambda)))*ai_b; %% channel between BS and IRS
hb_i{irs,bs}= hb_i{bs,irs};
%% IRS and user
theta_au=2*pi*rand(L) ;
theta_eu=2*pi*rand(L) ;
du_i(bs,irs)=sqrt((X3(irs)-x_u(bs))^2+(Y3(irs)-y_u(bs))^2); %% distance between bs and IRSs
du_i(irs,bs)=du_i(bs,irs);
au_i=array_resp(nn_h,nn_v,theta_au(irs),theta_eu(irs)); %steering vector1
hu_i{bs,irs}=(sqrt(alpha)/du_i(bs,irs))*(exp(-1j*(2*pi*du_i(bs,irs)./lambda)))*au_i; %% channel between BS and IRS
hu_i{irs,bs}= hu_i{bs,irs};
end
end
%% channel between IRS and IRS
for irs1 = 1:(L-1) % IRS1
ij=1;
for irs2 = (irs1+1):L % IRS2
%% AoA arrival
thetaaii=2*pi*rand(1) ;
thetaeii=2*pi*rand(1) ;
phi_aii= 2*pi*rand(1) ;
phi_eii=2*pi*rand(1) ;
sij2{irs1,irs2}=array_resp(nn_h,nn_v,phi_aii,phi_eii);
sij2{irs2,irs1}= sij2{irs1,irs2};
sij1{irs1,irs2}=array_resp(nn_h,nn_v,thetaaii,thetaeii);
sij1{irs2,irs1}= sij2{irs1,irs2};
hi_i{irs1,irs2}=(sqrt(alpha)/di_i(irs1,irs2))*(exp(-1j*(2*pi*di_i(irs1,irs2)/lambda)))*cell2mat(sij2(irs1,irs2))*cell2mat(sij1(irs1,irs2))'; %% distance between the IRSs
hi_i{irs2,irs1}=(sqrt(alpha)/di_i(irs1,irs2))*(exp(-1j*(2*pi*di_i(irs1,irs2)/lambda)))'*cell2mat(sij2(irs1,irs2))*cell2mat(sij1(irs1,irs2))';
ij=ij+1;
%% channel gain computations
r1=cell2mat(hu_i(1,irs2));
S1=cell2mat(hi_i(irs1,irs2));
t1=cell2mat(hb_i(1,irs1));
g11=cell2mat(sij1(irs1,irs2));
g22=cell2mat(sij2(irs1,irs2));
r_t1=r1';
T11=0;
T22=0;
for t11=1:length(g11)
T11(t11)=conj((g11(t11)*t1(t11))/abs(t1(t11)));
T22(t11)=conj((r_t1(t11)*g22(t11))/abs(r_t1(t11)));
end
phi11=diag(T11);
phi22=diag(T22);
h11(irs1,irs2,n_e)=r1'*phi22*S1*phi11*t1;
h11(irs2,irs1,n_e)= h11(irs1,irs2,n_e);
% Channel between BS2 and user 2
r2=cell2mat(hu_i(2,irs2));
S2=cell2mat(hi_i(irs1,irs2));
t2=cell2mat(hb_i(2,irs1));
g33=cell2mat(sij1(irs1,irs2));
g44=cell2mat(sij2(irs1,irs2));
r_t2=r2';
T33=0;
T44=0;
for t22=1:nn
T33(t22)=conj((g33(t22)*t2(t22))/abs(t2(t22)));
T44(t22)=conj((r_t2(t22)*g44(t22))/abs(r_t2(t22)));
end
phi33=diag(T33);
phi44=diag(T44);
h22(irs1,irs2,n_e)=r2'*phi44*S2*phi33*t2;
h22(irs2,irs1,n_e)= h22(irs1,irs2,n_e);
% %% Channel between BS3 and user 3
r3=cell2mat(hu_i(3,irs1));
S3=cell2mat(hi_i(irs1,irs2));
t3=cell2mat(hb_i(3,irs1));
g55=cell2mat(sij1(irs1,irs2));
g66=cell2mat(sij2(irs1,irs2));
r_t3=r3';
T55=0;
T66=0;
for t33=1:nn
T55(t33)=conj((g55(t33)*t3(t33))/abs(t3(t33)));
T66(t33)=conj((r_t3(t33)*g66(t33))/abs(r_t3(t33)));
end
phi55=diag(T55);
phi66=diag(T66);
h33(irs1,irs2,n_e)=r3'*phi66*S3*phi55*t3;
h33(irs2,irs1,n_e)=h33(irs1,irs2,n_e);
% %% Channel between BS4 and user 4
r4=cell2mat(hu_i(4,irs2));
S4=cell2mat(hi_i(irs1,irs2));
t4=cell2mat(hb_i(4,irs1));
g77=cell2mat(sij1(irs1,irs2));
g88=cell2mat(sij2(irs1,irs2));
r_t4=r4';
T77=0;
T88=0;
for t44=1:nn
T77(t44)=conj((g77(t44)*t4(t44))/abs(t4(t44)));
T88(t44)=conj((r_t4(t44)*g88(t44))/abs(r_t4(t44)));
end
phi77=diag(T77);
phi88=diag(T88);
h44(irs1,irs2,n_e)=r4'*phi88*S4*phi77*t4;
h44(irs2,irs1,n_e)=h44(irs1,irs2,n_e);
end
rr=rr-1;
end
%% Clustering
A = [X3 Y3] ; % points
G = 4 ; % number of groups
C = [(x_u+x_b)/2 (y_u+y_b)/2] ; % centroids
[idx, C] = kmeans(A,G,'MaxIter',10,'Start',C);
% gscatter(A(:,1),A(:,2),idx)
% hold on
% plot(C(:,1),C(:,2),'y*','Linewidth',6)
% legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4','Cluster Centroid')
P_by_cluster = splitapply(@(varargin) varargin, A, idx);
% index finding
% Cluster # 1
B1=(cell2mat(P_by_cluster(1)));
tic
idx=method_1(A,B1);
toc
disp(A(idx));
disp(idx);
i1=[idx(:,1)];
% Cluster # 2
B2=(cell2mat(P_by_cluster(2)));
tic
idx=method_1(A,B2);
toc
disp(A(idx));
disp(idx);
i2=[idx(:,1)];
% Cluster # 3
B3=(cell2mat(P_by_cluster(3)));
tic
idx=method_1(A,B3);
toc
disp(A(idx));
disp(idx);
i3=[idx(:,1)];
% Cluster # 4
B4=(cell2mat(P_by_cluster(4)));
tic
idx=method_1(A,B4);
toc
disp(A(idx));
disp(idx);
i4=[idx(:,1)];
r_irs = randperm(L); % Random non repeating IRS
%% Trellis for BS1
if(length(i1)==1)
r1=cell2mat(hu_i(1,i1));
t1=cell2mat(hb_i(1,i1));
h1f=r1'*t1;
elseif length(i1)==2
h1f=h11(i1(1),i1(2),n_e);
elseif length(i1)==3
%% stage2
b1=sort(i1);
tt11=cell2mat(hb_i(1,b1(1)));
tt12=cell2mat(hb_i(1,b1(2)));
tt13=cell2mat(hb_i(1,b1(3)));
%%
S21=cell2mat(hi_i(b1(2),b1(1)));
S31=cell2mat(hi_i(b1(3),b1(1)));
S23=cell2mat(hi_i(b1(3),b1(2)));
g21=cell2mat(sij1(b1(2),b1(1)));
g31=cell2mat(sij1(b1(3),b1(1)));
g23=cell2mat(sij1(b1(2),b1(3)));
g12=cell2mat(sij1(b1(1),b1(2)));
g13=cell2mat(sij1(b1(1),b1(3)));
g32=cell2mat(sij1(b1(3),b1(2)));
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*tt12(t11))/abs(tt12(t11)));
T31(t11)=conj((g31(t11)*tt13(t11))/abs(tt13(t11)));
T23(t11)=conj((g23(t11)*tt12(t11))/abs(tt12(t11)));
T12(t11)=conj((g12(t11)*tt11(t11))/abs(tt11(t11)));
T13(t11)=conj((g13(t11)*tt11(t11))/abs(tt11(t11)));
T32(t11)=conj((g32(t11)*tt13(t11))/abs(tt13(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
max=0;
% state 1
s1_1=tt11;
s1_2=tt12'*phi21*S21;
s1_3=tt13'*phi31*S23;
if ((norm(s1_1,"fro")^2>(norm(s1_2,"fro"))^2) && (norm(s1_1,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_1;
elseif ((norm(s1_2,"fro")^2>(norm(s1_1,"fro"))^2) && (norm(s1_2,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_2;
else
s1_f=s1_3;
end
% state 2
s12_1=tt12;
s12_2=tt11'*phi12*S21;
s12_3=tt13'*phi32*S23;
if ((norm(s12_1,"fro")^2>(norm(s12_2,"fro"))^2) && (norm(s12_1,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_1;
elseif ((norm(s12_2,"fro")^2>(norm(s12_1,"fro"))^2) && (norm(s12_2,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_2;
else
s12_f=s12_3;
end
% state 3
s13_1=tt13;
s13_2=tt11'*phi13*S31;
s13_3=tt13'*phi23*S23;
if ((norm(s13_1,"fro")^2>(norm(s13_2,"fro"))^2) && (norm(s13_1,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_1;
elseif ((norm(s13_2,"fro")^2>(norm(s13_1,"fro"))^2) && (norm(s13_2,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_2;
else
s13_f=s13_3;
end
%% stage 3
phi21=0;phi31=0; phi23=0;phi12=0;phi13=0;phi32=0;
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*s12_f(t11))/abs(s12_f(t11)));
T31(t11)=conj((g31(t11)*s13_f(t11))/abs(s13_f(t11)));
T23(t11)=conj((g23(t11)*s12_f(t11))/abs(s12_f(t11)));
T12(t11)=conj((g12(t11)*s1_f(t11))/abs(s1_f(t11)));
T13(t11)=conj((g13(t11)*s1_f(t11))/abs(s1_f(t11)));
T32(t11)=conj((g32(t11)*s13_f(t11))/abs(s13_f(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
% state 1
s2_1=s1_f;
s2_2=s12_f'*phi21*S21;
s2_3=s13_f'*phi31*S31;
if ((norm(s2_1,"fro")^2>(norm(s2_2,"fro"))^2) && (norm(s2_1,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_1;
max=1;
elseif ((norm(s2_2,"fro")^2>(norm(s2_1,"fro"))^2) && (norm(s2_2,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_2;
max=2;
else
s2_f=s2_3;
max=3;
end
% % state 2
s22_1=s12_f;
s22_2=s1_f'*phi12.*S21;
s22_3=s13_f'*phi32.*S23;
if ((norm(s22_1,"fro")^2>(norm(s22_2,"fro"))^2) && (norm(s22_1,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_1;
elseif ((norm(s22_2,"fro")^2>(norm(s22_1,"fro"))^2) && (norm(s22_2,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_2;
else
s22_f=s22_3;
end
% state 3
s23_1=s13_f;
s23_2=s1_f'*phi13.*S31;
s23_3=s12_f'*phi23.*S23;
if ((norm(s23_1,"fro")^2>(norm(s23_2,"fro"))^2) && (norm(s23_1,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_1;
elseif ((norm(s23_2,"fro")^2>(norm(s23_1,"fro"))^2) && (norm(s23_2,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_2;
else
s23_f=s23_3;
end
%% Final stage
r11=cell2mat(hu_i(1,b1(1)));
r12=cell2mat(hu_i(1,b1(2)));
r13=cell2mat(hu_i(1,b1(3)));
g11=0;g12=0;g13=0;
g11=cell2mat(sij2(b1(max),b1(1)));
g12=cell2mat(sij2(b1(max),b1(2)));
g13=cell2mat(sij2(b1(max),b1(3)));
%
T11=0;T12=0;T13=0;
phi11=0; phi12=0; phi13=0;
for t11=1:nn
% T11(t11)=conj((r11(t11)*g11(t11))/abs(r11(t11)));
T12(t11)=conj((r12(t11)*g12(t11))/abs(r12(t11)));
T13(t11)=conj((r13(t11)*g13(t11))/abs(r13(t11)));
end
phi12=diag(T12); phi13=diag(T13);
s2r_f = s2_f'*r11;
s22r_f=s22_f'*phi12*r12;
s23r_f=s23_f'*phi13*r13;
if ((norm(s2r_f,"fro")^2>(norm(s22r_f,"fro"))^2) && (norm(s2r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h1f=s2r_f;
elseif ((norm(s22r_f,"fro")^2>(norm(s2r_f,"fro"))^2) && (norm(s22r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h1f=s22r_f;
else
h1f=s23r_f;
end
else
h1f=0.068+0.1*j;
end
%% Trellis for BS2
if(length(i2)==1)
r1=cell2mat(hu_i(2,i2));
t1=cell2mat(hb_i(2,i2));
h2f=r1'*t1;
elseif length(i2)==2
h2f=h22(i2(1),i2(2),n_e);
elseif length(i2)==3
%% stage2
b2=sort(i2);
tt11=cell2mat(hb_i(2,b2(1)));
tt12=cell2mat(hb_i(2,b2(2)));
tt13=cell2mat(hb_i(2,b2(3)));
%%
S21=cell2mat(hi_i(b2(2),b2(1)));
S31=cell2mat(hi_i(b2(3),b2(1)));
S23=cell2mat(hi_i(b2(3),b2(2)));
g21=cell2mat(sij1(b2(2),b2(1)));
g31=cell2mat(sij1(b2(3),b2(1)));
g23=cell2mat(sij1(b2(2),b2(3)));
g12=cell2mat(sij1(b2(1),b2(2)));
g13=cell2mat(sij1(b2(1),b2(3)));
g32=cell2mat(sij1(b2(3),b2(2)));
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*tt12(t11))/abs(tt12(t11)));
T31(t11)=conj((g31(t11)*tt13(t11))/abs(tt13(t11)));
T23(t11)=conj((g23(t11)*tt12(t11))/abs(tt12(t11)));
T12(t11)=conj((g12(t11)*tt11(t11))/abs(tt11(t11)));
T13(t11)=conj((g13(t11)*tt11(t11))/abs(tt11(t11)));
T32(t11)=conj((g32(t11)*tt13(t11))/abs(tt13(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
max=0;
% state 1
s1_1=tt11;
s1_2=tt12'*phi21*S21;
s1_3=tt13'*phi31*S23;
if ((norm(s1_1,"fro")^2>(norm(s1_2,"fro"))^2) && (norm(s1_1,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_1;
elseif ((norm(s1_2,"fro")^2>(norm(s1_1,"fro"))^2) && (norm(s1_2,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_2;
else
s1_f=s1_3;
end
% state 2
s12_1=tt12;
s12_2=tt11'*phi12*S21;
s12_3=tt13'*phi32*S23;
if ((norm(s12_1,"fro")^2>(norm(s12_2,"fro"))^2) && (norm(s12_1,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_1;
elseif ((norm(s12_2,"fro")^2>(norm(s12_1,"fro"))^2) && (norm(s12_2,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_2;
else
s12_f=s12_3;
end
% state 3
s13_1=tt13;
s13_2=tt11'*phi13*S31;
s13_3=tt13'*phi23*S23;
if ((norm(s13_1,"fro")^2>(norm(s13_2,"fro"))^2) && (norm(s13_1,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_1;
elseif ((norm(s13_2,"fro")^2>(norm(s13_1,"fro"))^2) && (norm(s13_2,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_2;
else
s13_f=s13_3;
end
%% stage 3
phi21=0;phi31=0; phi23=0;phi12=0;phi13=0;phi32=0;
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*s12_f(t11))/abs(s12_f(t11)));
T31(t11)=conj((g31(t11)*s13_f(t11))/abs(s13_f(t11)));
T23(t11)=conj((g23(t11)*s12_f(t11))/abs(s12_f(t11)));
T12(t11)=conj((g12(t11)*s1_f(t11))/abs(s1_f(t11)));
T13(t11)=conj((g13(t11)*s1_f(t11))/abs(s1_f(t11)));
T32(t11)=conj((g32(t11)*s13_f(t11))/abs(s13_f(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
% state 1
s2_1=s1_f;
s2_2=s12_f'*phi21*S21;
s2_3=s13_f'*phi31*S31;
if ((norm(s2_1,"fro")^2>(norm(s2_2,"fro"))^2) && (norm(s2_1,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_1;
max=1;
elseif ((norm(s2_2,"fro")^2>(norm(s2_1,"fro"))^2) && (norm(s2_2,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_2;
max=2;
else
s2_f=s2_3;
max=3;
end
% % state 2
s22_1=s12_f;
s22_2=s1_f'*phi12*S21;
s22_3=s13_f'*phi32*S23;
if ((norm(s22_1,"fro")^2>(norm(s22_2,"fro"))^2) && (norm(s22_1,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_1;
elseif ((norm(s22_2,"fro")^2>(norm(s22_1,"fro"))^2) && (norm(s22_2,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_2;
else
s22_f=s22_3;
end
% state 3
s23_1=s13_f;
s23_2=s1_f'*phi13.*S31;
s23_3=s12_f'*phi23.*S23;
if ((norm(s23_1,"fro")^2>(norm(s23_2,"fro"))^2) && (norm(s23_1,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_1;
elseif ((norm(s23_2,"fro")^2>(norm(s23_1,"fro"))^2) && (norm(s23_2,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_2;
else
s23_f=s23_3;
end
%% Final stage
r11=cell2mat(hu_i(2,b2(1)));
r12=cell2mat(hu_i(2,b2(2)));
r13=cell2mat(hu_i(2,b2(3)));
g11=0;g12=0;g13=0;
g11=cell2mat(sij2(b2(max),b2(1)));
g12=cell2mat(sij2(b2(max),b2(2)));
g13=cell2mat(sij2(b2(max),b2(3)));
%
T11=0;T12=0;T13=0;
phi11=0; phi12=0; phi13=0;
for t11=1:nn
% T11(t11)=conj((r11(t11)*g11(t11))/abs(r11(t11)));
T12(t11)=conj((r12(t11)*g12(t11))/abs(r12(t11)));
T13(t11)=conj((r13(t11)*g13(t11))/abs(r13(t11)));
end
phi12=diag(T12); phi13=diag(T13);
s2r_f = s2_f'*r11;
s22r_f=s22_f'*phi12*r12;
s23r_f=s23_f'*phi13*r13;
if ((norm(s2r_f,"fro")^2>(norm(s22r_f,"fro"))^2) && (norm(s2r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h2f=s2r_f;
elseif ((norm(s22r_f,"fro")^2>(norm(s2r_f,"fro"))^2) && (norm(s22r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h2f=s22r_f;
else
h2f=s23r_f;
end
else
h2f=0.098+0.1*j;
end
%% Trellis for BS3
if(length(i3)==1)
r1=cell2mat(hu_i(3,i3));
t1=cell2mat(hb_i(3,i3));
h3f=r1'*t1;
elseif length(i3)==2
h3f=h33(i3(1),i3(2),n_e);
elseif length(i3)==3
%% stage2
b3=sort(i3);
tt11=cell2mat(hb_i(3,b3(1)));
tt12=cell2mat(hb_i(3,b3(2)));
tt13=cell2mat(hb_i(3,b3(3)));
%%
S21=cell2mat(hi_i(b3(2),b3(1)));
S31=cell2mat(hi_i(b3(3),b3(1)));
S23=cell2mat(hi_i(b3(3),b3(2)));
g21=cell2mat(sij1(b3(2),b3(1)));
g31=cell2mat(sij1(b3(3),b3(1)));
g23=cell2mat(sij1(b3(2),b3(3)));
g12=cell2mat(sij1(b3(1),b3(2)));
g13=cell2mat(sij1(b3(1),b3(3)));
g32=cell2mat(sij1(b3(3),b3(2)));
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*tt12(t11))/abs(tt12(t11)));
T31(t11)=conj((g31(t11)*tt13(t11))/abs(tt13(t11)));
T23(t11)=conj((g23(t11)*tt12(t11))/abs(tt12(t11)));
T12(t11)=conj((g12(t11)*tt11(t11))/abs(tt11(t11)));
T13(t11)=conj((g13(t11)*tt11(t11))/abs(tt11(t11)));
T32(t11)=conj((g32(t11)*tt13(t11))/abs(tt13(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
max=0;
% state 1
s1_1=tt11;
s1_2=tt12'*phi21*S21;
s1_3=tt13'*phi31*S23;
if ((norm(s1_1,"fro")^2>(norm(s1_2,"fro"))^2) && (norm(s1_1,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_1;
elseif ((norm(s1_2,"fro")^2>(norm(s1_1,"fro"))^2) && (norm(s1_2,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_2;
else
s1_f=s1_3;
end
% state 2
s12_1=tt12;
s12_2=tt11'*phi12*S21;
s12_3=tt13'*phi32*S23;
if ((norm(s12_1,"fro")^2>(norm(s12_2,"fro"))^2) && (norm(s12_1,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_1;
elseif ((norm(s12_2,"fro")^2>(norm(s12_1,"fro"))^2) && (norm(s12_2,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_2;
else
s12_f=s12_3;
end
% state 3
s13_1=tt13;
s13_2=tt11'*phi13*S31;
s13_3=tt13'*phi23*S23;
if ((norm(s13_1,"fro")^2>(norm(s13_2,"fro"))^2) && (norm(s13_1,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_1;
elseif ((norm(s13_2,"fro")^2>(norm(s13_1,"fro"))^2) && (norm(s13_2,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_2;
else
s13_f=s13_3;
end
%% stage 3
phi21=0;phi31=0; phi23=0;phi12=0;phi13=0;phi32=0;
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*s12_f(t11))/abs(s12_f(t11)));
T31(t11)=conj((g31(t11)*s13_f(t11))/abs(s13_f(t11)));
T23(t11)=conj((g23(t11)*s12_f(t11))/abs(s12_f(t11)));
T12(t11)=conj((g12(t11)*s1_f(t11))/abs(s1_f(t11)));
T13(t11)=conj((g13(t11)*s1_f(t11))/abs(s1_f(t11)));
T32(t11)=conj((g32(t11)*s13_f(t11))/abs(s13_f(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
% state 1
s2_1=s1_f;
s2_2=s12_f'*phi21*S21;
s2_3=s13_f'*phi31*S31;
if ((norm(s2_1,"fro")^2>(norm(s2_2,"fro"))^2) && (norm(s2_1,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_1;
max=1;
elseif ((norm(s2_2,"fro")^2>(norm(s2_1,"fro"))^2) && (norm(s2_2,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_2;
max=2;
else
s2_f=s2_3;
max=3;
end
% % state 2
s22_1=s12_f;
s22_2=s1_f'*phi12.*S21;
s22_3=s13_f'*phi32.*S23;
if ((norm(s22_1,"fro")^2>(norm(s22_2,"fro"))^2) && (norm(s22_1,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_1;
elseif ((norm(s22_2,"fro")^2>(norm(s22_1,"fro"))^2) && (norm(s22_2,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_2;
else
s22_f=s22_3;
end
% state 3
s23_1=s13_f;
s23_2=s1_f'*phi13.*S31;
s23_3=s12_f'*phi23.*S23;
if ((norm(s23_1,"fro")^2>(norm(s23_2,"fro"))^2) && (norm(s23_1,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_1;
elseif ((norm(s23_2,"fro")^2>(norm(s23_1,"fro"))^2) && (norm(s23_2,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_2;
else
s23_f=s23_3;
end
%% Final stage
r11=cell2mat(hu_i(3,b3(1)));
r12=cell2mat(hu_i(3,b3(2)));
r13=cell2mat(hu_i(3,b3(3)));
g11=0;g12=0;g13=0;
g11=cell2mat(sij2(b3(max),b3(1)));
g12=cell2mat(sij2(b3(max),b3(2)));
g13=cell2mat(sij2(b3(max),b3(3)));
%
T11=0;T12=0;T13=0;
phi11=0; phi12=0; phi13=0;
for t11=1:nn
% T11(t11)=conj((r11(t11)*g11(t11))/abs(r11(t11)));
T12(t11)=conj((r12(t11)*g12(t11))/abs(r12(t11)));
T13(t11)=conj((r13(t11)*g13(t11))/abs(r13(t11)));
end
phi12=diag(T12); phi13=diag(T13);
s2r_f = s2_f'*r11;
s22r_f=s22_f'*phi12*r12;
s23r_f=s23_f'*phi13*r13;
if ((norm(s2r_f,"fro")^2>(norm(s22r_f,"fro"))^2) && (norm(s2r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h3f=s2r_f;
elseif ((norm(s22r_f,"fro")^2>(norm(s2r_f,"fro"))^2) && (norm(s22r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h3f=s22r_f;
else
h3f=s23r_f;
end
else
h3f=0.048+0.1*j;
end
%% Trellis for BS4
if(length(i4)==1)
r1=cell2mat(hu_i(4,i4));
t1=cell2mat(hb_i(4,i4));
h4f=r1'*t1;
elseif length(i4)==2
h4f=h11(i4(1),i4(2),n_e);
elseif length(i4)==3
%% stage2
b4=sort(i4);
tt11=cell2mat(hb_i(4,b4(1)));
tt12=cell2mat(hb_i(4,b4(2)));
tt13=cell2mat(hb_i(4,b4(3)));
%%
S21=cell2mat(hi_i(b4(2),b4(1)));
S31=cell2mat(hi_i(b4(3),b4(1)));
S23=cell2mat(hi_i(b4(3),b4(2)));
g21=cell2mat(sij1(b4(2),b4(1)));
g31=cell2mat(sij1(b4(3),b4(1)));
g23=cell2mat(sij1(b4(2),b4(3)));
g12=cell2mat(sij1(b4(1),b4(2)));
g13=cell2mat(sij1(b4(1),b4(3)));
g32=cell2mat(sij1(b4(3),b4(2)));
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*tt12(t11))/abs(tt12(t11)));
T31(t11)=conj((g31(t11)*tt13(t11))/abs(tt13(t11)));
T23(t11)=conj((g23(t11)*tt12(t11))/abs(tt12(t11)));
T12(t11)=conj((g12(t11)*tt11(t11))/abs(tt11(t11)));
T13(t11)=conj((g13(t11)*tt11(t11))/abs(tt11(t11)));
T32(t11)=conj((g32(t11)*tt13(t11))/abs(tt13(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
max=0;
% state 1
s1_1=tt11;
s1_2=tt12'*phi21*S21;
s1_3=tt13'*phi31*S23;
if ((norm(s1_1,"fro")^2>(norm(s1_2,"fro"))^2) && (norm(s1_1,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_1;
elseif ((norm(s1_2,"fro")^2>(norm(s1_1,"fro"))^2) && (norm(s1_2,"fro")^2>(norm(s1_3,"fro"))^2))
s1_f=s1_2;
else
s1_f=s1_3;
end
% state 2
s12_1=tt12;
s12_2=tt11'*phi12*S21;
s12_3=tt13'*phi32*S23;
if ((norm(s12_1,"fro")^2>(norm(s12_2,"fro"))^2) && (norm(s12_1,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_1;
elseif ((norm(s12_2,"fro")^2>(norm(s12_1,"fro"))^2) && (norm(s12_2,"fro")^2>(norm(s12_3,"fro"))^2))
s12_f=s12_2;
else
s12_f=s12_3;
end
% state 3
s13_1=tt13;
s13_2=tt11'*phi13*S31;
s13_3=tt13'*phi23*S23;
if ((norm(s13_1,"fro")^2>(norm(s13_2,"fro"))^2) && (norm(s13_1,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_1;
elseif ((norm(s13_2,"fro")^2>(norm(s13_1,"fro"))^2) && (norm(s13_2,"fro")^2>(norm(s13_3,"fro"))^2))
s13_f=s13_2;
else
s13_f=s13_3;
end
%% stage 3
phi21=0;phi31=0; phi23=0;phi12=0;phi13=0;phi32=0;
T21=0; T31=0; T23=0;T12=0;T13=0;T32=0;
for t11=1:nn
T21(t11)=conj((g21(t11)*s12_f(t11))/abs(s12_f(t11)));
T31(t11)=conj((g31(t11)*s13_f(t11))/abs(s13_f(t11)));
T23(t11)=conj((g23(t11)*s12_f(t11))/abs(s12_f(t11)));
T12(t11)=conj((g12(t11)*s1_f(t11))/abs(s1_f(t11)));
T13(t11)=conj((g13(t11)*s1_f(t11))/abs(s1_f(t11)));
T32(t11)=conj((g32(t11)*s13_f(t11))/abs(s13_f(t11)));
end
phi21=diag(T21);
phi31=diag(T31);
phi23=diag(T23);
phi12=diag(T12);
phi13=diag(T13);
phi32=diag(T32);
% state 1
s2_1=s1_f;
s2_2=s12_f'*phi21*S21;
s2_3=s13_f'*phi31*S31;
if ((norm(s2_1,"fro")^2>(norm(s2_2,"fro"))^2) && (norm(s2_1,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_1;
max=1;
elseif ((norm(s2_2,"fro")^2>(norm(s2_1,"fro"))^2) && (norm(s2_2,"fro")^2>(norm(s2_3,"fro"))^2))
s2_f=s2_2;
max=2;
else
s2_f=s2_3;
max=3;
end
% % state 2
s22_1=s12_f;
s22_2=s1_f'*phi12.*S21;
s22_3=s13_f'*phi32.*S23;
if ((norm(s22_1,"fro")^2>(norm(s22_2,"fro"))^2) && (norm(s22_1,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_1;
elseif ((norm(s22_2,"fro")^2>(norm(s22_1,"fro"))^2) && (norm(s22_2,"fro")^2>(norm(s22_3,"fro"))^2))
s22_f=s22_2;
else
s22_f=s22_3;
end
% state 3
s23_1=s13_f;
s23_2=s1_f'*phi13.*S31;
s23_3=s12_f'*phi23.*S23;
if ((norm(s23_1,"fro")^2>(norm(s23_2,"fro"))^2) && (norm(s23_1,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_1;
elseif ((norm(s23_2,"fro")^2>(norm(s23_1,"fro"))^2) && (norm(s23_2,"fro")^2>(norm(s23_3,"fro"))^2))
s23_f=s23_2;
else
s23_f=s23_3;
end
%% Final stage
r11=cell2mat(hu_i(4,b4(1)));
r12=cell2mat(hu_i(4,b4(2)));
r13=cell2mat(hu_i(4,b4(3)));
g11=0;g12=0;g13=0;
g11=cell2mat(sij2(b4(max),b4(1)));
g12=cell2mat(sij2(b4(max),b4(2)));
g13=cell2mat(sij2(b4(max),b4(3)));
%
T11=0;T12=0;T13=0;
phi11=0; phi12=0; phi13=0;
for t11=1:nn
% T11(t11)=conj((r11(t11)*g11(t11))/abs(r11(t11)));
T12(t11)=conj((r12(t11)*g12(t11))/abs(r12(t11)));
T13(t11)=conj((r13(t11)*g13(t11))/abs(r13(t11)));
end
phi12=diag(T12); phi13=diag(T13);
s2r_f = s2_f'*r11;
s22r_f=s22_f'*phi12*r12;
s23r_f=s23_f'*phi13*r13;
if ((norm(s2r_f,"fro")^2>(norm(s22r_f,"fro"))^2) && (norm(s2r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h4f=s2r_f;
elseif ((norm(s22r_f,"fro")^2>(norm(s2r_f,"fro"))^2) && (norm(s22r_f,"fro")^2>(norm(s23r_f,"fro"))^2))
h4f=s22r_f;
else
h4f=s23r_f;
end
else
h4f=0.79;
end
%% Signal to Noise Ratio
SNR1_1=(powerTx*abs(h1f)^2)/((Sigma)^2);
SNR2_2=(powerTx*abs(h2f)^2)/((Sigma)^2);
SNR3_3=(powerTx*abs(h3f)^2)/((Sigma)^2);
SNR4_4=(powerTx*abs(h4f)^2)/((Sigma)^2);
C11=log2(1+SNR1_1);
C22=log2(1+SNR2_2);
C33=log2(1+SNR3_3);
C44=log2(1+SNR4_4);
cc11=cc11+C11;
cc22=cc22+C22;
cc33=cc33+C33;
cc44=cc44+C44;
% % sum= C11+C22+C33+C44;
end
CCC11=(cc11)/10;
CCC22=(cc22)/10;
CCC33=(cc33)/10;
CCC44=(cc44)/10;
Sum(n_e)=CCC11+CCC22+CCC33+CCC4;
end
plot(tt,Sum,'-','Linewidth',2);
title('Random Allocation with Optimized Phases')
xlim([100 200]);
ylim([1 100]);
xticks(100:100:200);
xlabel('Number of elements');
ylabel('Sum rate');
grid on
hold on
end
legend('P=0 db','P=5 db','P=10 db','P=15 db','P=20 db');

回答(1 个)

Image Analyst
Image Analyst 2022-4-13
I didn't run it, but in this kind of situation, the most likely cause was the user not having vectors in plot(), but having scalars, which plot only a single point. And if you don't give it a marker, it won't plot anything. Try
plot(tt, Sum, 'b.', 'MarkerSize', 15);
If that doesn't work, write back.
  5 个评论
Maimoona Asad
Maimoona Asad 2022-4-13
function array=array_resp(N,NN,theta_a,theta_e)
lambda=0.06;
l=lambda/4;
s_v1=[];
for nn=0:N-1
h_d1=exp(-1j*pi*(nn)*((2*l)/lambda)*sin(theta_e)*cos(theta_a));
s_v1=[s_v1 h_d1];
end
sv_1=(s_v1)';
s_v2=[];
for nnn=0:NN-1
h_d2=exp(-1j*pi*(nnn)*((2*l)/lambda)*cos(theta_e));
s_v2=[s_v2 h_d2];
end
sv_2=(s_v2)';
array=kron(sv_1,sv_2);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Time Series 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by