⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.m

📁 mimo系统仿真 bpsk调制 瑞利信道 得Eb/No-BER曲线
💻 M
字号:
% A sample program of MIMO system
% Detection is performed only by multiply H* to the received signal
% May result in high BER error floor, i.e. poor BER performance


% information frame size
N = input(' Please enter the information bits length (= N, default: 1000) ');
if isempty(N)                % isempty: 确认是否为空矩阵
   N = 1000;	 
end

% Fading amplitude; a=1 in AWGN channel
a = 1; 

% Number of frames to count as a stop criterior
FrameLim = input(' Please enter number of frames to terminate: default 1000 ');
if isempty(FrameLim)
   FrameLim = 1000;
end   

% Number of transmit antenna
nT = input(' Please enter number of transmit antenna : 4 ');
if isempty(nT)
   nT = 4;
end

% Number of receive antenna
nR = input(' Please enter number of receive antenna : 4 ');
if isempty(nR)
   nR = 4;
end

% input of EbNo could be a vector
EbN0db = input(' Please enter Eb/N0 in dB : default [10.0]    ');
if isempty(EbN0db)
   EbN0db = [10.0];
end
      
% number of transmitted data bits (FRAME) 
FRAME = N;
      
fprintf(' \n\n----------------------------------------------------\n'); 
fprintf(' Number of Information bits = %6d\n',N);
fprintf(' Frame Length = %6d\n',FRAME);
fprintf(' transmit antenna number =  %6d\n', nT);
fprintf(' receive antenna number =  %6d\n', nR);
fprintf(' Eb / N0 (dB) = ');

for i = 1:length(EbN0db)   
    fprintf('%10.2f',EbN0db(i));
end
fprintf('\n----------------------------------------------------\n\n');
    
fprintf('+ + + Please be patient. Wait a while to get the result. + + +\n');

for nEN = 1:length(EbN0db)
   
   % convert Eb/No from DB to normal value (nv)
   en = 10^(EbN0db(nEN)/10);    % dB转为数值 dB = 10*lg(nv)
   sigma = sqrt(nT/en/2); 	% standard deviation of AWGN noise
                            % 0 < sigma < 1
   
  % Clear bit error counter and frame error counter
   
  cber0(nEN) = 0;
  cerrs0(nEN) = 0;
  
  % clear counter of transmitted frames
  nframe = 0;    
   
   while nframe < FrameLim
      nframe = nframe + 1;    
      
    % info. bits (per frame)
      data = randint(1, N);  % 产生一个1*N维数组,其中出现0的概率为1/2。 
              
    % Independent Rayleigh MIMO channel model
      H = (randn(nR, nT) + j*randn(nR, nT))/sqrt(2*nR);
      
    % Serial to Parallel convertion of data  串并变换
      for k=1:N/nT
          for m=1:nT
              sMatrix0(m,k)= data(1,m+(k-1)*nT);
          end
      end
      
    % BPSK modulation
      sMatrix0 = 2 .* sMatrix0 - 1;
    
    % received signal (without noise)
      rMatrix0 =  H * sMatrix0;
          
    % AWGN noise 
      nMatrix0 = sigma*(randn(nR,FRAME/nT)+j*randn(nR,FRAME/nT));
%       nMatrix0=0; % for debugg
      
    % Received signals
      rMatrix0 = rMatrix0 + nMatrix0;
                                    
    % Detection of received signal
      dMatrix0= H'* rMatrix0;
      
    % BPSK demodulation (discard the imaginary part)
      dec1(1:nT,1:N/nT)=real(dMatrix0(1:nT,1:N/nT));
 
    % Parellel to serial convertion of data
      for k=1:N/nT
          for m=1:nT
              dec2(1,m+(k-1)*nT)=dec1(m,k);
          end
      end
      
    % Hard decision
      dec = (sign(dec2)+1)/2;

    % Count bit errors
      cerr0 = length(find(dec(1:N) ~= data(1:N)));
  
    % Sum bit errors over all frames
      cerrs0(nEN) = cerrs0(nEN) + cerr0;
    
    % End of while
     end       
     
       cerrs0(nEN);
     % Bit error rate
       cber0(nEN) = cerrs0(nEN)/(N)/nframe;
 
       
    % Display intermediate results in process

      fprintf('************** Eb/N0 = %5.2f db **************\n', EbN0db(nEN));
      fprintf('Frame size = %d \n', FRAME);
      fprintf('%d frames transmitted.\n', nframe);
      fprintf('BER: %8.4e \n', cber0(nEN));
      fprintf('\n');
      fprintf('***********************************************\n\n');
         
    % end of nEN         
   
  end  

																																																																																																																																																																																																																																																																																														

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -