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

📄 gflib.c

📁 Proakis《contemporarycommunication systems using matlab》matlab源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
   *   mu_l_mu = mu - l_mu;
   */
  /* allocate (t+2) for *mu */
  mu = Iwork;
  for(i=0; i < t+2; i++)
    mu[i] = i - 1;
  
  /* allocate (t+2)*(t+1) for *sigma_mu */    
  sigma_mu = mu + (t + 2);
  for(i=0; i < (t+2)*(t+1); i++){
    if( i > t+1 )
      sigma_mu[i] = -1;
  }
  
  /* allocate (t+2) for *d_mu */
  d_mu = sigma_mu + (t+1)*(t+2);
  d_mu[1] = syndr[0];
  
  /* allocate (t+2) for *l_mu */
  l_mu = d_mu + (t+2);
  for(i=0; i < t; i++)
    l_mu[i+2] = i + 1;
  
  /* allocate (t+2) for *mu_l_mu */
  mu_l_mu = l_mu + (t+2);
  for(i=0; i < t+2; i++)
    mu_l_mu[i] = mu[i] - l_mu[i];

  /* allocate (t+2) for *indx */
  /* allocate (t+1) for *shifted */
  /* allocate (t+1) for *tmpRoom */
  indx = mu_l_mu + (t+2);
  shifted = indx + (t+2);
  tmpRoom = shifted+(t+1);
  /* M-file
   *% iteratiev start with row three. The first two rows are filled.
   *for de_i = 3:t+2
   */
  for(de_i=2; de_i < t+2; de_i++){
    /*M-file
     *% no more effort to failed situation
     *if (d_mu(de_i - 1) < 0) | err
     *    sigma_mu(de_i, :) = sigma_mu(de_i-1, :);
     *    l_mu(de_i) = l_mu(de_i - 1);
     */
    if( d_mu[de_i-1] < 0 || err_In[0] != 0 ){
      for(j=0; j < t+1; j++)
	sigma_mu[de_i+j*(t+2)] = sigma_mu[de_i-1+j*(t+2)];
      l_mu[de_i] = l_mu[de_i-1];
      /*M-file
       *  else
       *      % find another row proceeding to row de_i -1
       *      % d_mu equals to zero
       *      % and mu - l_mu is the largest.
       *      indx = find(d_mu(1:de_i - 2) >= 0);
       *      rho  = find(mu_l_mu(indx) == max(mu_l_mu(indx)));
       *      rho = indx(rho(1));
       */
    } else {
      len_indx = 0;
      for(j=0; j < de_i-1; j++){
	if(d_mu[j] >= 0){
	  indx[len_indx] = j;
	  len_indx++;
	}
      }
      max = mu_l_mu[indx[0]];
      for(j=0; j < len_indx; j++){
	if(mu_l_mu[indx[j]] >= max)
	  max = mu_l_mu[indx[j]];
      }
      len_tmp = 0;
      for(j=0; j < len_indx; j++){
	if(mu_l_mu[indx[j]] != max){
	  len_tmp++;
	}else{
	  rho = indx[len_tmp];
	  j = len_indx;
	}
      }
      /* M-file
       *    % by (6.25)
       *    % shifted = gfmul(d_mu(de_i - 1), pow_dim - d_mu(rho), tp);
       *    % shifted = gfmul(shifted, sigma_mu(rho, :), tp)';
       *    % multiply inreplace the above two lines.
       *    shifted = -ones(1, t+1);
       *    if (d_mu(de_i - 1) >= 0) & (pow_dim - d_mu(rho) >= 0)
       *        tmp = rem(pow_dim - d_mu(rho) + d_mu(de_i - 1), pow_dim);
       *        indx = find(sigma_mu(rho,:) >= 0);
       *        for de_k = 1 : length(indx)
       *            shifted(indx(de_k)) = rem(tmp + sigma_mu(rho, indx(de_k)), pow_dim);
       *        end;            
       *    end;
       *    % end multiply
       */
      for(j=0; j < t+1; j++)
	shifted[j] = -1;
      
      if( d_mu[de_i-1]>=0 && (pow_dim-d_mu[rho])>=0 ){
	tmp = (pow_dim - d_mu[rho] + d_mu[de_i-1]) % pow_dim;
	/* take advantage of the memory of *indx */
	len_indx = 0;
	for(j=0; j < t+1; j++){
	  if( sigma_mu[rho+j*(t+2)] >= 0 ){
	    indx[len_indx] = j;
	    len_indx++;
	  }
	}
	for(de_k=0; de_k < len_indx; de_k++)
	  shifted[indx[de_k]] = (tmp + sigma_mu[rho+indx[de_k]*(t+2)]) % pow_dim;
      }
      shifting = mu[de_i-1] - mu[rho];
      
      /* M-file
       *  % calculate new sigma_mu
       *  if ~isempty(find(shifted(t-shifting+2 : t+1) >= 0))
       *      % more than t errors, BCH code fails.
       *        err = 1;
       *  else
       *      % calculate the new sigma
       *      shifted = [-ones(1, shifting) shifted(1:t-shifting+1)];
       *      sigma_mu(de_i, :) = gfplus(sigma_mu(de_i-1,:), shifted, tp_num, tp_inv);
       *  end;
       *  l_mu(de_i) = max(l_mu(de_i-1), l_mu(rho) + (de_i - 1) - rho);
       *end;
       */
      /* calculate new sigma_mu */
      len_tmp = 0;
      for(j=t-shifting+1; j < t+1; j++){
	if( shifted[j] >= 0 )
	  len_tmp++;
      }
      
      if (len_tmp != 0){
	err_In[0] = 1;
      }else{
	/* calculate the new sigma */
	for(j=0;j<t+1;j++)
	  tmpRoom[j]=shifted[j];
	
	for(j=0; j < shifting; j++)
	  shifted[j] = -1;
	if(shifting < t+1){
	  for(j=shifting; j < t+1; j++)
	    shifted[j] = tmpRoom[j-shifting];
                }
	for(j=0; j < t+1; j++)
	  gfplus(&sigma_mu[de_i-1+j*(t+2)],1,1, &shifted[j],1,1, pNum,pow_dim+1,pInv,pow_dim+1, &sigma_mu[de_i+j*(t+2)]);
      }
      if( l_mu[de_i-1] < l_mu[rho]+(de_i-1)-rho )
	l_mu[de_i] = l_mu[rho] + (de_i-1) - rho-1;
    }
    /*M-file
     *% calculate d_mu. It is not necessary to do so if mu(de_i) == t
     *if de_i < t+2
     *    % the constant term
     *    d_mu(de_i) = syndrome(mu(de_i) + 1);
     *    indx = find(sigma_mu(de_i, 2:t) >= 0);
     */
    if( de_i < t+1 ){
      d_mu[de_i] = syndr[mu[de_i]];
      len_indx = 0;
      for(j=1; j < t; j++){
	if( sigma_mu[de_i+j*(t+2)] >= 0 ){
	  indx[len_indx] = j-1;
	  len_indx++;
	}
      }
      /*M-file
       *for de_j = 1 : length(indx)
       *    de_j_tmp = indx(de_j);
       *        % Before the "end", it is equivalent to
       *        % d_mu(de_i) = gfadd(d_mu(de_i), ...
       *        %              gfmul(sigma_mu(de_i + 1, de_j_tmp+1), ...
       *        %              syndrome(mu(de_i) * 2 - de_j_tmp + 1), tp), tp);
       *    tmp = syndrome(mu(de_i) - de_j_tmp + 1);
       *    if (tmp < 0) | (sigma_mu(de_i, de_j_tmp + 1) < 0)
       *        tmp = -1;
       *    else
       *        tmp = rem(tmp + sigma_mu(de_i, de_j_tmp + 1), pow_dim);
       *    end;
       *    d_mu(de_i) = gfplus(d_mu(de_i), tmp, tp_num, tp_inv);
       *end;
       *end;--- this 'end' for 'if de_i < t+2
       */
      for(de_j=0; de_j < len_indx; de_j++){
	de_j_tmp = indx[de_j];
	tmp = syndr[ mu[de_i] - de_j_tmp -1];
	if( tmp < 0 || sigma_mu[de_i + (de_j_tmp+1)*(t+2)] < 0 )
	  tmp = -1;
	else
	  tmp = (tmp + sigma_mu[de_i+(de_j_tmp+1)*(t+2)] ) % pow_dim;
	
	gfplus(&d_mu[de_i],1,1,&tmp,1,1,pNum,pow_dim+1,pInv,pow_dim+1, &d_mu[de_i]);
      }
    }
    /*M-file
     *% calculate mu-l_mu
     *mu_l_mu(de_i) = mu(de_i) - l_mu(de_i);
     *end;
     */
    mu_l_mu[de_i] = mu[de_i] - l_mu[de_i];
  }
  /* truncate the reduancy */
  len_Out[0] = 0;
  for(i=0; i < t+1; i++){
    if ( sigma_mu[(t+1) + i*(t+2)] >= 0 )
      len_Out[0] = i;
  }
  len_Out[0] = len_Out[0] + 1;
  for(i=0; i < len_Out[0]; i++)
    sigma_Out[i] = sigma_mu[(t+1)+i*(t+2)];
}
/*--end of errlocp1()--*/
/*
 * errlocp0()
 *  Iwork --- 5*(t+2)+(t+4)*(t+1)
 *  Iwork = mu
 *      + t+2 = sigma_mu
 *          + (t+2)*(t+1) = d_mu
 *              + t+2 = l_mu
 *                  + t+2 = mu2_l_mu
 *                      + t+2 = indx
 *                          + t+2 = shifted
 *                              + t+1 = tmpRoom
 *                                  + t+1 = bottom of iwork in errlocp0() 
 */
