% Solve the optimization problem
cvx_solver mosek
cvx_save_prefs
% Set the required parameters (replace these with actual values as per your case)
N = 4; % array number of BS
M = 64; % array number of IRS
SNR_dB = 10; % dBW
%%%%% noise
N0=10^((-174-30) / 10); %-174dBm
B=10^7; %10MHz
noise_maxpower_original = N0*B; % % W
noise_maxpower_original = 10^((-80-30) / 10); % % W
%%%%% ends
temp=10:5:40;
trans_maxpower_all =10.^((temp-30) ./ 10); % trans_power=1
miu_bs=0.01;
miu_u=0.01;
%% Simulation loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num_loop = 500;
load(‘G_U_all’);
load(‘G_E_all’);
% Ensure that the dimensions of G_U_all and G_E_all are compatible with your loop
[M_all, N_all, num_loops] = size(G_U_all); % Assuming G_U_all has size [M, N, num_loops]
% Set the original noise power level
% noise_maxpower_original = 1; % Replace with your actual value if needed
noise_maxpower = noise_maxpower_original;
% Loop over num_loops
for loop = 1:num_loops
outerflag = 1;
% Adjust G_U and G_E for the current loop
G_U = [G_U_all(1:M, 1:N, loop); G_U_all(M_all, 1:N, loop)] / sqrt(noise_maxpower_original);
G_E = [G_E_all(1:M, 1:N, loop); G_E_all(M_all, 1:N, loop)] / sqrt(noise_maxpower_original);
noise_maxpower = noise_maxpower_original / noise_maxpower_original;
% Loop over different transmission powers (SNR values)
fprintf(' loop | num_J | SNR | i | trans_SNR | relay_SNR \n');
for i_p = 1:length(trans_maxpower_all)
trans_maxpower = trans_maxpower_all(i_p); % Adjust based on current SNR setting
%%%%% Initialize F and e beamforming %%%%%
e_temp=randn(M+1,1) + sqrt(-1)* randn(M+1,1);
e_ini=exp(1j*angle(e_temp));
e_ini=ones(M+1,1);
f_ini=ones(N,1)*sqrt(trans_maxpower/(N));
% f_ini=randn(N,1)*sqrt(trans_maxpower/(N));
f(:,1)=f_ini;
e(:,1)=e_ini;
% miu_bs=0.01;
% miu_u=0.01;
cvx_begin quiet
variable E(M+1, M+1) hermitian
variable r(4,1)
variable p(4,1)
T_u = G_U*f_ini*f_ini'*G_U';
D_u = (1+miu_u)*miu_bs*G_U*diag(diag(f_ini*f_ini'))*G_U';
temp = trace(((1+miu_u)*T_u+D_u)*E) + noise_maxpower - r(1);
constraint(1) = -temp;
constraint(2) = trace((miu_u*T_u+D_u)*E) + noise_maxpower - r(2);
r_ini(2) = trace(e_ini'*(miu_u*T_u+D_u)*e_ini) + noise_maxpower;
T_e = G_E*f_ini*f_ini'*G_E';
D_e = miu_bs*G_E*diag(diag(f_ini*f_ini'))*G_E';
constraint(3) = trace((T_e+D_e)*E) + noise_maxpower - r(3);
r_ini(3) = trace(e_ini'*(T_e+D_e)*e_ini) + noise_maxpower;
temp = trace(D_e*E) + noise_maxpower - r(4);
constraint(4) = -temp;
constraint(5) = p(1) - log(r(1))/log(2);
constraint(6) = log2(r_ini(2)) + (r(2) - r_ini(2)) / (r_ini(2)*log(2)) - p(2);
constraint(7) = log2(r_ini(3)) + (r(3) - r_ini(3)) / (r_ini(3)*log(2)) - p(3);
constraint(8) = p(4) - log(r(4))/log(2);
maximize p(1) - p(2) - p(3) + p(4)
subject to
real(constraint) <= 0;
diag(E) == 1;
E == hermitian_semidefinite(M+1);
cvx_end
if cvx_status(1) == 'S' || cvx_status(3) == 'a'
flag = 1;
[t1, t2] = eig(E);
location = find(abs(diag(t2)) > 10^(-6));
if size(location, 1) == 1
e_hat = t1(:, location) * t2(location, location)^(1/2);
%%%%% Obj value %%%%%
numi_u = trace(e_hat' * ((1+miu_u)*T_u + D_u) * e_hat) + noise_maxpower;
deno_u = trace(e_hat' * (miu_u*T_u + D_u) * e_hat) + noise_maxpower;
rate_u = log2(numi_u / deno_u);
numi_e = trace(e_hat' * (T_e + D_e) * e_hat) + noise_maxpower;
deno_e = trace(e_hat' * D_e * e_hat) + noise_maxpower;
rate_e = log2(numi_e / deno_e);
rate = max(rate_u - rate_e, 0);
else
for i = 1:500
flag_2 = 1;
b1(:, i) = t1 * t2^(1/2) * sqrt(1/2) * (randn(M+1, 1) + sqrt(-1) * randn(M+1, 1));
b2(:, i) = exp(1j * angle(b1(:, i) / b1(M+1, i)));
%%%%% Obj value %%%%%
numi_u = trace(b2(:, i)' * ((1+miu_u)*T_u + D_u) * b2(:, i)) + noise_maxpower;
deno_u = trace(b2(:, i)' * (miu_u*T_u + D_u) * b2(:, i)) + noise_maxpower;
rate_u = log2(numi_u / deno_u);
numi_e = trace(b2(:, i)' * (T_e + D_e) * b2(:, i)) + noise_maxpower;
deno_e = trace(b2(:, i)' * D_e * b2(:, i)) + noise_maxpower;
rate_e = log2(numi_e / deno_e);
Obj(i) = max(rate_u - rate_e, 0);
end
[X, locat] = max(Obj);
e_hat = b2(:, locat);
rate = Obj(locat);
end
e = exp(1j * angle(e_hat / e_hat(M+1)));
fprintf('Resulting e for loop %d, i_p %d:\n', loop, i_p);
disp(e); % Display result for the current loop and i_p
else
flag = 0;
e = ones(M+1, 1);
rate = 0;
end
end
end
Unable to perform assignment because value of type ‘cvx’ is not convertible to ‘double’. Error in untitled5 (line 65) constraint(1) = -temp; Caused by: Error using double Conversion to double from cvx is not possible.