无线携能通信网络在多用户接收用户时的波束成形优化代码

clear all
clc


 for j=1:50
q1 = 20;
q2 = 30;
q3 = 15;
q4 = 5;
sigma_sq = 1;

W(:,:,1) = eye(2);
W(:,:,2) = eye(2);
V = eye(2);

h1 = complex(randn(2,1),randn(2,1)); 
h2 = complex(randn(2,1),randn(2,1)); 
h3 = complex(randn(2,1),randn(2,1)); 
h4 = complex(randn(2,1),randn(2,1)); 


g1 = complex(randn(2,1),randn(2,1)); 
g2 = complex(randn(2,1),randn(2,1)); 
g3 = complex(randn(2,1),randn(2,1)); 
g4 = complex(randn(2,1),randn(2,1)); 
 

t = -1;

 minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq);
 minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq);
 u1 = max(minus_SINR1,minus_SINR2);
 k = 1;
while abs(t) >= 1e-3
    cvx_begin sdp
    variable W(2,2,2) complex hermitian
    variable V(2,2) complex hermitian 
    variable t 
    minimize t;
    subject to
       trace( W(:,:,1)+W(:,:,2) ) <= q1;  % information power constraint
       trace(V) <= q2;                           % energy power constraints
       W(:,:,1) == hermitian_semidefinite(2);
       W(:,:,2) == hermitian_semidefinite(2);
       V == hermitian_semidefinite(2);  
       
       real( h3'*( W(:,:,1)+W(:,:,2) )*h3 + g3'*V*g3 ) >= q3;  % EH constraint
       imag( h3'*( W(:,:,1)+W(:,:,2) )*h3 + g3'*V*g3 ) == 0;
       real( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) <= q4; % Interference constraint 
       imag( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) == 0;
       real( - h1'*W(:,:,1)*h1 - u1*(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq) ) <= t; % mimus_SINR for user 1
       real( - h2'*W(:,:,2)*h2 - u1*(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq) ) <= t; % minus_SINR for user 2    
       imag( - h1'*W(:,:,1)*h1 - u1*(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq) ) == 0; 
       imag( - h2'*W(:,:,2)*h2 - u1*(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq) ) == 0;    
 cvx_end
 imag(u1)==0
 q(k)=real(u1)
 
 p(k) = t;
   
  if p(k) == 0
      W_opt = W;
      V_opt = V;
      break;
  else
      minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq);
      minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq);
      u1 = max(minus_SINR1,minus_SINR2);
      k = k+1;
  end
end
z1(j)=u1

W(:,:,1) = eye(2);
W(:,:,2) = eye(2);
V = eye(2);
t = -1;

 minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq);
 minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq);
 u2 = max(minus_SINR1,minus_SINR2);
 k = 1;
 g_value1 = h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq
 g_value2 = h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq

 
while abs(t) >= 1e-3
    cvx_begin sdp
    variable W(2,2,2) complex hermitian
    variable V(2,2) complex hermitian 
    variable t 
    minimize t;
    subject to
       trace( W(:,:,1)+W(:,:,2) ) <= q1;  % information power constraint
       trace(V) <= q2;                           % energy power constraints
       W(:,:,1) == hermitian_semidefinite(2);
       W(:,:,2) == hermitian_semidefinite(2);
       V == hermitian_semidefinite(2);  
       
       real( h3'*( W(:,:,1)+W(:,:,2) )*h3 + g3'*V*g3 ) >= q3;  % EH constraint
       imag( h3'*( W(:,:,1)+W(:,:,2) )*h3 + g3'*V*g3 ) == 0;
       real( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) <= q4; % Interference constraint 
       imag( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) == 0;
       real( ( - h1'*W(:,:,1)*h1 - u2*(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq))/g_value1 ) <= t; % mimus_SINR for user 1
       real( (- h2'*W(:,:,2)*h2 - u2*(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq))/ g_value2 ) <= t; % minus_SINR for user 2    
       imag( ( - h1'*W(:,:,1)*h1 - u2*(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq))/g_value1 ) == 0; 
       imag( (- h2'*W(:,:,2)*h2 - u2*(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq))/ g_value2 ) == 0;    
 cvx_end
  imag(u2)==0
 q(k)=real(u2)
 p(k) = t;
   
  if p(k) == 0
      W_opt = W;
      V_opt = V;
      break;
  else
      minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq);
      minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq);
      u2 = max(minus_SINR1,minus_SINR2);
      k = k+1;
  end
   g_value1 = h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq;
   g_value2 = h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq;
end
z2(j)=u2

W(:,:,1) = eye(2);
W(:,:,2) = eye(2);

V = eye(2);

t = -1;

 minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+sigma_sq);
 minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+sigma_sq);
 u3 = max(minus_SINR1,minus_SINR2);
 k = 1;
 
while abs(t) >= 1e-3
    cvx_begin sdp
    variable W(2,2,3) complex hermitian
    variable V(2,2) complex hermitian 
    variable t 
    minimize t;
    subject to
       trace( W(:,:,1)+W(:,:,2)+W(:,:,3) ) <= q1;  % information power constraint
       trace(V) <= q2;                           % energy power constraints
       W(:,:,1) == hermitian_semidefinite(2);
       W(:,:,2) == hermitian_semidefinite(2);
       W(:,:,3) == hermitian_semidefinite(2);
       V == hermitian_semidefinite(2);  
       
       real( h3'*( W(:,:,1)+W(:,:,2) + W(:,:,3))*h3 + g3'*V*g3 ) >= q3;  % EH constraint
       imag( h3'*( W(:,:,1)+W(:,:,2) + W(:,:,3) )*h3 + g3'*V*g3 ) == 0;
      % real( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) <= q4; % Interference constraint 
       %imag( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) == 0;
       real( - h1'*W(:,:,1)*h1 - u3*(h1'*W(:,:,2)*h1+sigma_sq) ) <= t; % mimus_SINR for user 1
       real( - h2'*W(:,:,2)*h2 - u3*(h2'*W(:,:,1)*h2+sigma_sq) ) <= t; % minus_SINR for user 2    
       imag( - h1'*W(:,:,1)*h1 - u3*(h1'*W(:,:,2)*h1+sigma_sq) ) == 0; 
       imag( - h2'*W(:,:,2)*h2 - u3*(h2'*W(:,:,1)*h2+sigma_sq) ) == 0;    
 cvx_end
 
 imag(u3)==0
 z(k)=real(u3)
 
 p(k) = t;
   
  if p(k) == 0
      W_opt = W;
      V_opt = V;
      break;
  else
      minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+sigma_sq);
      minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+sigma_sq);
      u3 = max(minus_SINR1,minus_SINR2);
      k = k+1;
  end
