Can some one fix this code? I am unable to understand this code? Though fixing one problem another problem is arising ! please help!
1 view (last 30 days)
Show older comments
% Parameters
expected outputs
Np = 2; % Number of reflecting elements in IRS
K = 2; % Number of users
Mtot = 20; % Total number of antennas at the base station
Pmax = 10; % Maximum transmit power
fc = 28e9; % Carrier frequency
fd = 200; % Maximum Doppler shift
N = 100; % Number of IRS size values to simulate
Np_values = 1:N; % IRS size values to simulate
SNR_dB = 20; % SNR in dB
SNR = 10^(SNR_dB/10); % SNR in linear scale
% Generate channel matrices
H = (randn(Mtot,K)+1j*randn(Mtot,K))/sqrt(2);
G = (randn(Np,Mtot)+1j*randn(Np,Mtot))/sqrt(2);
F = (randn(Mtot,K)+1j*randn(Mtot,K))/sqrt(2);
% Simulate achievable sum rate vs IRS size
sum_rate_fc = zeros(1,N);
sum_rate_fd = zeros(1,N);
sum_rate_zf = zeros(1,N);
for i = 1:N
Np = Np_values(i);
G = (randn(Np,Mtot)+1j*randn(Np,Mtot))/sqrt(2);
H_irs = H.*G;
H_eff_fc = H_irs;
H_eff_fd = H_irs.*exp(-1j*2*pi*fd*(0:K-1).'/fd);
H_eff_zf = H_irs*(H_irs'*H_irs)^(-1)*H_irs';
sum_rate_fc(i) = sum(log2(1+SNR*abs(H_eff_fc*F).^2));
sum_rate_fd(i) = sum(log2(1+SNR*abs(H_eff_fd*F).^2));
sum_rate_zf(i) = sum(log2(1+SNR*abs(H_eff_zf*F).^2));
end
% Plot achievable sum rate vs IRS size
figure;
plot(Np_values,sum_rate_fc,'-o','LineWidth',2,'MarkerSize',8);
hold on;
plot(Np_values,sum_rate_fd,'-s','LineWidth',2,'MarkerSize',8);
plot(Np_values,sum_rate_zf,'-d','LineWidth',2,'MarkerSize',8);
xlabel('Number of reflecting elements in IRS (Np)');
ylabel('Achievable sum rate (bps/Hz)');
legend('Proposed fc','Proposed fd','ZF+ Random PBF');
% Simulate achievable sum rate vs Pmax
P_values = 0:0.1:Pmax;
sum_rate_proposed = zeros(1,length(P_values));
for i = 1:length(P_values)
P = P_values(i);
[W,~,~] = proposed_algorithm(P,H,G,F,Np,K);
sum_rate_proposed(i) = sum(log2(1+SNR*abs(H_eff_fc*W).^2));
end
% Plot achievable sum rate vs Pmax
figure;
plot(P_values,sum_rate_proposed,'-o','LineWidth',2,'MarkerSize',8);
xlabel('Maximum transmit power (Pmax)');
ylabel('Achievable sum rate (bps/Hz)');
% Plot convergence behavior of the proposed algorithm
figure;
[~,rate,~] = proposed_algorithm(Pmax,H,G,F,Np,K);
plot(rate,'-o','LineWidth',2,'MarkerSize',8);
xlabel('Iteration');
ylabel('Achievable sum rate (bps/Hz)');
0 Comments
Answers (1)
Alan Stevens
on 17 Apr 2023
In the following line:
G = (randn(Np,Mtot)+1j*randn(Np,Mtot))/sqrt(2); % When i=1, G is 1x20, but H is 20x2
so the following line has matrices of incompatible sizes.
5 Comments
See Also
Categories
Find more on Motor Drives in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!