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

📄 main.asv

📁 Woven码在TD-SCDMA中的应用仿真程序
💻 ASV
字号:
% This script simulates the classical turbo encoding-decoding system. 
% It simulates parallel concatenated convolutional codes.
% Two component rate 1/2 RSC (Recursive Systematic Convolutional) component encoders are assumed.
% First encoder is terminated with tails bits. (Info + tail) bits are scrambled and passed to 
% the second encoder, while second encoder is left open without tail bits of itself.
%
% Random information bits are modulated into +1/-1, and transmitted through a AWGN channel.
% Interleavers are randomly generated for each frame.
%
% Log-MAP algorithm without quantization or approximation is used.
% By making use of ln(e^x+e^y) = max(x,y) + ln(1+e^(-abs(x-y))),
% the Log-MAP can be simplified with a look-up table for the correction function.
% If use approximation ln(e^x+e^y) = max(x,y), it becomes MAX-Log-MAP.
%
% Copyright Nov 1998, Yufei Wu
% MPRG lab, Virginia Tech.
% for academic use only

clear all

% Write display messages to a text file
diary conv_link.txt

set_sim_consts
global sim_consts;

    rate = 1/3;   
    a = sim_consts.a;    
    niter = sim_consts.niter;
    ferrlim = sim_consts.ferrlim;
    EbN0db = sim_consts.EbN0;
    L_total = sim_consts.L_total;


fprintf('\n\n----------------------------------------------------\n'); 
    
fprintf('+ + + + Please be patient. Wait a while to get the result. + + + +\n');

for nEN = 1:length(EbN0db)
   snr = EbN0db(nEN);
   en = 10^(EbN0db(nEN)/10);      % convert Eb/N0 from unit db to normal numbers
   L_c = 4*a*en*rate; 	% reliability value of the channel
   sigma = 1/sqrt(2*rate*en); 	% standard deviation of AWGN noise

% Clear bit error counter and frame error counter
   errs(nEN,1:niter) = zeros(1,niter);
   nferr(nEN,1:niter) = zeros(1,niter);

   nframe = 0;    % clear counter of transmitted frames
   while ( nferr(nEN, niter)<sim_consts.ferrlim && nframe < sim_consts.nframeAll )
      
      % block count
      nframe = nframe + 1;    
      
      % info source
      x = round(rand(1, L_total-sim_consts.m));    % info. bits
      xx = [x zeros(1,8)];
      
      % conv code      
      en_output = 2*convenc(xx,sim_consts.t)-1;  % encoder output (+1/-1)
      
      % rate match
      L_b = 88*sim_consts.cNumber*sim_consts.tsNumber*sim_consts.subFrames;
      en_output(size(en_output,2)+1:L_b) = en_output(size(en_output,2))*ones(1,L_b-size(en_output,2));
      clear L_b;      
      
      % modulater
      for kk=1:length(en_output)/2
          modulator_out(kk) = en_output((kk-1)*2+1) + j*en_output(kk*2) ;
      end  
      clear kk;
      
      % through the channel 
      % spread, frame, channel, estimate, JD, deframe and despread       
      s_all = modulator_out(:);
      L_f = 44*sim_consts.cNumber*sim_consts.tsNumber*sim_consts.subFrames;
      L_sf = 44*sim_consts.cNumber*sim_consts.tsNumber;
      r_all = zeros(L_f,1);      
      for fIdx = 1:sim_consts.subFrames
          s = zeros(L_sf, 1);
          s(:) = s_all((fIdx-1)*L_sf+1:fIdx*L_sf);
          r_middle= send(s,snr);       % child function, type 'help send' to see the detail 
          r_all((fIdx-1)*L_sf+1:fIdx*L_sf) = r_middle(:);
          clear s r_middle;
      end
      clear L_sf;
      
      % demodulation
      for i=1:L_f
          r_s((i-1)*2+1) = real(r_all(i)) ;
          r_s(i*2) = imag(r_all(i)) ;
      end
      clear L_f;
      
      % conv decode
      ry = zeros(1,sim_consts.L_total/rate);
      ry(:) = r_s(1:sim_consts.L_total/rate);
      yk = demultiplex(ry,alpha,puncture); % demultiplex to get input for decoder 1 and 2
      
% Scale the received bits      
      rec_s = yk;
      L_all = vitdec(rec_s,sim_consts.t,sim_consts.tblen,'trunc','hard') ;
% Estimate the info. bits        
         xhat(alpha) = (sign(L_all)+1)/2;

% Number of bit errors in current iteration
         err(iter) = length(find(xhat(1:L_total-m)~=x));
% Count frame errors for the current iteration
         if err(iter)>0
            nferr(nEN,iter) = nferr(nEN,iter)+1;
         end   
      end	%iter
      
% Total number of bit errors for all iterations
      errs(nEN,1:niter) = errs(nEN,1:niter) + err(1:niter);

      if rem(nframe,3)==0 | nferr(nEN, niter)==ferrlim
% Bit error rate
         ber(nEN,1:niter) = errs(nEN,1:niter)/nframe/(L_total-m);
% Frame error rate
         fer(nEN,1:niter) = nferr(nEN,1:niter)/nframe;

% Display intermediate results in process  
         fprintf('************** Eb/N0 = %5.2f db **************\n', EbN0db(nEN));
         fprintf('Frame size = %d, rate 1/%d. \n', L_total, 2+puncture);
         fprintf('%d frames transmitted, %d frames in error.\n', nframe, nferr(nEN, niter));
         fprintf('Bit Error Rate (from iteration 1 to iteration %d):\n', niter);
         for i=1:niter
            fprintf('%8.4e    ', ber(nEN,i));
         end
         fprintf('\n');
         fprintf('Frame Error Rate (from iteration 1 to iteration %d):\n', niter);
         for i=1:niter
            fprintf('%8.4e    ', fer(nEN,i));
         end
         fprintf('\n');
         fprintf('***********************************************\n\n');

% Save intermediate results 
         save turbo_sova EbN0db ber fer
      end
      if  errs(nEN, sim_consts.niter) > sim_consts.errAll 
          break;
      end    
   end		%while
end 		%nEN

diary off

⌨️ 快捷键说明

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