end
z3(j)=u3

W(:,:,1) = eye(2);
W(:,:,2) = eye(2);

V = eye(2);


t = -1;

 minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+sigma_sq);
 minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+sigma_sq);
 u4 = max(minus_SINR1,minus_SINR2);
 k = 1;
 g_value1 = h1'*W(:,:,2)*h1+sigma_sq
 g_value2 = h2'*W(:,:,1)*h2+sigma_sq

 
while abs(t) >= 1e-3
    cvx_begin sdp
    variable W(2,2,3) complex hermitian
    variable V(2,2) complex hermitian 
    variable t 
    minimize t;
    subject to
       trace( W(:,:,1)+W(:,:,2)+W(:,:,3) ) <= q1;  % information power constraint
       trace(V) <= q2;                           % energy power constraints
       W(:,:,1) == hermitian_semidefinite(2);
       W(:,:,2) == hermitian_semidefinite(2);
       W(:,:,3) == hermitian_semidefinite(2);
       V == hermitian_semidefinite(2); 
       
      real( h3'*( W(:,:,1)+W(:,:,2) + W(:,:,3))*h3 + g3'*V*g3 ) >= q3;  % EH constraint
       imag( h3'*( W(:,:,1)+W(:,:,2) + W(:,:,3) )*h3 + g3'*V*g3 ) == 0;
      % real( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) <= q4; % Interference constraint 
       %imag( h4'*( W(:,:,1)+W(:,:,2) )*h4 + g4'*V*g4 ) == 0;
       real( ( - h1'*W(:,:,1)*h1 - u4*(h1'*W(:,:,2)*h1+sigma_sq))/g_value1 ) <= t; % mimus_SINR for user 1
       real( (- h2'*W(:,:,2)*h2 - u4*(h2'*W(:,:,1)*h2+sigma_sq))/ g_value2 ) <= t; % minus_SINR for user 2    
       imag( ( - h1'*W(:,:,1)*h1 - u4*(h1'*W(:,:,2)*h1+sigma_sq))/g_value1 ) == 0; 
       imag( (- h2'*W(:,:,2)*h2 - u4*(h2'*W(:,:,1)*h2+sigma_sq))/ g_value2 ) == 0;    
 cvx_end
  imag(u4)==0
 l(k)=real(u4)
 p(k) = t;
   
  if p(k) == 0
      W_opt = W;
      V_opt = V;
      break;
  else
      minus_SINR1 = -h1'*W(:,:,1)*h1/(h1'*W(:,:,2)*h1+sigma_sq);
      minus_SINR2 = -h2'*W(:,:,2)*h2/(h2'*W(:,:,1)*h2+sigma_sq);
      u4 = max(minus_SINR1,minus_SINR2);
      k = k+1;
  end
   g_value1 = h1'*W(:,:,2)*h1+g1'*V*g1+sigma_sq;
   g_value2 = h2'*W(:,:,1)*h2+g2'*V*g2+sigma_sq;
end
z4(j)=u4
 end
 figure;
plot(1:length(z1),real(-z1),'-ro'); 
grid on;
hold on;
plot(1:length(z2),real(-z2),'-bo');
hold off;
hold on;
plot(1:length(z3),real(-z3),'-go');
hold off;
hold on;
plot(1:length(z4),real(-z4),'-mo');
hold off;

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值