Exemplo n.º 1
0
/* From  Cain, Clark, "Error-Correction Coding For Digital Communications", pp. 216. */
void
Modified_Berlekamp_Massey (void)
{
	int n, L, L2, k, d, i;
	int psi[MAXDEG], psi2[MAXDEG], D[MAXDEG];
	int gamma[MAXDEG];

	/* initialize Gamma, the erasure locator polynomial */
	init_gamma(gamma);

	/* initialize to z */
	copy_poly(D, gamma);
	mul_z_poly(D);

	copy_poly(psi, gamma);
	k = -1;
	L = NErasures;

	for (n = NErasures; n < NPAR; n++) {

		d = compute_discrepancy(psi, synBytes, L, n);

		if (d != 0) {

			/* psi2 = psi - d*D */
			for (i = 0; i < MAXDEG; i++) psi2[i] = psi[i] ^ gmult(d, D[i]);


			if (L < (n-k)) {
				L2 = n-k;
				k = n-L;
				/* D = scale_poly(ginv(d), psi); */
				for (i = 0; i < MAXDEG; i++) D[i] = gmult(psi[i], ginv(d));
				L = L2;
			}

			/* psi = psi2 */
			for (i = 0; i < MAXDEG; i++) psi[i] = psi2[i];
		}

		mul_z_poly(D);
	}

	for(i = 0; i < MAXDEG; i++) Lambda[i] = psi[i];
	compute_modified_omega();


}
Exemplo n.º 2
0
void CReedSolomon::Modified_Berlekamp_Massey (void) {	

	int L, L2, k, d;
	int psi [MAX_LENGTH], psi2 [MAX_LENGTH], D [MAX_LENGTH];
	int gamma [MAX_LENGTH];
	int iMaxLength = m_iCorrectCodeSize * 2;
	
	/* initialize Gamma, the erasure locator polynomial */
	init_gamma (gamma);

	/* initialize to z */
	copy_poly (D, gamma);
	mul_z_poly (D);
	
	copy_poly (psi, gamma);	
	k = -1;
	L = m_NErasures;
	
	for (int n = m_NErasures; n < m_iCorrectCodeSize; n ++) {
		d = compute_discrepancy (psi, m_synBytes, L, n);
		
		if (d != 0) {
			/* psi2 = psi - d*D */
			for (int i = 0; i < iMaxLength; i++) {
				psi2 [i] = psi [i] ^ gmult (d, D [i]);
			}
			if (L < (n - k)) {
				L2 = n - k;
				k = n - L;
				/* D = scale_poly(ginv(d), psi); */
				for (int i = 0; i < iMaxLength; i ++) {
					D [i] = gmult (psi [i], ginv (d));
				}
				L = L2;
			}
			/* psi = psi2 */
			for (int i = 0; i < iMaxLength; i ++) {
				psi [i] = psi2 [i];
			}
		}
		mul_z_poly (D);
	}
	
	for (int i = 0; i < MAX_LENGTH; i ++) {
		m_Lambda [i] = psi [i];
	}
	compute_modified_omega ();
}
Exemplo n.º 3
0
void convert_ksprop_to_wprop_swv(spin_wilson_vector *swv, 
				 su3_vector *ksp, int r[], int r0[])
{
  int i;
  site *s;
  gamma_matrix_t gamma0;

  init_gamma();

  /* Construct source gamma adjoint */
  gamma0 = g1;   /* Unit gamma */
  mult_omega_l(&gamma0, r[0]-r0[0], r[1]-r0[1], r[2]-r0[2], r[3]-r0[3]);
  gamma_adj(&gamma0_dag, &gamma0);

  FORALLSITES(i,s){
    m_by_omega_swv( swv+i, ksp+i, s, r0);
  }
Exemplo n.º 4
0
// Given alf, the parameter α of the Laguerre polynomials, this routine
// returns arrays x[1..n] and w[1..n] containing the abscissas and weights
// of the n-point Gauss-Laguerre quadrature formula. The smallest abscissa is
// returned in x[1], the largest in x[n].
void gaulag(double x[], double w[], int n, int alf)
{
  int i, its, j;
  double ai;
  double p1,p2,p3,pp,z,z1;   // High precision is a good idea for this routine.
  init_gamma();
  for (i = 1; i <= n; i++) {  // Loop over the desired roots.
    if (i == 1) {  // Initial guess for the smallest root.
      z=(1.0+alf)*(3.0+0.92*alf)/(1.0+2.4*n+1.8*alf);
    } else if (i == 2) {  // Initial guess for the second root.
      z += (15.0+6.25*alf)/(1.0+0.9*alf+2.5*n);
    } else {   // Initial guess for the other roots.
      ai=i-2;
      z += ((1.0+2.55*ai)/(1.9*ai)+1.26*ai*alf/
           (1.0+3.5*ai))*(z-x[i-2])/(1.0+0.3*alf);
    }
    for (its=1;its<=MAXIT;its++) {   // Refinement by Newton’s method.
      p1=1.0;
      p2=0.0;
      for (j=1;j<=n;j++) {   // Loop up the recurrence relation to get the
        p3=p2;                 // Laguerre polynomial evaluated at z.
        p2=p1;
        p1=((2*j-1+alf-z)*p2-(j-1+alf)*p3)/j;
      }
      // p1 is now the desired Laguerre polynomial. We next compute pp,
      // its derivative, by a standard relation involving also p2,
      // the polynomial of one lower order.
      pp=(n*p1-(n+alf)*p2)/z;
      z1=z;
      z=z1-p1/pp;    // Newton’s formula.
      if (fabs(z-z1) <= EPS) break;
    }
    if (its > MAXIT) nrerror("too many iterations in gaulag");
    x[i]=z;   // Store the root and the weight.
    w[i] = -exp(gammaln[alf+n]-gammaln[n])/(pp*n*p2);
  }
}