clc

clear

o=0;

M=30;

xBS= 0;

yBS = 0;

xBob= 0;

yBob = 100;

xW= 0;

yW = 150;

x0=-200;

y0=0;

xF=200;

yF=0;

H=50;

P=1000;

rouw=6;

Vmax=50;

sigmaK=db2pow(-120);

Nx = 5; % IRS单元个数

Ny = 6;

N = Nx*Ny;
beta0=db2pow(-50);
alphaIB = 2.2;
alphaBI = 2.2;
beta_BI = db2pow(3); % AP到RIS之间考虑莱斯信道，莱斯因子为3dB
beta_IB = db2pow(3); % IRS到User考虑瑞利莱斯信道，莱斯因子为3dB
theta = 2*pi

*rand(1,N); % 随机初始化IRS的相位*

Theta = diag(exp(1itheta));

Theta = diag(exp(1i

theta_BI=zeros(M,1);

theta_IB=zeros(M,1);

x_fea2=zeros(M,1);

y_fea2=zeros(M,1);

u0=zeros(M,1);

v0=zeros(M,1);

dBI0=zeros(M,1);

dIB0=zeros(M,1);

dIW0=zeros(M,1);

s0=zeros(M,1);

t0=zeros(M,1);

k0=zeros(M,1);

l0=zeros(M,1);

for i=1:M

x_fea2(i)=-200+(40/3)*i;
y_fea2(i)=-abs(x_fea2(i))+200;
u0(i)=((x_fea2(i)^2+y_fea2(i)^2+H^2)^1.1)*((x_fea2(i)^2+(y_fea2(i)-yBob)^2+H^2)^1.1);

v0(i)=((x_fea2(i)^2+y_fea2(i)^2+H^2)^1.1)*((x_fea2(i)^2+(y_fea2(i)-yW)^2+H^2)^1.1);

dBI0(i)=sqrt((x_fea2(i)^2+y_fea2(i)^2+H^2));

dIB0(i)=sqrt((x_fea2(i)^2+(y_fea2(i)-yBob)^2+H^2));

dIW0(i)=sqrt((x_fea2(i)^2+(y_fea2(i)-yW)^2+H^2));

end

eps = 1e-3;

maxIter = 20;

r0=0;

r=0;

hBI=zeros(M,N);

hIB=zeros(M,N);

count = 0;

K_AI = db2pow(10);

z2 = zeros(M,1);

Rate = zeros(M,1);

a=zeros(1,M);

A=P*beta0^2*N^2/sigmaK;

for i=1:M

a(i)=A/(log(2)*u0(i)*(u0(i)+A));

end

t2=-a*u0;
z1=sigmaK*(exp(0.01

*2*log(rouw))-1)/(rouw

*P);*

d0=zeros(M,1);

d1=zeros(M,1);

for i=1:M

d0(i)=0.5((dBI0(i)+dIB0(i))^2-(dBI0(i)^2+dIB0(i)^2));

d0=zeros(M,1);

d1=zeros(M,1);

for i=1:M

d0(i)=0.5

d1(i)=0.5*((dBI0(i)+dIW0(i))^2-(dBI0(i)^2+dIW0(i)^2));

end

for i=1:M

dBI(i)=sqrt((x_fea2(i)-xBS)^2+(y_fea2(i)-yBS)^2+H^2);

dIB(i)=sqrt((x_fea2(i)-xBob)^2+(y_fea2(i)-yBob)^2+H^2);

theta_BI(i) = (x_fea2(i)-xBS)/dBI(i);

theta_IB(i) = (x_fea2(i)-xBob)/dIB(i);

hBI(i,:)=sqrt(beta0*dBI(i)^(-alphaBI))*(sqrt(beta_BI/(1+beta_BI))*URA_sv(theta_BI(i),0,Nx,Ny)+sqrt(1/(1+beta_BI))*(randn(N,1)+1i*randn(N,1)/sqrt(2)));
hIB(i,:)=sqrt(beta0*dBI(i)^(-alphaIB))

*(sqrt(beta_IB/(1+beta_IB))*randn(N,1)/sqrt(2)));

*URA_sv(theta_IB(i),0,Nx,Ny)+sqrt(1/(1+beta_IB))*(randn(N,1)+1ithetaBI(i,:)=angle(hBI(i,:));

thetaIB(i,:)=angle(hIB(i,:));

end

cvx_begin

variable x(M,1)

variable y(M,1)

variable u(M,1)

variable v(M,1)

expression t1

t1=-a*u/M;
maximize t1
subject to
for i=1:M
N^2*beta0^2<=z1*v(i);

end

for i=1:M-1

(x(i+1)-x(i))^2+(y(i+1)-y(i))^2<=Vmax^2;

end

x(1)==x0;

y(1)==y0;

x(M)==xF;

y(M)==yF;

for i=1:M

u(i)^(1/2.2)>=d0(i)-(2*x_fea2(i)*(x(i)-x_fea2(i))+(2*y_fea2(i)-yBob)*(y(i)-y_fea2(i)));

d1(i)+(dBI0(i)+dIW0(i))*((x_fea2(i)*(x(i)-x_fea2(i))+y_fea2(i)*(y(i)-y_fea2(i)))/dBI0(i)+(x_fea2(i)*(x(i)-x_fea2(i))+(y_fea2(i)-yW)*(y(i)-y_fea2(i)))/dIW0(i))>=v0(i)^(1/2.2)+v0(i)^((1/2.2)-1)*(v(i)-v0(i))/2.2;

end

cvx_end