I am trying to maximize the receiving SNR in a wireless communication system, but I am encountering fluctuations in the SNR values. I have three subproblems , and I suspect that there may be an issue in this part. any advice will help

function [wc_opt,ws_opt,Wc_opt,Ws_opt,SNR_BS_1] = Optimization_wc_ws(EdeltaS,r_max,Delta_theta,Delta_phi,lamda,theta_S,phi_S,HBR,h_RK1,h_RK2,h_RK3,h_BK1,h_BK2,h_BK3,sigma_BS,sigma_UE,Ptx,M,Nx,Ny,ome_in,wrx_in,d,accu,gamma)
Mr = 0;
Dff_S = ((Delta_phi*(1/accu))(Delta_theta(1/accu)));

for ind_phi = 1:accu
phi_tem = phi_S - Delta_phi/2 + Delta_phi*(ind_phi/accu);
for ind_theta = 1:accu
theta_tem = theta_S - Delta_theta/2 + Delta_theta*(ind_theta/accu);
% Array response
for i = 1:Nx
a_vec_tem1(i,1) = exp(1j*(2pid/lamda)(i-1) (sin(theta_tem)cos(phi_tem)) );
for i = 1:Ny
a_vec_tem2(i,1) = exp(1j
(2pid/lamda)(i-1) (sin(theta_tem)sin(phi_tem)) );
a_RIS_tem = kron(a_vec_tem1,a_vec_tem2);
% Matrix Mr:
mat_C = (EdeltaS
( HBR’diag(ome_in’)(a_RIS_tema_RIS_tem’)*diag(ome_in’)HBR(wrx_in…
*wrx_in’)HBR’diag(ome_in)(a_RIS_tema_RIS_tem’)*diag(ome_in)*HBR * sin(theta_tem) );

    Mr = Mr + mat_C * Dff_S;


% Matrix Xi
Ome_in = diag(ome_in);
Xi_1 = (HBR’*Ome_in’h_RK1+h_BK1)(h_RK1’Ome_inHBR+h_BK1’);
Xi_2 = (HBR’*Ome_in’h_RK2+h_BK2)(h_RK2’Ome_inHBR+h_BK2’);
Xi_3 = (HBR’*Ome_in’h_RK3+h_BK3)(h_RK3’Ome_inHBR+h_BK3’);

% Optimize wc ws
Mr = round(Mr,12);
Xi_1 = round(Xi_1,15);
Xi_2 = round(Xi_2,16);
Xi_3 = round(Xi_3,16);

cvx_begin quiet
cvx_solver sedumi
cvx_precision best
variable Wc(M,M) hermitian;
variable Ws(M,M) hermitian;
% variable wc(M,1);
% variable ws(M,1);
maximize (trace((Mr)(Wc+Ws)) )
subject to
Wc == hermitian_semidefinite(M);
Ws == hermitian_semidefinite(M);
trace(Wc + Ws) <= Ptx;
(Wc - gammaWs)) >= gamma(sigma_UE);
trace((Xi_2)(Wc - gammaWs)) >= gamma*(sigma_UE);
trace((Xi_3)(Wc - gammaWs)) >= gamma*(sigma_UE);

Wc_opt = Wc;
Ws_opt = Ws;

% Eigenvalue Decomposition
[Wc_x,Wc_y] = eig(Wc);
lamda_vec_Wc = diag(Wc_y);
[lamda_max_Wc,ii] = max(lamda_vec_Wc);
eigvec_max_c = Wc_x(:,ii);
wc_opt = sqrt(lamda_max_Wc)*eigvec_max_c;

[Ws_x,Ws_y] = eig(Ws);
lamda_vec_Ws = diag(Ws_y);
[lamda_max_Ws,ii] = max(lamda_vec_Ws);
eigvec_max_s = Ws_x(:,ii);
ws_opt = sqrt(lamda_max_Ws)*eigvec_max_s;

SNR_BS_1 = abs(trace((Mr)*(Wc_opt + Ws_opt)) );

Remove quiet and look at the solver and CVX output.

Never use cvx_precision best. Stick with the default setting.

Beyond that, your question is so vague, and readers probably have no idea what you’re doing or why, that they are unlikely to resolve your difficulties, whatever they are, which perhaps only you know.

"I wanted to maximize the signal-to-noise ratio(SNR) of the received signal, so I optimized the communication and sensing beamformer, the phase shift of the Reconfigurable Intelligent Surface (RIS), and the receive combining vector at the base station (BS). At each iteration, the value of the SNR should increase until convergence. However, I observed fluctuations in the values, and I am not sure why?!

Did you remove quiet and cvx_precision best? Did you carefully look at the solver and CVX output for each CVX problem solved?

I haven’t look carefully enough at the code to determine the scope of all the for loops. if CVX is called inside a for loop, what is changing between the CVX problems? is the result of one problem used as input for the next, for example, Successive Convex Approximation If so, it might not necessarily be the case that the process converges to anything, and that if it does, it converges monotonically.