├── README.md └── dissertation ├── IRS_Receiver_channel.m ├── Transmitter_IRS_channel.m ├── computeQ_R.m ├── compute_Am_Bm.m ├── compute_C_noIRS.m ├── compute_final_Q.m ├── direct_channel.m ├── main.m └── wfill.m /README.md: -------------------------------------------------------------------------------- 1 | # dissertation 2 | This is the MATLAB code for my dissertation "Sum-rate optimization for IRS-aided MIMO communication" 3 | -------------------------------------------------------------------------------- /dissertation/IRS_Receiver_channel.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Generation of the IRS - Receiver channel %%%% 3 | 4 | function [R] = IRS_Receiver_channel(H_hat,Nr,dp_hat,dh_hat,do,alpha_IR,M,beta_o_lineal) 5 | 6 | dIR = sqrt(dh_hat^2+dp_hat^2+H_hat^2); 7 | beta_IR = beta_o_lineal*(dIR/do)^-alpha_IR; 8 | NLoS_IRS_Rx = sqrt(1/2)*(randn(Nr,M)+1j*randn(Nr,M)); 9 | R = sqrt(beta_IR)*NLoS_IRS_Rx; 10 | end 11 | 12 | -------------------------------------------------------------------------------- /dissertation/Transmitter_IRS_channel.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Generation of the Transmitter - IRS channel %%%% 3 | 4 | function [T] = Transmitter_IRS_channel(Nt,M,dp_hat,dh_hat,dD_hat,do,alpha_TI,beta_o_lineal) 5 | dTI = sqrt((dD_hat-dh_hat)^2+dp_hat^2); 6 | beta_TI = beta_o_lineal*(dTI/do)^-alpha_TI; 7 | NLoS_Tx_IRS = sqrt(1/2)*(randn(M,Nt)+1j*randn(M,Nt)); 8 | T = sqrt(beta_TI)*NLoS_Tx_IRS; 9 | end 10 | 11 | 12 | -------------------------------------------------------------------------------- /dissertation/computeQ_R.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Initialization process: Optimizing Q given a set of reflection 3 | %%%% coefficients with random phase and selecting Q and reflection coeff. 4 | %%%% giving the maximum achievable capacity as starting point 5 | 6 | function [optR,optQ,totalQ,totalC,totalR,Q,H_tilde,reflection_coefficients,optCapacity,Capacity_IRS] = computeQ_R(Nr,Nt,M,R,T,H,P_max_linear,accuracy,sigma_lineal,a,b) 7 | 8 | L = 100; 9 | totalQ = []; 10 | totalC = []; 11 | totalR = []; 12 | 13 | 14 | for i = 1:L 15 | 16 | reflection_coefficients = 1*exp(1j*transpose((b-a).*rand(M,1)+a)*(2*pi)/360); %% Reflection coefficients vector 17 | 18 | 19 | A = zeros(Nr,Nt); 20 | 21 | for l = 1:M 22 | A1 = reflection_coefficients(l)*R(:,l)*T(l,:); 23 | A = A + A1; 24 | end 25 | 26 | 27 | %%% Generation of the channel with IRS 28 | 29 | H_tilde = H + A; 30 | D2 = rank(H_tilde); 31 | 32 | %%% Singular value decomposition and acquisition of singular values 33 | 34 | [U,D,V] = svd(H_tilde); 35 | lam = diag(D).^2; %Singular Values 36 | 37 | 38 | %%% Water-filling power allocation 39 | 40 | wline = wfill(1./lam, P_max_linear,accuracy); 41 | Pi = max(wline-1./lam,0); % Tx power allocated to each Tx antenna 42 | power = zeros(1,size(V,2)); 43 | power(1:length(lam)) = Pi; % optimal Tx power per Tx antenna + added zero to fit dimension of V; 44 | 45 | %%% Generation of the transmit covariance matrix 46 | 47 | Q = V*diag(power)*V'; % Tx covariance matrix 48 | 49 | %%% Channel capacity with IRS 50 | 51 | Capacity_IRS = log2(det(eye(Nr)+1/sigma_lineal*H_tilde*Q*H_tilde')); 52 | 53 | totalQ = [totalQ;Q]; 54 | totalC = [totalC Capacity_IRS]; 55 | totalR = [totalR; reflection_coefficients]; 56 | 57 | end 58 | 59 | [optCvalue, optCindex] = max(totalC); 60 | 61 | %%% Selecting the optimal Q and reflection coefficients giving the largest 62 | %%% rate 63 | 64 | optQ = [totalQ(optCindex*4-3,:);totalQ(optCindex*4-2,:);totalQ(optCindex*4-1,:);totalQ(optCindex*4,:)]; 65 | optR = totalR(optCindex,:); 66 | optCapacity = optCvalue; 67 | 68 | end 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /dissertation/compute_Am_Bm.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Resolution of Subproblem 2 - Optimization of a single reflection 3 | %%%% coefficient with all the other variables being fixed 4 | 5 | function [Am,Bm,Final_matrix,Am1,Bm1,NZ_eigenvalues,optimal_solution_1,optimal_capacity_1] = compute_Am_Bm(M,R,T,H,optR,optQ,Nr,Nt,sigma_lineal) 6 | 7 | [U1,D1,V1] = eig(optQ); 8 | 9 | H_prima = H*U1*D1^1/2; 10 | 11 | B = zeros(Nr,Nt); 12 | C = zeros(Nr,Nt); 13 | 14 | 15 | 16 | Am1 = []; 17 | Bm1 = []; 18 | Final_matrix = []; 19 | S111 = []; 20 | U111 = []; 21 | Vm1 = []; 22 | Vm_inv_1 = []; 23 | vm_vec = []; 24 | vmT_fin = []; 25 | optimal_solution_1 = []; 26 | optimal_capacity_1 = []; 27 | 28 | 29 | 30 | for l = 1:M 31 | 32 | for k = 1:M 33 | if k ~= l 34 | B1 = optR(k)*R(:,k)*((D1^1/2*V1*T(k,:)')'); 35 | B = B + B1; 36 | Am = eye(Nr) + 1/sigma_lineal*(H_prima + B)*(H_prima + B)' + 1/sigma_lineal * R(:,l) * ((D1^1/2*V1*T(k,:)')') * (D1^1/2*V1*T(k,:)') * R(:,l)'; 37 | 38 | C1 = (D1^1/2*V1*T(k,:)')*R(:,k)'*conj(optR(k)); 39 | C = C + C1; 40 | Bm = 1/sigma_lineal * R(:,l) * ((D1^1/2*V1*T(l,:)')') * (H_prima' + C); 41 | end 42 | end 43 | 44 | Am1 = [Am1 Am]; 45 | Bm1 = [Bm1 Bm]; 46 | 47 | Final_matrix_1 = (Am1(:, 1+(l-1)*Nr:Nr*l))\Bm1(:, 1+(l-1)*Nr:Nr*l); 48 | Final_matrix = [Final_matrix Final_matrix_1]; 49 | 50 | [U11,S11,V11] = eig(Final_matrix(:, 1+(l-1)*Nr:Nr*l)); 51 | S111 = [S111 S11(1)]; 52 | U111 = [U111 U11]; 53 | NZ_eigenvalues = S111; 54 | Vm = U111(:, 1+(l-1)*Nr:Nr*l)'*Am1(:, 1+(l-1)*Nr:Nr*l)*U111(:, 1+(l-1)*Nr:Nr*l); 55 | Vm1 = [Vm1 Vm]; 56 | 57 | Vm_inv = inv(Vm1(:, 1+(l-1)*Nr:Nr*l)); 58 | Vm_inv_1 = [Vm_inv_1 Vm_inv]; 59 | vm = Vm_inv_1(:,1+(l-1)*Nr); 60 | vm_vec = [vm_vec vm]; 61 | vm1 = vm_vec(1,:); %%% first elements of vm_vec 62 | vmT = Vm1(1,:); 63 | vmT1 = vmT(1+(l-1)*Nr); 64 | vmT_fin = [vmT_fin vmT1]; %%% first element of vmT1 65 | 66 | 67 | if trace(Final_matrix(:, 1+(l-1)*Nr:Nr*l)) ~= 0 68 | 69 | optimal_solution = exp(-1i*angle(NZ_eigenvalues(l))); 70 | optimal_capacity = log2(1+abs(NZ_eigenvalues(l))^2*(1-vmT_fin(l)*vm1(l))+2*abs(NZ_eigenvalues(l)))+log2(det(Am1(:, 1+(l-1)*Nr:Nr*l))); 71 | 72 | else 73 | optimal_solution = 1; 74 | optimal_capacity = log2(det(Am1(:, 1+(l-1)*Nr:Nr*l)-Bm1(:, 1+(l-1)*Nr:Nr*l)'*inv(Am1(:, 1+(l-1)*Nr:Nr*l))*Bm1(:, 1+(l-1)*Nr:Nr*l))); 75 | end 76 | 77 | optimal_solution_1 = [optimal_solution_1 optimal_solution]; 78 | optimal_capacity_1 = [optimal_capacity_1 optimal_capacity]; 79 | 80 | end 81 | 82 | end -------------------------------------------------------------------------------- /dissertation/compute_C_noIRS.m: -------------------------------------------------------------------------------- 1 | function [Capacity_no_IRS] = compute_C_noIRS(Nr,H,P_max_linear,accuracy,sigma_lineal) 2 | 3 | 4 | %%% Singular value decomposition and acquisition of singular values 5 | 6 | [U4,D4,V4] = svd(H); 7 | lam4 = diag(D4).^2; % Singular Values 8 | 9 | 10 | %%% Water-filling power allocation 11 | 12 | wline = wfill(1./lam4, P_max_linear,accuracy); 13 | Pi = max(wline-1./lam4,0); % Tx power allocated to each Tx antenna 14 | power = zeros(1,size(V4,2)); 15 | power(1:length(lam4)) = Pi; % optimal Tx power per Tx antenna + added zero to fit dimension of V; 16 | 17 | %%% Generation of the transmit covariance matrix 18 | 19 | Q = V4*diag(power)*V4'; % Tx covariance matrix 20 | 21 | %%% Channel capacity with IRS 22 | 23 | Capacity_no_IRS = log2(det(eye(Nr)+1/sigma_lineal*H*Q*H')); 24 | 25 | end 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /dissertation/compute_final_Q.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Resolution of Subproblem 1: Optimization of Q with given 3 | %%%% reflection coefficients 4 | 5 | function [Q1,reflection_coefficients_1,H_tilde_1] = compute_final_Q(Nr,Nt,M,R,T,H,P_max_linear,accuracy,optimal_solution_1,sigma_lineal) 6 | 7 | reflection_coefficients_1 = optimal_solution_1; 8 | 9 | E = zeros(Nr,Nt); 10 | 11 | for n = 1:M 12 | E1 = reflection_coefficients_1(n)*R(:,n)*T(n,:); 13 | E = E + E1; 14 | end 15 | 16 | 17 | %%% Generation of the channel with IRS 18 | 19 | H_tilde_1 = H + E; 20 | 21 | %%% Singular value decomposition and acquisition of singular values 22 | 23 | [U3,D3,V3] = svd(H_tilde_1); 24 | lam1 = diag(D3).^2; %Singular Values 25 | 26 | %%% Water-filling power allocation 27 | 28 | wline = wfill(1./lam1, P_max_linear,accuracy); 29 | Pi1 = max(wline-1./lam1,0); % Tx power allocated to each Tx antenna 30 | power1 = zeros(1,size(V3,2)); 31 | power1(1:length(lam1)) = Pi1; % optimal Tx power per Tx antenna + added zero to fit dimension of V; 32 | 33 | %%% Generation of the transmit covariance matrix 34 | 35 | Q1 = V3*diag(power1)*V3'; % Tx covariance matrix 36 | 37 | end -------------------------------------------------------------------------------- /dissertation/direct_channel.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Genaration of the direct channel H between the transmitter and the 3 | %%%% receiver 4 | 5 | function [H] = direct_channel(H_hat,dD_hat,Nr,Nt,lambda,theta_AoA,theta_AoD,Kd,do,beta_o_lineal,dA,alpha_d) 6 | 7 | ar1 = []; 8 | at1 = []; 9 | 10 | for i = 1:Nr 11 | ar = exp(i*2*pi*(i-1)*dA*(sin(theta_AoA))/lambda); 12 | ar1 = [ar1 ar]; 13 | end 14 | 15 | for i = 1:Nt 16 | at = exp(i*2*pi*(i-1)*dA*(sin(theta_AoD))/lambda); 17 | at1 = [at1 at]; 18 | end 19 | 20 | ar1 = ar1'; 21 | at1 = at1'; 22 | 23 | H_LoS = ar1*at1'; 24 | 25 | H_NLoS_direct = sqrt(1/2)*(randn(Nr,Nt)+1j*randn(Nr,Nt)); %% Rayleigh channel matrix of the direct link between Tx-Rx (variance of 1) 26 | 27 | dD = sqrt(dD_hat^2+H_hat^2); 28 | beta_d = beta_o_lineal*(dD/do)^-alpha_d; 29 | 30 | H = sqrt(beta_d/(Kd+1))*(sqrt(Kd)*H_LoS+H_NLoS_direct); 31 | 32 | end 33 | -------------------------------------------------------------------------------- /dissertation/main.m: -------------------------------------------------------------------------------- 1 | 2 | %%%% Sum-rate optimization for IRS-aided MIMO %%%% 3 | 4 | clc; 5 | clear; 6 | 7 | %%% Definition of all the variables 8 | 9 | M = 40; 10 | f = 10e6; 11 | c = 3e8; 12 | lambda = c/f; 13 | theta_AoA = 0; 14 | theta_AoD = 0; 15 | Nt = 4; %% Number of Tx-IRS streams 16 | Nr = 4; %% Number of IRS-Rx streams 17 | a = 0; %% Lower-bound reflection coefficient phase in degrees 18 | b = 360; %% Upper-bound reflection coefficient phase in degrees 19 | H_hat = 10; 20 | dp_hat = 2; 21 | dh_hat = 2; 22 | do = 1; 23 | alpha_IR = 2.8; 24 | alpha_TI = 2.2; 25 | alpha_d = 3.5; 26 | dD_hat = 600; 27 | Kd = 0; 28 | beta_o = -30; 29 | beta_o_lineal = 10^(-30/10); 30 | dA = lambda/2; 31 | P_max_dBm = 30; % in dBm 32 | P_max_dB = P_max_dBm-30; % in dB 33 | P_max_linear = 10^(P_max_dB/10); 34 | accuracy = 1E-3; % accuracy of water-filing algorithm 35 | sigma_dBm = -90; 36 | sigma_dB = sigma_dBm-30; 37 | sigma_lineal = 10^(sigma_dB/10); 38 | 39 | %%% Definition of all the channels and inizialization 40 | 41 | 42 | [R] = IRS_Receiver_channel(H_hat,Nr,dp_hat,dh_hat,do,alpha_IR,M,beta_o_lineal); 43 | [T] = Transmitter_IRS_channel(Nt,M,dp_hat,dh_hat,dD_hat,do,alpha_TI,beta_o_lineal); 44 | [H] = direct_channel(H_hat,dD_hat,Nr,Nt,lambda,theta_AoA,theta_AoD,Kd,do,beta_o_lineal,dA,alpha_d); 45 | 46 | 47 | [optR,optQ,totalQ,totalC,totalR,Q,H_tilde,reflection_coefficients,optCapacity,Capacity_IRS] = computeQ_R(Nr,Nt,M,R,T,H,P_max_linear,accuracy,sigma_lineal,a,b); 48 | 49 | Capacity_IRS_random_phase = log2(det(eye(Nr)+1/sigma_lineal*H_tilde*Q*H_tilde')); %%% Capacity for a given set of reflection coefficients with random phase 50 | 51 | [Capacity_no_IRS] = compute_C_noIRS(Nr,H,P_max_linear,accuracy,sigma_lineal); %%% This function gives the channel capacity of the system without IRS 52 | 53 | %%% Up to this point: Optimal transmit covariance matrix and reflection 54 | %%% coefficients initialized (OptR and OptQ) 55 | 56 | 57 | cond = true; 58 | NumIterations = 1; 59 | CapacityVec = []; 60 | IterationsVec = []; 61 | 62 | capacity_prev = 0; 63 | 64 | optimal_capacity_11 = []; 65 | 66 | while(cond) %%% This process will be executed until two adjacent capacity values are the same 67 | 68 | %%% Computing Am and Bm - Subproblem 2 69 | 70 | [Am,Bm,Final_matrix,Am1,Bm1,NZ_eigenvalues,optimal_solution_1,optimal_capacity_1] = compute_Am_Bm(M,R,T,H,optR,optQ,Nr,Nt,sigma_lineal); 71 | 72 | %%% Computing optimized Q - Subproblem 1 73 | 74 | [Q1,reflection_coefficients_1,H_tilde_1] = compute_final_Q(Nr,Nt,M,R,T,H,P_max_linear,accuracy,optimal_solution_1,sigma_lineal); 75 | 76 | Capacity_IRS_1 = log2(det(eye(Nr)+1/sigma_lineal*H_tilde_1*Q1*H_tilde_1')); 77 | 78 | 79 | optQ = Q1; 80 | optR = reflection_coefficients_1; 81 | 82 | 83 | if abs(Capacity_IRS_1 - capacity_prev) < 10e-4 %%% Iteratively comparing two adjacent capacity values 84 | cond = false; 85 | end 86 | 87 | capacity_prev = Capacity_IRS_1; 88 | 89 | 90 | NumIterations = NumIterations + 1; 91 | 92 | 93 | end 94 | 95 | %%% disp(NumIterations); 96 | %%% disp(Capacity_IRS_1); 97 | %%% disp(Capacity_IRS); 98 | %%% disp(abs(Capacity_IRS_1 - capacity_prev)); 99 | %%% disp(Capacity_no_IRS); 100 | %%% disp(Capacity_IRS_random_phase); 101 | 102 | 103 | -------------------------------------------------------------------------------- /dissertation/wfill.m: -------------------------------------------------------------------------------- 1 | function wline=wfill(vec, pcon, tol) 2 | % WFILL: The Water Filling algorithm. 3 | % WLINE = WFILL(VEC, PCON, TOL) performs the water filling algorithm 4 | % with the given total power constrain to approach Shannon capacity 5 | % of the channel. 6 | % The water filling algorithm is based on an interative procedure, so the tolerance 7 | % must be assigned to determine the end-of-loop. 8 | % 9 | % VEC is a noise absolute or relative level in LINEAR units at different frequencies, 10 | % space or whatever bins. PCON is a total power constrain given in the same units as the VEC. 11 | % TOL is an acceptable tolerance in the units of VEC. 12 | % WLINE indicates the WATERLINE level in units of VEC so that: 13 | % 14 | % abs(PCON-SUM(MAX(WLINE-VEC, 0)))<=TOL 15 | % 16 | % The algorithm is built such a way that PCON>=SUM(MAX(WLINE-VEC, 0)) and never 17 | % PCONtol 47 | wline=wline+(pcon-ptot)/N; 48 | ptot=sum(max(wline-vec,0)); 49 | end 50 | 51 | --------------------------------------------------------------------------------