how to plot in matlab a formula with multiple summation ?
    7 ビュー (過去 30 日間)
  
       古いコメントを表示
    
i have the following Spectral efficiency in line of sight  (SE_NLOS) formula :


i have K angles Q0 random value between (0;2Pi) we'll refer to them as Q in my code ,and K random angles Q1 random in value between (0;2PI) we'll refer to them as W in my code,
 in the first G(.,.) ,  G1( Q(k), Q(i) ) where i and k are the i_th and k_th Q angles
and the second G(.,.), G2( Q(k), W(i) ) where i is the i_th angle of W, and k is the k_th Q angles
due do the random nature of generating the random angles Q and W,  i calculate the mean of  G over many realizations for accuracy
beta_bar and SNR0 are given in dB we convert them to linear scale (and to avoid any errors in the case of  1/SNR0)
the plotted results should be similar to that present in the figure below

i only attempted to simulate SE_LOS for M=100 so it's the upper most black line that we need to pay attention to 
(i'am yet to attemp recreating the code for the NLOS case (blue line) but considering my evident incompetence when it comes to loops and summations it won't be long before i post a question about it)
my best attempt code is below:
% parameters
dH = 0.5;
M = 100;
K_UE = 1:20;
SNR0_dB = 0;
SNR0 = 10^(0/10);
beta_bar_dB = -10;
beta_bar = 10^(-10/10);
num_realizations = 1000;
% Compute SE_LOS for each value of K
% SE_LOS = zeros(length(K));
% SE_LOS=0;
SE_LOS = 0;
G1_sum = 0;
G2_sum = 0;
TOT_SUM = 0;
for kk = 1:numel(K_UE)
    K = K_UE(kk);
for k = 1:K    % for the innitial sum k to K
    G1 = zeros(1, num_realizations);
    G2 = zeros(1, num_realizations);
        for i = 1:K  % for the G sums i to K per each k
        for j = 1:num_realizations  % we calculate the mean of multiple realizations of G1 & G2 for more accuracy
            Q = 2*180*rand(1:K); %  Q  angles of each intra_cell UE 
            W = 2*180*rand(1:K); %  W  angles of each inter_cell UE 
            if  sind(Q(k)) ~= sind(W(i))
                G2(j) = (sind(180*dH*M*(sind(Q(k))-sind(W(i)))))^2/ ...
                       (M*(sind(180*dH*(sind(Q(k))-sind(W(i)))))^2);
            else
                G2(j) = M;
            end
            if i ~= k
                G1(j) = (sind(pi*dH*M*(sind(Q(k))-sind(Q(i)))))^2/ ...
                       (M*(sind(pi*dH*(sind(Q(k))-sind(Q(i)))))^2); 
            else 
                G1(j) = 0; 
            end
        end
        G2_sum = G2_sum + mean(G2);
        G1_sum = G1_sum + mean(G1); 
        end
    TOT_SUM = TOT_SUM + mean( log2(1 + M ./ (G1_sum + beta_bar * G2_sum + 1./SNR0)) );
    G2_sum = 0;
    G1_sum = 0; 
end   
SE_LOS(kk) = TOT_SUM
TOT_SUM=0;
end
% Plot SE_LOS as function of K_UE
plot(K_UE, SE_LOS);
xlabel('Number of UEs (K)');
ylabel('Sum SE (bits/s/Hz)');
when it comes to matlab summations and loops continue to be the bane of my existence when it comes to matlab 
 of coure all assistance is greatly appreciated!
3 件のコメント
  VBBV
      
      
 2023 年 5 月 20 日
				May be you can do something like this
