用于WBAN的Matlab中BER计算的路径损耗因子

任何人都可以指导我如何在Matlab中的无线体域网络的BER计算中包含路径损耗值?我正在使用qpsk调制和瑞利信道 .

如果我简单地将信道与路径损耗值相乘,如下:

y=x*(h*PL)+n

结果是大多数值变为零 .

代码(参见rx,rx1和rx2的计算):

format long; bit_count = 1000000;

Eb_No = 0: 1: 30;

SNR = Eb_No + 10*log10(2);

for aa = 1: 1: length(SNR)

   T_Errors = 0;

   T_bits = 0;

   T_Errors1=0;

   T_Errors2=0;  

   while T_Errors < 10 && T_Errors1 < 10 && T_Errors2 < 10

      uncoded_bits  = round(rand(1,bit_count));

      B1 = uncoded_bits(1:2:end);

      B2 = uncoded_bits(2:2:end);

      qpsk_sig = ((B1==0).*(B2==0)*(exp(i*pi/4))+(B1==0).*(B2==1)...
      *(exp(3*i*pi/4))+(B1==1).*(B2==1)*(exp(5*i*pi/4))...
      +(B1==1).*(B2==0)*(exp(7*i*pi/4)));        

      h = sqrt(0.5*((randn(3,length(qpsk_sig))).^2+(randn(3,length(qpsk_sig))).^2));

      d1=50;

      PL1=43.22;

      PL2=67.77;

      PL3=69.8; 

      n=0.6^(SNR(aa)/0.6); 

      n1=0.7^(SNR(aa)/0.7); 

      n2=1/10^(SNR(aa)/10);  

      rx = (qpsk_sig.*h(1,:)*PL1)+ sqrt(n/2)*(randn(1,length(qpsk_sig))+i*randn(1,length(qpsk_sig)));  % Source to  Relay

      rx_re = real(rx);
      rx_im = imag(rx);      
      rxHat(find(rx_re < 0 & rx_im < 0)) = -1 + -1*j;

      rxHat(find(rx_re >= 0 & rx_im > 0)) = 1 + 1*j;

      rxHat(find(rx_re < 0 & rx_im >= 0)) = -1 + 1*j;

      rxHat(find(rx_re >= 0 & rx_im < 0)) = 1 - 1*j;
      rx1 = (rxHat.*h(2,:)*PL2) + sqrt(n1/2)*(randn(1,length(qpsk_sig))+i*randn(1,length(qpsk_sig)));  %Relay to Destination

      rx2=(qpsk_sig.*h(3,:)*PL3) + sqrt(n2/2)*randn(1,length(qpsk_sig))+i*randn(1,length(qpsk_sig)));  % Source to Destination

      %---------------------------------------------------------------

      rx = rx./h(1,:);

      rx1 = rx1./h(2,:);

      rx2 = rx2./h(3,:);

      B4 = (real(rx)<0);

      B3 = (imag(rx)<0);

      uncoded_bits_rx = zeros(1,2*length(rx));

      uncoded_bits_rx(1:2:end) = B3;

      uncoded_bits_rx(2:2:end) = B4;

      % Calculate Bit Errors

      diff = uncoded_bits - uncoded_bits_rx;

      T_Errors = T_Errors + sum(abs(diff));

      T_bits = T_bits + length(uncoded_bits);


      B8 = (real(rx1)<0);

      B7 = (imag(rx1)<0);

      uncoded_bits_rx1 = zeros(1,2*length(rx1));

      uncoded_bits_rx1(1:2:end) = B7;

      uncoded_bits_rx1(2:2:end) = B8;


      % Calculate Bit Errors
      diff1 = uncoded_bits - uncoded_bits_rx1;
      T_Errors1 = T_Errors1 + sum(abs(diff1));
      T_bits = T_bits + length(uncoded_bits);

      B6 = (real(rx2)<0);
      B5 = (imag(rx2)<0);

      uncoded_bits_rx2 = zeros(1,2*length(rx2));
      uncoded_bits_rx2(1:2:end) = B5;
      uncoded_bits_rx2(2:2:end) = B6;


      % Calculate Bit Errors
      diff2 = uncoded_bits - uncoded_bits_rx2;
      T_Errors2 = T_Errors2 + sum(abs(diff2));
      T_bits = T_bits + length(uncoded_bits);

   end

   % Calculate Bit Error Rate
   BER(aa) = T_Errors / T_bits;
   BER1(aa) = T_Errors1 / T_bits; 
   BER2(aa) = T_Errors2 / T_bits;
end

