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 view (last 30 days)
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

Accepted Answer

DGM
DGM on 17 May 2021
Edited: DGM on 17 May 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

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 17 May 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);

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!