% parameters
dH = 0.5;
M = 100;
K_UE = 1:20;
SNR0_dB = 0;
SNR0 = 10^(0/10);
beta_bar_dB = -10;
beta_bar = 10^(-10/10);
num_realizations = 100;
% Compute SE_LOS for each value of K
% SE_LOS = zeros(length(K));
% SE_LOS=0;
SE_LOS = 0;
G1_sum = 0;
G2_sum = 0;
TOT_SUM = 0;
for kk = 1:numel(K_UE)
    K = K_UE(kk);
    for k = 1:K    % for the innitial sum k to K
        G1 = zeros(1, num_realizations);
        G2 = zeros(1, num_realizations);     
         Q1 = 2*180*rand(K,1); % 
            for i = 1:K  % for the G sums i to K per each k
                 Q2 = 2*180*rand(K,1); %
                 Q = 2*180*rand(K,1);
                 W = 2*180*rand(K,1); %  W  angles of each inter_cell UE 
                for j = 1:num_realizations  % we calculate the mean of multiple realizations of G1 & G2 for more accuracy
                    if  sind(Q(k)) ~= sind(W(i))
                        G2(j) = (sind(180*dH*M*(sind(Q(k))-sind(W(i)))))^2/ ...
                               (M*(sind(180*dH*(sind(Q(k))-sind(W(i)))))^2);                       
                    else
                        G2(j) = M;                          
                    end
                    if i~=k
                         G1(j) = (sind(180*dH*M*(sind(Q1(k))-sind(Q2(i)))))^2/ ...
                               (M*(sind(180*dH*(sind(Q1(k))-sind(Q2(i)))))^2);
                    else
                            G1(j) = 0;
                    end
                end
                G2_sum = G2_sum + mean(G2);
                G1_sum = G1_sum + mean(G1);             
            end
        TOT_SUM = TOT_SUM + ( log2(1 + M ./ (G1_sum + beta_bar * G2_sum + (1./SNR0))) );
        G2_sum = 0;
        G1_sum = 0;         
    end   
    SE_LOS(kk) = TOT_SUM;
    TOT_SUM=0;
end
G1, G2
% Plot SE_LOS as function of K_UE
plot(K_UE, SE_LOS);
grid 
xlabel('Number of UEs (K)');
ylabel('Sum SE (bits/s/Hz)');
回答 (1 件)
  VBBV
      
      
 2023 年 5 月 20 日
        % parameters
dH = 0.5;
M = 100;
K_UE = 1:20;
SNR0_dB = 0;
SNR0 = 10^(0/10);
beta_bar_dB = -10;
beta_bar = 10^(-10/10);
num_realizations = 100;
% Compute SE_LOS for each value of K
% SE_LOS = zeros(length(K));
% SE_LOS=0;
SE_LOS = 0;
G1_sum = 0;
G2_sum = 0;
TOT_SUM = 0;
for kk = 1:numel(K_UE)
    K = K_UE(kk);
    for k = 1:K    % for the innitial sum k to K
        G1 = zeros(1, num_realizations);
        G2 = zeros(1, num_realizations);        
            for i = 1:K  % for the G sums i to K per each k
                for j = 1:num_realizations  % we calculate the mean of multiple realizations of G1 & G2 for more accuracy
                    Q = 2*180*rand(K,1); %  Q  angles of each intra_cell UE 
                    W = 2*180*rand(K,1); %  W  angles of each inter_cell UE                     
                    if  sind(Q(k)) ~= sind(W(i))
                        G2(j) = (sind(180*dH*M*(sind(Q(k))-sind(W(i)))))^2/ ...
                               (M*(sind(180*dH*(sind(Q(k))-sind(W(i)))))^2);
                    else
                        G2(j) = M;                        
                    end
                    % 
                    % if i ~= k
                    %     G1(j) = (sind(pi*dH*M*(sind(Q(k))-sind(Q(i)))))^2/ ...
                    %            (M*(sind(pi*dH*(sind(Q(k))-sind(Q(i)))))^2); 
                    % else 
                    %     G1(j) = 0; 
                    % end                
                end
                G2_sum = G2_sum + mean(G2);
                G1_sum = G1_sum + mean(G1);             
            end
        TOT_SUM = TOT_SUM + ( log2(1 + M ./ (G1_sum + beta_bar * G2_sum + (1./SNR0))) );
        G2_sum = 0;
        G1_sum = 0;         
    end   
    SE_LOS(kk) = TOT_SUM;
    TOT_SUM=0;
end
% Plot SE_LOS as function of K_UE
plot(K_UE, SE_LOS);
grid 
xlabel('Number of UEs (K)');
ylabel('Sum SE (bits/s/Hz)');
2 件のコメント
  VBBV
      
      
 2023 年 5 月 20 日
				% if i ~= k
%     G1(j) = (sind(pi*dH*M*(sind(Q(k))-sind(Q(i)))))^2/ ...
%            (M*(sind(pi*dH*(sind(Q(k))-sind(Q(i)))))^2); 
% else 
%     G1(j) = 0; 
% end      
The above code  may be superfluous , otherwise code looks ok except for these lines below 
Q = 2*180*rand(1:K); %  Q  angles of each intra_cell UE 
W = 2*180*rand(1:K); 
K  is a scalar, when you use it as 1:K  it becomes a vector which is interpreted incorrectly by rand  function. Change it to 
Q = 2*180*rand(K,1); %  Q  angles of each intra_cell UE 
W = 2*180*rand(K,1); 
参考
カテゴリ
				Help Center および File Exchange で Link-Level Simulation についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