%------------------------------------------------------------ figure(1); semilogy(SNR,BER1,'bs-','LineWidth',2');

hold on;

xlabel('SNR');

ylabel('BER');

grid on;

figure(1);

semilogy(SNR,BER2,'*r');

hold on;

xlabel('SNR');

ylabel('BER');

grid on;

legend('Relay','Direct');

axis([0 30 10^-10 0.1])

请帮忙 . 谢谢

回答(1)

2 years ago

我认为零是可以接受的,因为源 - >中继 - >目标路径有时会有0位错误,而直接路径有> 0.当以对数刻度绘制时,这会导致数据点出现在-Inf(离开情节) .

enter image description here

Edit :我稍微修改了你的代码以绘制更高的SNR(参见更新的图表) . 另外,我认为pathloss的原始用法是不正确的 . 我假设给定的路径损耗常数以dB为单位 . 在将它们(相乘)应用于发送信号之前,需要将它们转换为线性标度 . 此外,路径损耗值应为负dB . 原始代码实质上是给信号增益而不是损失 . 这是修改后的代码:

format long; 

bit_count = 1000000;

Eb_No = 20: 1: 100;

SNR = Eb_No + 10*log10(2);  % not sure about the 10*log10 part, ??
BER = zeros(size(SNR));
BER1 = zeros(size(SNR));
BER2 = zeros(size(SNR));
for aa = 1: 1: length(SNR)

   T_Errors = 0;

   T_bits = 0;

   T_Errors1=0;

   T_Errors2=0;  

   while T_Errors < 10 && T_Errors1 < 10 && T_Errors2 < 10

      uncoded_bits  = round(rand(1,bit_count));

      B1 = uncoded_bits(1:2:end);

      B2 = uncoded_bits(2:2:end);

      qpsk_sig = ((B1==0).*(B2==0)*(exp(1i*pi/4))+(B1==0).*(B2==1)...
      *(exp(3*1i*pi/4))+(B1==1).*(B2==1)*(exp(5*1i*pi/4))...
      +(B1==1).*(B2==0)*(exp(7*1i*pi/4)));        

      h = sqrt(0.5*((randn(3,length(qpsk_sig))).^2+(randn(3,length(qpsk_sig))).^2));

      d1=50;

      % Path losses in dB
      PL1=-23.22;

      PL2=-27.77;

      PL3=-49.8; 

      n=0.6^(SNR(aa)/0.6); 

      n1=0.7^(SNR(aa)/0.7); 

      n2=1/10^(SNR(aa)/10);  

      % Since we are multiplying pathloss by the input, pathloss needs to
      % be linear (not dB).  If we keep P.L. in dB, then we would subtract
      % P.L. from the signal (which would also need to be in dB).
      rx = (qpsk_sig.*h(1,:)*(10^(PL1/10)))+ sqrt(n/2)*(randn(1,length(qpsk_sig))+1i*randn(1,length(qpsk_sig)));  % Source to  Relay

      rx_re = real(rx);
      rx_im = imag(rx);  

      rxHat = zeros(size(rx));

      rxHat(find(rx_re < 0 & rx_im < 0)) = exp(5*1i*pi/4); %-1 + -1*j;

      rxHat(find(rx_re >= 0 & rx_im > 0)) = exp(1i*pi/4); % 1 + 1*j;

      rxHat(find(rx_re < 0 & rx_im >= 0)) = exp(3*1i*pi/4); % -1 + 1*j;

      rxHat(find(rx_re >= 0 & rx_im < 0)) = exp(7*1i*pi/4); % 1 - 1*j;

      % Same as above, convert pathloss from dB to linear
      rx1 = (rxHat.*h(2,:)*(10^(PL2/10))) + sqrt(n1/2)*(randn(1,length(qpsk_sig))+1i*randn(1,length(qpsk_sig)));  %Relay to Destination

      rx2=(qpsk_sig.*h(3,:)*(10^(PL3/10))) + sqrt(n2/2)*(randn(1,length(qpsk_sig))+1i*randn(1,length(qpsk_sig)));  % Source to Destination

      %---------------------------------------------------------------

      rx = rx./h(1,:);

      rx1 = rx1./h(2,:);

      rx2 = rx2./h(3,:);

      B4 = (real(rx)<0);

      B3 = (imag(rx)<0);

      uncoded_bits_rx = zeros(1,2*length(rx));

      uncoded_bits_rx(1:2:end) = B3;

      uncoded_bits_rx(2:2:end) = B4;

      % Calculate Bit Errors

      diff = uncoded_bits - uncoded_bits_rx;

      T_Errors = T_Errors + sum(abs(diff));

      T_bits = T_bits + length(uncoded_bits);


      B8 = (real(rx1)<0);

      B7 = (imag(rx1)<0);

      uncoded_bits_rx1 = zeros(1,2*length(rx1));

      uncoded_bits_rx1(1:2:end) = B7;

      uncoded_bits_rx1(2:2:end) = B8;


      % Calculate Bit Errors
      diff1 = uncoded_bits - uncoded_bits_rx1;
      T_Errors1 = T_Errors1 + sum(abs(diff1));
      T_bits = T_bits + length(uncoded_bits);

      B6 = (real(rx2)<0);
      B5 = (imag(rx2)<0);

      uncoded_bits_rx2 = zeros(1,2*length(rx2));
      uncoded_bits_rx2(1:2:end) = B5;
      uncoded_bits_rx2(2:2:end) = B6;


      % Calculate Bit Errors
      diff2 = uncoded_bits - uncoded_bits_rx2;
      T_Errors2 = T_Errors2 + sum(abs(diff2));
      T_bits = T_bits + length(uncoded_bits);

   end

   % Calculate Bit Error Rate
   BER(aa) = T_Errors / T_bits;
   BER1(aa) = T_Errors1 / T_bits; 
   BER2(aa) = T_Errors2 / T_bits;
end

%------------------------------------------------------------ 

figure(1); 

subplot(2,1,1);

semilogy(SNR,BER1,'bs-','LineWidth',2');

hold on;

xlabel('SNR');

ylabel('BER');

grid on;

figure(1);

semilogy(SNR,BER2,'*r');

hold on;

xlabel('SNR');

ylabel('BER');

grid on;

legend('Relay','Direct');

title('Bit Errors (log)')

xlim([min(SNR) max(SNR)])

subplot(2,1,2)

plot(SNR,BER1,'bs-');

hold on

plot(SNR,BER2,'*r')

hold off

title('Bit Errors (linear)')

xlabel('SNR')

ylabel('BER')

xlim([min(SNR) max(SNR)])