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

时间:2014-09-26 11:21:09

标签: matlab path

有人可以指导我如何在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 个答案:

答案 0 :(得分:1)

认为零是可接受的,因为源 - &gt;中继 - &gt;目标路径有时会出现0位错误,而直接路径有> 0。 0.以对数刻度绘图时,这会导致数据点显示在-Inf(关闭绘图)。

enter image description here

编辑:我稍微修改了您的代码以绘制更高的SNR(请参阅更新的图表)。另外,我认为路径损失的原始用法是不正确的。我假设给定的路径损耗常数以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)])