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 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

DGM
DGM am 17 Mai 2021
Bearbeitet: DGM am 17 Mai 2021
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

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 17 Mai 2021
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);

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by