static void errlocp0(syndr, t, pNum, pInv, pow_dim, err_In, Iwork, sigma_Out, len_Out)
     int *syndr, t, *pNum, *pInv, pow_dim, *err_In, *Iwork, *sigma_Out, *len_Out;
{
  int     i, j, k, de_i, de_j, de_k, de_j_tmp;
  int     len_indx, len_tmp, max, rho, shifting, tmp, print_flag;
  int     *mu, *sigma_mu, *d_mu, *l_mu, *mu2_l_mu, *tmpRoom, *indx, *shifted;
  
  /*M-file
   *% use simplified algorithm
   *mu = [-1/2, 0:t]';
   *sigma_mu = [zeros(t+2,1), -ones(t+2, t)];
   *d_mu = [0; syndrome(1); zeros(t, 1)];
   *l_mu = [0 0 2*(1:t)]';
   *mu2_l_mu = 2*mu - l_mu;
   */
  /* allocate (t+2) for *mu
   * this *mu is different with M-file, *mu = 2*mu
   */
  mu = Iwork ;
  mu[0] = -1;
  for(i=0; i < t+1; i++)
    mu[i+1] = 2*i;
  
  /* allocate (t+2)*(t+1) for *sigma_mu */    
  sigma_mu = mu + (t+2);
  for(i=0; i < (t+2)*(t+1); i++){
    if( i > t+1 )
      sigma_mu[i] = -1;
    else
      sigma_mu[i] = 0;     
  }
  
  /* allocate (t+2) for *d_mu */
  d_mu = sigma_mu + (t+2)*(t+1);
  d_mu[1] = syndr[0];
  
  /* allocate (t+2) for *l_mu */
  l_mu = d_mu + (t+2);
  for(i=0; i < t; i++)
    l_mu[i+2] = 2*(i + 1);
  
  /* allocate (t+2) for *mu2_l_mu */
  mu2_l_mu = l_mu + (t+2);
  for(i=0; i < t+2; i++)
    mu2_l_mu[i] = mu[i] - l_mu[i];
  
  /* allocate (t+2) for *indx */
  /* allocate (t+1) for *shifted */
  /* allocate (t+1) for *tmpRoom */
  indx = mu2_l_mu + (t+2);
  shifted = indx + (t+2);
  tmpRoom = shifted+(t+1);
  /* M-file
   *% iteratiev start with row three. The first two rows are filled.
   *for de_i = 3:t+2
   */
  for(de_i=2; de_i < t+2; de_i++){
    /*M-file
     *% no more effort to failed situation
     *if (d_mu(de_i - 1) < 0) | err
     *    sigma_mu(de_i, :) = sigma_mu(de_i-1, :);
     */
    if( d_mu[de_i-1] < 0 || err_In[0] != 0 ){
      for(j=0; j < t+1; j++)
	sigma_mu[de_i+j*(t+2)] = sigma_mu[de_i-1+j*(t+2)];
      /*M-file
       *  else
       *      % find another row proceeding to row de_i-1
       *      % d_mu equals to zero
       *      % and 2*mu - l_mu is the largest.
       *      indx = find(d_mu(1:de_i - 2) >= 0);
       *      rho  = find(mu2_l_mu(indx) == max(mu2_l_mu(indx)));
       *      rho = indx(rho(1));
       */
    } else {
      len_indx = 0;
      for(j=0; j < de_i-1; j++){
	if(d_mu[j] >= 0){
	  indx[len_indx] = j;
	  len_indx++;
	}
      }
      max = mu2_l_mu[0];
      for(j=0; j < len_indx; j++){
	if(mu2_l_mu[indx[j]] > max)
	  max = mu2_l_mu[indx[j]];
      }
      for(j=0; j < len_indx; j++){
	if(mu2_l_mu[indx[j]] == max)
	  rho = indx[j];
      }
      /* M-file
       *    % by (6.28)
       *    % shifted = gfmul(d_mu(de_i - 1), pow_dim - d_mu(rho), tp);
       *    % shifted = gfmul(shifted, sigma_mu(rho, :), tp)';
       *    % multiply inreplace the above two lines.
       *    shifted = -ones(1, t+1);
       *    if (d_mu(de_i - 1) >= 0) & (pow_dim - d_mu(rho) >= 0)
       *        tmp = rem(pow_dim - d_mu(rho) + d_mu(de_i - 1), pow_dim);
       *        indx = find(sigma_mu(rho,:) >= 0);
       *        for de_k = 1 : length(indx)
       *            shifted(indx(de_k)) = rem(tmp + sigma_mu(rho, indx(de_k)), pow_dim);
       *        end;            
       *    end;
       *    % end multiply
       */
      for(j=0; j < t+1; j++)
	shifted[j] = -1;
      
      if( d_mu[de_i-1]>=0 && (pow_dim-d_mu[rho])>=0 ){
	tmp = (pow_dim - d_mu[rho] + d_mu[de_i-1]) % pow_dim;
	
	/* take advantage of the memory of *indx */
	len_indx = 0;
	for(j=0; j < t+1; j++){
	  if( sigma_mu[rho+j*(t+2)] >= 0 ){
	    indx[len_indx] = j;
	    len_indx++;
	  }
	}
	for(de_k=0; de_k < len_indx; de_k++)
	  shifted[indx[de_k]] = (tmp + sigma_mu[rho+indx[de_k]*(t+2)]) % pow_dim;
      }
      /*M-file
       *shifting = (mu(de_i - 1) - mu(rho))*2;
       */
      shifting = mu[de_i-1] - mu[rho];
      
      /*M-file
       *% calculate new sigma_mu
       *if ~isempty(find(sigma_mu(1:de_i-2,max(1,t-shifting+2):t+1) >=0))
       *    disp('potential error more than posible')
       *    disp(['de_i=',num2str(de_i), ' shifting=',num2str(shifting)]);
       *    disp(sigma_mu)
       *    disp(['shifted=',mat2str(shifted)]);
       *end;
       */
      
      if ( t-shifting+2 > 1 )
	max = t - shifting + 1;
      else
	max = 0;
      print_flag = 0;
      for(j=0; j < de_i-2; j++){
	for(k=max; k < t+1; k++){
	  if( sigma_mu[j+k*(t+2)] >= 0 )
	    print_flag++;
	}
      }
      if ( print_flag != 0 ){
	/*                printf("potential error more than posible\n");
			  printf("de_i=%d,shifting=%d\n",de_i,shifting);
			  for(j=0; j<(t+2)*(t+1); j++)
			  printf("sigma_mu=%d\n",sigma_mu[j]);
			  printf("shifted=");
			  for(j=0; j < t+1; j++)
			  printf(" %d\n",shifted[j]); */
      }
      /*M-file
       *if ~isempty(find(shifted(max(t-shifting+2, 1) : t+1) >= 0))
       *    % more than t errors, BCH code fails.
       *    err = 1;
       *else
       *    % calculate the new sigma
       *    shifted = [-ones(1, shifting) shifted(1:t-shifting+1)];
       *    sigma_mu(de_i, :) = gfplus(sigma_mu(de_i-1,:), shifted, tp_num, tp_inv);
       *end;
       *end;--this end for "if (d_mu(de_i - 1) < 0) | err"
       *l_mu(de_i) = max(find(sigma_mu(de_i,:) >= 0)) - 1;
       */
      /* calculate new sigma_mu */
      len_tmp = 0;
      for(j=max; j < t+1; j++){
	if( shifted[j] >= 0 )
	  len_tmp++;
      }
      if (len_tmp > 0){
	err_In[0] = 1;
      }else{
	for(j=0;j<t+1;j++)
	  tmpRoom[j]=shifted[j];
	
	for(j=0; j < shifting; j++)
	  shifted[j] = -1;
	if(shifting < t+1){
	  for(j=shifting; j < t+1; j++)
	    shifted[j] = tmpRoom[j-shifting];
	}
	for(j=0; j < t+1; j++)
	  gfplus(&sigma_mu[de_i-1+j*(t+2)],1,1, &shifted[j],1,1, pNum,pow_dim+1,pInv,pow_dim+1, &sigma_mu[de_i+j*(t+2)]);
      }
    }
    for(j=0; j < t+1; j++){
      if(sigma_mu[de_i+j*(t+2)] >= 0)
	l_mu[de_i] = j;

⌨️ 快捷键说明

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