The Average of the Matrix G with the dimension (M,n) that I'm repeating 3 times in a loop so I'll have 3 matrices of G (M,n) and I want to take the Average of these 3 matrices so I can get only one matrix of G(M,n) represent the Average of them)

1 回表示 (過去 30 日間)
clc; clear;
M=5; n=3; freq = 28e9; lambda = physconst('LightSpeed')/freq; d_BS=lambda/2; %Inter-antenna separation atthe BS. d_IRS=lambda/2; %Inter-element separation at the IRS.
G = zeros(M,n);
for l=1:3
theta_2=-pi+(2*pi*rand); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand))/2; %AoD [-pi/2,pi/2]
for mi=1:M
for ni=1:n
e = exp(1i*2*pi/lambda*((mi-1)*d_BS*sin(theta_1)*sin(phi_1)+(ni-1)*d_IRS*sin(theta_2)*sin(phi_2)));
Beta = 1; % path loss factor
G(mi,ni) = 1/sqrt(2).*sqrt(Beta).*e
end
end
end

採用された回答

DGM
DGM 2021 年 5 月 17 日
編集済み: DGM 2021 年 5 月 17 日
Something like this
M=5;
n=3;
freq = 28e9;
lambda = physconst('LightSpeed')/freq;
d_BS=lambda/2; %Inter-antenna separation atthe BS.
d_IRS=lambda/2; %Inter-element separation at the IRS.
G = zeros(M,n,3); % allocate big enough for all copies
for l=1:3
theta_2=-pi+(2*pi*rand); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand))/2; %AoD [-pi/2,pi/2]
for mi=1:M
for ni=1:n
e = exp(1i*2*pi/lambda*((mi-1)*d_BS*sin(theta_1)*sin(phi_1)+(ni-1)*d_IRS*sin(theta_2)*sin(phi_2)));
Beta = 1; % path loss factor
G(mi,ni,l) = 1/sqrt(2).*sqrt(Beta).*e; % write just this page
end
end
end
G = mean(G,3) % average along dim3

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 17 日
in your exercise, the loop is not a good one. You can use vectorization instead. E.g.:
theta_2=-pi+(2*pi*rand(3,1)); %AoA [-pi,pi]
phi_2=(-pi+(2*pi*rand(3,1)))/2; %AoA [-pi/2,pi/2]
theta_1=-pi+(2*pi*rand(3,1)); %AoD [-pi,pi]
phi_1=(-pi+(2*pi*rand(3,1)))/2; %AoD [-pi/2,pi/2]
M_theta2=mean(theta_2);
M_phi2=mean(phi_2);
M_theta1=mean(theta_1);
M_phi1=mean(phi_1);

カテゴリ

Help Center および File ExchangeWireless Communications についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by