channel_decoding.m
上传用户:look542
上传日期:2009-06-04
资源大小:784k
文件大小:3k
源码类别:

传真(Fax)编程

开发平台:

Matlab

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % 根据不同用户的信道编码参数,进行信道解码
  3. function decoded_user_bit = channel_decoding ( demod_user_bit ,ChCodingMethod,Dec_alg,L_total,Generator,Puncture,...
  4.     N_iter,RateChCoding,Alpha,Turbo_frame,N_Turbo_frame, UserRS_Coding , UserTrellis,TraceBackLen, user_bit_cnt,...
  5.     turn_on )
  6. if turn_on
  7.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8.     % 使用Turbo码 + 交织 
  9.     if ChCodingMethod == 1
  10.         % 先假设单用户情况
  11.         
  12.         
  13.         soft_bits = demod_user_bit.';
  14.         
  15.         turbo_decoded = zeros(1,Turbo_frame*N_Turbo_frame);
  16.         
  17.         for n = 1:N_Turbo_frame
  18.             
  19.             soft_bits_frame = soft_bits(1,(n-1)*L_total/RateChCoding + 1:n*L_total/RateChCoding );
  20.             
  21.             yk = demultiplex(soft_bits_frame,Alpha,Puncture);
  22.             
  23.             % Scale the received bits      
  24.             % rec_s = 0.5*L_c*yk;
  25.             rec_s = yk;
  26.             
  27.             % Initialize extrinsic information      
  28.             L_e(1:L_total) = zeros(1,L_total);
  29.             
  30.             for iter = 1:N_iter
  31.                 % Decoder one
  32.                 L_a(Alpha) = L_e;  % a priori info. 
  33.                 if Dec_alg == 0
  34.                     
  35.                     L_all = logmapo(rec_s(1,:), Generator, L_a, 1);  % complete info.
  36.                 else   
  37.                     L_all = sova0(rec_s(1,:), Generator, L_a, 1);  % complete info.
  38.                 end   
  39.                 L_e = L_all - 2*rec_s(1,1:2:2*L_total) - L_a;  % extrinsic info.
  40.                 
  41.                 % Decoder two         
  42.                 L_a = L_e(Alpha);  % a priori info.
  43.                 if Dec_alg == 0
  44.                     L_all = logmapo(rec_s(2,:), Generator, L_a, 2);  % complete info.  
  45.                 else
  46.                     L_all = sova0(rec_s(2,:), Generator, L_a, 2);  % complete info. 
  47.                 end
  48.                 L_e = L_all - 2*rec_s(2,1:2:2*L_total) - L_a;  % extrinsic info.
  49.                 
  50.             end %iter
  51.             
  52.             % Estimate the info. bits        
  53.             xhat(Alpha) = (sign(L_all)+1)/2;    % 硬判决
  54.             turbo_decoded(1,(n-1)*Turbo_frame + 1:n*Turbo_frame ) = xhat(1:Turbo_frame);
  55.             
  56.         end
  57.         
  58.         decoded_user_bit =  turbo_decoded';
  59.         %err_bits = length(find(bits ~= turbo_decoded)) ; 
  60.         
  61.         
  62.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  63.         % 使用卷积 + RS + 交织    
  64.     elseif ChCodingMethod == 2
  65.         
  66.         user_convdecode = vitdec(demod_user_bit,UserTrellis,TraceBackLen ,'cont','hard');        
  67.         user_convdecode = user_convdecode(TraceBackLen + 1:end);
  68.         user_rsdecode = rsdeco(user_convdecode,UserRS_Coding(1),UserRS_Coding(2));
  69.         decoded_user_bit = user_rsdecode(1:user_bit_cnt);
  70.         
  71.     end
  72.     
  73. else
  74.     decoded_user_bit = demod_user_bit > 0;
  75.     
  76. end