Please Can some one fix this code? I am unable to understand this code? Though fixing one problem another problem is arising !

2 views (last 30 days)
% Parameters
Np = 2; % Number of reflecting elements in IRS
K = 2; % Number of users
Mtot = 20:20:120; % 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 = 2; % IRS size values to simulate
SNR_dB = 20; % SNR in dB
SNR = 10^(SNR_dB/10); % SNR in linear scale
% Generate channel matrices
for i=1:length(Mtot)
H = (randn(Mtot(i),K)+1j*randn(Mtot(i),K))/sqrt(2);
G = (randn(Np,Mtot(i))+1j*randn(Np,Mtot(i)))/sqrt(2);
F = (randn(Mtot(i),K)+1j*randn(Mtot(i),K))/sqrt(2);
% Simulate achievable sum rate vs IRS size
sum_rate_fc = zeros(1,Mtot(i));
sum_rate_fd = zeros(1,Mtot(i));
sum_rate_zf = zeros(1,Mtot(i));
G = (randn(Np,Mtot(i))+1j*randn(Np,Mtot(i)))/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 = sum(log2(1+SNR*abs(H_eff_fc*F).^2));
sum_rate_fd = sum(log2(1+SNR*abs(H_eff_fd*F).^2));
sum_rate_zf = sum(log2(1+SNR*abs(H_eff_zf*F).^2));
end
Arrays have incompatible sizes for this operation.
% 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)');
expected output plots
  1 Comment
per isakson
per isakson on 20 Apr 2023
You cannot multiply a 1x2 vector by a 20x20 array
K>> H_eff_fd = H_irs.*exp(-1j*2*pi*fd*(0:K-1).'/fd);
Matrix dimensions must agree.
K>> z = exp(-1j*2*pi*fd*(0:K-1).'/fd)
z =
1 + 0i
1 + 2.4493e-16i
K>> whos z H_irs
Name Size Bytes Class Attributes
H_irs 20x20 6400 double complex
z 2x1 32 double complex
K>>

Sign in to comment.

Answers (0)

Categories

Find more on RF Toolbox 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!