# SNR and Channel capacity becomes constant after few meters. (Code bug)

9 views (last 30 days)
Arslan Ahmed Sohoo on 14 Feb 2023
Answered: Prathyusha Appalla on 15 Mar 2023
I am calculating the Channel capacity vs length. i have tried to replicate the paper(attached figure 1). The code that i have written is having some issues. The SNR decreases with distance but after some distance (i-e 30 meters), it becomes constant and does not change with distance. Same is the case with capacity. capacity does not decrease after some distances( result plot after simulation).
can you check the code. might be i have done some mistakes in dBm , dB and linear conversion.
Code:
Pt=20;
eta=8.75; % SNR gap in dB
eta_linear= 7.49; % SNR gap in linear
B=200e9; % bandwidth
sigma=-160; % AWGN noise
l=1:1:40 ;
a=0.2;% suppose attenuation constant is 0.2 dB/m
% Calculate the signal power after passing through the transfer function
H=exp(-a.* l);
H2=H.^2;
Pt_transferred = Pt .* H2 ;
% Calculate the signal-to-noise ratio (SNR) in dB
SNR = (Pt_transferred - sigma); %-------------------
SNR_linear=10.^(SNR/10) / 1000; %-----------------SNR from dBm to linear
% Calculate the channel capacity, C, in bps
C = B * log2(1 + SNR_linear/eta_linear);
% Display the result
plot(l,C,'-o')
legend('C');
xlabel('Distance ( in meters)');
ylabel('Data rate ( in Tbps)');

Prathyusha Appalla on 15 Mar 2023
Hi,
I understand that you want to plot Channel capacity versus length plot. The attenuation constant ‘a’ which you have considered in your code effects the trend of the plot. With higher value of ‘a’, the curve gets saturated to a constant value at a lesser length/distance. This relation can be observed from the equation in the image you’ve shared.
One possible workaround may be to consider a lesser value of attenuation constant which could give a smoother curve that decreases with length. I would suggest you to play around with different values of attenuation constant.
From the code shared by you:
SNR = (Pt_transferred - sigma);
where, “Pt_transferred” is in dBm and “sigma” is in dBm. When two values which are in dBm are subtracted the resultant value will be in dB but not in dBm. So, SNR conversion to linear can simply be done using:
SNR_linear=10.^(SNR/10);
For more information, a relevant MATLAB answer on the conversion criteria can be referred from the following link below. Hope this helps you to achieve your desired result!

### Categories

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