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 CenterFile Exchange에서 Wireless Communications에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by