示例#1
0
文件: dirac.c 项目: MrMage/schwinger
// out = K^dag * in
// K_nm = (M + 4r) \delta_nm - 0.5 * \sum_\mu  ((r - \gamma_\mu) \delta_m,n+\mu + (r + \gamma_\mu) \delta_m,n-\mu)?
// Rothe, p. 56
// gamma_1/2 -> sigma_1/2, gamma_5 -> sigma_3, gamma_5 vorne dran
void gam5D_wilson(spinor *out, spinor *in) {
  int i;
  double factor = (2*g_R + g_mass);
  for(i=0; i<GRIDPOINTS; i++) {
    complex double link1_i = link1[i];
    spinor in_i = in[i];
    int left1_i = left1[i];
    int left2_i = left2[i];
    int right1_i = right1[i];
    int right2_i = right2[i];
    spinor in_right1_i = in[right1_i];
    spinor in_right2_i = in[right2_i];
    spinor in_left1_i = in[left1_i];
    spinor in_left2_i = in[left2_i];
    complex double cconj_link1_left1_i = cconj(link1[left1_i]);
    complex double cconj_link2_left2_i = cconj(link2[left2_i]);
    out[i].s1 = factor * in_i.s1 - 
    0.5*(link1_i*(g_R*in_right1_i.s1 - in_right1_i.s2) +
         cconj_link1_left1_i * ( g_R*in_left1_i.s1  +   in_left1_i.s2)  +
         link2[i] * ( g_R*in_right2_i.s1 + I*in_right2_i.s2) +
         cconj_link2_left2_i * ( g_R*in_left2_i.s1  - I*in_left2_i.s2));
    
    out[i].s2 = - factor * in_i.s2 -
    0.5*(link1_i * (   in_right1_i.s1 - g_R*in_right1_i.s2) -
         cconj_link1_left1_i * (in_left1_i.s1  + g_R*in_left1_i.s2)  +
         link2[i] * ( I*in_right2_i.s1 - g_R*in_right2_i.s2) -
         cconj_link2_left2_i * (I*in_left2_i.s1  + g_R*in_left2_i.s2));
  }
  return;
}
示例#2
0
文件: fdmdv.c 项目: guyt101z/codec2-1
float qpsk_to_bits(int rx_bits[], int *sync_bit, COMP phase_difference[], COMP prev_rx_symbols[], COMP rx_symbols[])
{
    int   c;
    COMP  pi_on_4;
    COMP  d;
    int   msb=0, lsb=0;
    float ferr;

    pi_on_4.real = cosf(PI/4.0);
    pi_on_4.imag = sinf(PI/4.0);

    /* Extra 45 degree clockwise lets us use real and imag axis as
       decision boundaries */

    for(c=0; c<NC; c++)
	phase_difference[c] = cmult(cmult(rx_symbols[c], cconj(prev_rx_symbols[c])), pi_on_4);
				    
    /* map (Nc,1) DQPSK symbols back into an (1,Nc*Nb) array of bits */

    for (c=0; c<NC; c++) {
      d = phase_difference[c];
      if ((d.real >= 0) && (d.imag >= 0)) {
         msb = 0; lsb = 0;
      }
      if ((d.real < 0) && (d.imag >= 0)) {
         msb = 0; lsb = 1;
      }
      if ((d.real < 0) && (d.imag < 0)) {
         msb = 1; lsb = 0;
      }
      if ((d.real >= 0) && (d.imag < 0)) {
         msb = 1; lsb = 1;
      }
      rx_bits[2*c] = msb;
      rx_bits[2*c+1] = lsb;
    }
 
    /* Extract DBPSK encoded Sync bit and fine freq offset estimate */

    phase_difference[NC] = cmult(rx_symbols[NC], cconj(prev_rx_symbols[NC]));
    if (phase_difference[NC].real < 0) {
      *sync_bit = 1;
      ferr = phase_difference[NC].imag;
    }
    else {
      *sync_bit = 0;
      ferr = -phase_difference[NC].imag;
    }
    
    /* pilot carrier gets an extra pi/4 rotation to make it consistent
       with other carriers, as we need it for snr_update and scatter
       diagram */

    phase_difference[NC] = cmult(phase_difference[NC], pi_on_4);

    return ferr;
}
示例#3
0
文件: fdmdv.c 项目: guyt101z/codec2-1
float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin)
{
    int  i,j;
    COMP pilot[M+M/P];
    COMP prev_pilot[M+M/P];
    float foff, foff1, foff2;
    float   max1, max2;

    assert(nin <= M+M/P);

    /* get pilot samples used for correlation/down conversion of rx signal */

    for (i=0; i<nin; i++) {
	pilot[i] = f->pilot_lut[f->pilot_lut_index];
	f->pilot_lut_index++;
	if (f->pilot_lut_index >= 4*M)
	    f->pilot_lut_index = 0;
	
	prev_pilot[i] = f->pilot_lut[f->prev_pilot_lut_index];
	f->prev_pilot_lut_index++;
	if (f->prev_pilot_lut_index >= 4*M)
	    f->prev_pilot_lut_index = 0;
    }

    /*
      Down convert latest M samples of pilot by multiplying by ideal
      BPSK pilot signal we have generated locally.  The peak of the
      resulting signal is sensitive to the time shift between the
      received and local version of the pilot, so we do it twice at
      different time shifts and choose the maximum.
    */

    for(i=0; i<NPILOTBASEBAND-nin; i++) {
	f->pilot_baseband1[i] = f->pilot_baseband1[i+nin];
	f->pilot_baseband2[i] = f->pilot_baseband2[i+nin];
    }

    for(i=0,j=NPILOTBASEBAND-nin; i<nin; i++,j++) {
       	f->pilot_baseband1[j] = cmult(rx_fdm[i], cconj(pilot[i]));
	f->pilot_baseband2[j] = cmult(rx_fdm[i], cconj(prev_pilot[i]));
    }

    lpf_peak_pick(&foff1, &max1, f->pilot_baseband1, f->pilot_lpf1, f->fft_pilot_cfg, f->S1, nin);
    lpf_peak_pick(&foff2, &max2, f->pilot_baseband2, f->pilot_lpf2, f->fft_pilot_cfg, f->S2, nin);

    if (max1 > max2)
	foff = foff1;
    else
	foff = foff2;
	
    return foff;
}
示例#4
0
文件: dirac.c 项目: MrMage/schwinger
// assumes that in g_gam5DX is gam5D * X 
// (X^*)(dM/da)(M)(X) + (X^*)(M)(dM/da)(X) = 2Re{(X^*)(dM/da)(M)(X)}
double trX_dQ_wilson_dalpha1_X(int j)
{
  return(creal(I*((cconj(link1[j]) 
		   * (cconj(g_X[right1[j]].s1)*(g_R*g_gam5DX[j].s1 +  g_gam5DX[j].s2) -
		      cconj(g_X[right1[j]].s2)*(  g_gam5DX[j].s1   + g_R*g_gam5DX[j].s2))) 
		  -
		  (link1[j] 
		   * (cconj(g_X[j].s1) * (g_R*g_gam5DX[right1[j]].s1-  g_gam5DX[right1[j]].s2) + 
		      cconj(g_X[j].s2) * (  g_gam5DX[right1[j]].s1-g_R*g_gam5DX[right1[j]].s2)))
		  )
	       )
	 );
}
示例#5
0
double pion_correlation_function(int t)
{
  double C = 0;
  for (int x = 0; x < X1; x ++)
  {
    int index = idx(x, t, X1);
    complex double a = R1[index].s1;
    complex double b = R1[index].s2;
    complex double c = R2[index].s1;
    complex double d = R2[index].s2;
    C += fabs(a * cconj(a) + b * cconj(b) + c * cconj(c) + d * cconj(d));
  }
  return C;
}
示例#6
0
double pcac_correlation_function(int t)
{
  complex double C = 0;
  for (int x = 0; x < X1; x ++)
  {
    int index = idx(x, t, X1);
    complex double a = R1[index].s1;
    complex double b = R1[index].s2;
    complex double c = R2[index].s1;
    complex double d = R2[index].s2;
    //C += I * (a * cconj(c) - c * cconj(a) + b * cconj(d) - d * cconj(b));
    C += -cimag(a * cconj(c)) - cimag(b * cconj(d));
    //C += -cimag(c);
    //C += -cimag(a * cconj(b)) - cimag(c * cconj(d));
  }
  C *= 2;
  if (fabs(cimag(C)) > 1e-6)
    printf("\nImaginary part of PCAC correlation function detected!\n");
  return fabs(C);
}
示例#7
0
文件: fdmdv.c 项目: guyt101z/codec2-1
void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin)
{
    int  i,c;

    /* maximum number of input samples to demod */

    assert(nin <= (M+M/P));

    /* Nc/2 tones below centre freq */
  
    for (c=0; c<NC/2; c++) 
	for (i=0; i<nin; i++) {
	    phase_rx[c] = cmult(phase_rx[c], freq[c]);
	    rx_baseband[c][i] = cmult(rx_fdm[i], cconj(phase_rx[c]));
	}

    /* Nc/2 tones above centre freq */

    for (c=NC/2; c<NC; c++) 
	for (i=0; i<nin; i++) {
	    phase_rx[c] = cmult(phase_rx[c], freq[c]);
	    rx_baseband[c][i] = cmult(rx_fdm[i], cconj(phase_rx[c]));
	}

    /* centre pilot tone  */

    c = NC;
    for (i=0; i<nin; i++) {
	phase_rx[c] = cmult(phase_rx[c],  freq[c]);
	rx_baseband[c][i] = cmult(rx_fdm[i], cconj(phase_rx[c]));
    }

    /* normalise digital oscilators as the magnitude can drfift over time */

    for (c=0; c<NC+1; c++) {
	phase_rx[c].real /= cabsolute(phase_rx[c]);	  
	phase_rx[c].imag /= cabsolute(phase_rx[c]);	  
    }
}
示例#8
0
void main()
{
    int gd = DETECT,gm,i, ch, cch;
    conj* A=iconj();
    conj* B=iconj();
    A=cconj(A);
    B=A;
    clrscr();
    do
    {
    printf("1. Presentacion\n");
    printf("2. Los elementos del conjunto A o B\n");
    printf("3. El producto cartesiano\n");
    printf("4. El conjunto relación (R)\n");
    printf("5. La matriz de adyacencia de la relación\n");
    printf("6. El dígrafo de la relación\n");
    printf("7. Salir\n");
    printf("Eliga una de las opciones presentadas.\n");
    scanf("%d", &ch);
    switch(ch)
    {
	case 1: presentacion();
		break;
	case 2: 
		printf("Que conjunto desea imprimir?\n1. A\n2. B\n");
		scanf("%d", &cch);
		if(cch==1){
			printf("A=");printj(A);
		} else if(cch==2){
			printf("B=");printj(B);
		}
		break;
	case 3: printf("Producto Cartesiano\n");
		pcar(A,B);
		break;
	case 4: printf("Conjunto de Relación\n");
		nrel(A,B,1);
		break;
	case 5: printf("Matriz relacion\n");
		matrel(A, B);
		break;
	case 6: graphic(&gd,&gm,A,B);
		break;
	case 7: printf("Gracias!");
		break;
	default: printf("Eliga de las opciones predeterminadas.\n");
    }
    }while (ch!=7);
    //printf("N: %d\n",A->X[0]);
    getch();
}
示例#9
0
文件: fdmdv.c 项目: guyt101z/codec2-1
void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, 
                                          COMP *foff_rect, COMP *foff_phase_rect, int nin)
{
    int   i;

    foff_rect->real = cosf(2.0*PI*foff/FS);
    foff_rect->imag = sinf(2.0*PI*foff/FS);
    for(i=0; i<nin; i++) {
	*foff_phase_rect = cmult(*foff_phase_rect, cconj(*foff_rect));
	rx_fdm_fcorr[i] = cmult(rx_fdm[i], *foff_phase_rect);
    }

    /* normalise digital oscilator as the magnitude can drfift over time */

    foff_phase_rect->real /= cabsolute(*foff_phase_rect);	 
    foff_phase_rect->imag /= cabsolute(*foff_phase_rect);	 
}
示例#10
0
static complex complex_inner_product(
    const complex *lhs,
    const complex *rhs,
    int length)
{
    complex accum;
    int i;

    accum.re = accum.im = 0.0f;
    for (i = 0; i < length; ++i)
    {
        const complex prod = cmult(
            cconj(lhs[i]), rhs[i]);
        accum.re += prod.re;
        accum.im += prod.im;
    }
    return accum; // ACCEPT_PERMIT
}
示例#11
0
static void compute_gamma_weights(
    APPROX float gamma[N_STEERING],
    complex (* const adaptive_weights)[N_BLOCKS][N_STEERING][N_CHAN*TDOF],
    complex (* const steering_vectors)[N_CHAN*TDOF],
    int range_block,
    int dop_index)
{
    int i, sv;
    complex accum;

    for (sv = 0; sv < N_STEERING; ++sv)
    {
        accum.re = accum.im = 0.0f;
        for (i = 0; i < N_CHAN*TDOF; ++i)
        {
            const complex prod = cmult(
                cconj(adaptive_weights[dop_index][range_block][sv][i]),
                steering_vectors[sv][i]);
            accum.re += prod.re;
            accum.im += prod.im;
        }

        /*
         * In exact arithmetic, accum should be a real positive
         * scalar and thus the imaginary component should be zero.
         * However, with limited precision that may not be the case,
         * so we take the magnitude of accum.  Also, gamma is a
         * normalization scalar and thus we take the inverse of
         * the computed inner product, w*v.
         */
        gamma[sv] = sqrt(accum.re*accum.re + accum.im*accum.im);
        if (ENDORSE(gamma[sv] > 0))
        {
            gamma[sv] = 1.0f / gamma[sv];
        }
        else
        {
            gamma[sv] = 1.0f;
        }
    }
}
示例#12
0
static int vq_phase(COMP cb[], COMP vec[], float weights[], int d, int e, float *se)
{
   float   error;	/* current error		*/
   int     besti;	/* best index so far		*/
   float   best_error;	/* best error so far		*/
   int	   i,j;
   int     ignore;
   COMP    diffr;
   float   diffp, metric, best_metric;

   besti = 0;
   best_metric = best_error = 1E32;
   for(j=0; j<e; j++) {
	error = 0.0;
	metric = 0.0;
	for(i=0; i<d; i++) {
	    ignore = (vec[i].real == 0.0) && (vec[i].imag == 0.0);
	    if (!ignore) {
		diffr = cmult(cb[j*d+i], cconj(vec[i]));
		diffp = atan2(diffr.imag, diffr.real);
		error  += diffp*diffp;
		metric += weights[i]*weights[i]*diffp*diffp;
		//metric += weights[i]*diffp*diffp;
		//metric = log10(weights[i]*fabs(diffp));
		//printf("diffp %f metric %f\n", diffp, metric);
		//if (metric < log10(PI/(8.0*sqrt(3.0))))
		//   metric = log10(PI/(8.0*sqrt(3.0)));
	    }
	}
	if (metric < best_metric) {
	    best_metric = metric;
	    best_error = error;
	    besti = j;
	}
   }

   *se += best_error;

   return(besti);
}
示例#13
0
static void forward_and_back_substitution(
    complex adaptive_weights[N_DOP][N_BLOCKS][N_STEERING][N_CHAN*TDOF],
    complex (* const cholesky_factors)[N_BLOCKS][N_CHAN*TDOF][N_CHAN*TDOF],
    complex (* const steering_vectors)[N_CHAN*TDOF])
{
    /*
     * We are solving the system R*Rx = b where upper triangular matrix R
     * is the result of Cholesky factorization.  To do so, we first apply
     * forward substitution to solve R*y = b for y and then apply back
     * substitution to solve Rx = y for x.  In this case, b and x correspond
     * to the steering vectors and adaptive weights, respectively.
     */

    complex (* R)[N_BLOCKS][N_CHAN*TDOF][N_CHAN*TDOF] = cholesky_factors;
    complex (* x)[N_BLOCKS][N_STEERING][N_CHAN*TDOF] = adaptive_weights;
    complex (* b)[N_CHAN*TDOF] = steering_vectors;
    int dop, block, sv, i, k;
    APPROX int j;
    complex accum;

    for (dop = 0; dop < N_DOP; ++dop)
    {
        for (block = 0; block < N_BLOCKS; ++block)
        {
            for (sv = 0; sv < N_STEERING; ++sv)
            {
                /* First apply forward substitution */
                for (i = 0; i < N_CHAN*TDOF; ++i)
                {
		    APPROX const float Rii_inv = 1.0f / R[dop][block][i][i].re;
                    accum.re = accum.im = 0.0f;
                    for (j = 0; ENDORSE(j < i); ++j)
                    {
                        /*
                         * Use the conjugate of the upper triangular entries
                         * of R as the lower triangular entries.
                         */
                        const complex prod = cmult(
                            cconj(R[dop][block][j][i]), x[dop][block][sv][j]);
                        accum.re += prod.re;
                        accum.im += prod.im;
                    }
                    x[dop][block][sv][i].re = (b[sv][i].re - accum.re) * Rii_inv;
                    x[dop][block][sv][i].im = (b[sv][i].im - accum.im) * Rii_inv;
                }

                /* And now apply back substitution */
                for (j = N_CHAN*TDOF-1; ENDORSE(j >= 0); --j)
                {
                    APPROX const float Rjj_inv = 1.0f / R[dop][block][j][j].re;
                    accum.re = accum.im = 0.0f;
                    for (k = ENDORSE(j+1); k < N_CHAN*TDOF; ++k)
                    {
                        const complex prod = cmult(
                            R[dop][block][j][k], x[dop][block][sv][k]);
                        accum.re += prod.re;
                        accum.im += prod.im;
                    }
                    x[dop][block][sv][j].re =
                        (x[dop][block][sv][j].re - accum.re) * Rjj_inv;
                    x[dop][block][sv][j].im =
                        (x[dop][block][sv][j].im - accum.im) * Rjj_inv;
                }
            }
        }
    }
}
示例#14
0
static void cholesky_factorization(
    complex cholesky_factors[N_DOP][N_BLOCKS][N_CHAN*TDOF][N_CHAN*TDOF],
    complex (* const covariance)[N_BLOCKS][N_CHAN*TDOF][N_CHAN*TDOF])
{
    int k, dop, block;
    APPROX int i, j;
    complex (* R)[N_BLOCKS][N_CHAN*TDOF][N_CHAN*TDOF] = NULL;
    APPROX float Rkk_inv, Rkk_inv_sqrt;

    /*
     * cholesky_factors is a working buffer used to factorize the
     * covariance matrices in-place.  We copy the covariance matrices
     * into cholesky_factors and give cholesky_factors the convenient
     * name R for a more succinct inner loop below.
     */
    memcpy(cholesky_factors, covariance,
        sizeof(complex)*N_DOP*N_BLOCKS*N_CHAN*TDOF*N_CHAN*TDOF);
    R = cholesky_factors;

    for (dop = 0; dop < N_DOP; ++dop)
    {
        for (block = 0; block < N_BLOCKS; ++block)
        {
            /*
             * The following Cholesky factorization notation is based
             * upon the presentation in "Numerical Linear Algebra" by
             * Trefethen and Bau, SIAM, 1997.
             */
            for (k = 0; k < N_CHAN*TDOF; ++k)
            {
                /*
                 * Hermitian positive definite matrices are assumed, but
                 * for safety we check that the diagonal is always positive.
                 */
                //assert(R[dop][block][k][k].re > 0);

                /* Diagonal entries are real-valued. */
                Rkk_inv = 1.0f / R[dop][block][k][k].re;
                Rkk_inv_sqrt = sqrt(Rkk_inv);

                for (j = k+1; ENDORSE(j < N_CHAN*TDOF); ++j)
                {
                    const complex Rkj_conj = cconj(R[dop][block][k][j]);
                    for (i = j; ENDORSE(i < N_CHAN*TDOF); ++i)
                    {
                        const complex Rki_Rkj_conj = cmult(
                            R[dop][block][k][i], Rkj_conj);
                        R[dop][block][j][i].re -= Rki_Rkj_conj.re * Rkk_inv;
                        R[dop][block][j][i].im -= Rki_Rkj_conj.im * Rkk_inv;
                    }
                }
                for (i = k; ENDORSE(i < N_CHAN*TDOF); ++i)
                {
                    R[dop][block][k][i].re *= Rkk_inv_sqrt;
                    R[dop][block][k][i].im *= Rkk_inv_sqrt;
                }
            }
            /*
             * Copy the conjugate of the upper triangular portion of R
             * into the lower triangular portion. This is not required
             * for correctness, but can help with testing and validation
             * (e.g., correctness metrics calculated over all elements
             * will not be "diluted" by trivially correct zeros in the
             * lower diagonal region).
             */
            for (i = 0; ENDORSE(i < N_CHAN*TDOF); ++i)
            {
	        for (j = i+1; ENDORSE(j < N_CHAN*TDOF); ++j)
                {
		    const complex x = R[dop][block][i][j]; // ACCEPT_PERMIT
                    R[dop][block][j][i].re = x.re;
                    R[dop][block][j][i].im = -1.0f * x.im;
                }
            }
        }
    }
}
示例#15
0
文件: fdmdv.c 项目: 0x0B501E7E/codec2
float qpsk_to_bits(int rx_bits[], int *sync_bit, int Nc, COMP phase_difference[], COMP prev_rx_symbols[], 
                   COMP rx_symbols[], int old_qpsk_mapping)
{
    int   c;
    COMP  pi_on_4;
    COMP  d;
    int   msb=0, lsb=0;
    float ferr, norm;

    pi_on_4.real = cos(PI/4.0);
    pi_on_4.imag = sin(PI/4.0);

    /* Extra 45 degree clockwise lets us use real and imag axis as
       decision boundaries. "norm" makes sure the phase subtraction
       from the previous symbol doesn't affect the amplitude, which
       leads to sensible scatter plots */

    for(c=0; c<Nc; c++) {
        norm = 1.0/(cabsolute(prev_rx_symbols[c])+1E-6);
	phase_difference[c] = cmult(cmult(rx_symbols[c], fcmult(norm,cconj(prev_rx_symbols[c]))), pi_on_4);
    }
				    
    /* map (Nc,1) DQPSK symbols back into an (1,Nc*Nb) array of bits */

    for (c=0; c<Nc; c++) {
      d = phase_difference[c];
      if ((d.real >= 0) && (d.imag >= 0)) {
          msb = 0; lsb = 0;
      }
      if ((d.real < 0) && (d.imag >= 0)) {
          msb = 0; lsb = 1;
      }
      if ((d.real < 0) && (d.imag < 0)) {
          if (old_qpsk_mapping) {
              msb = 1; lsb = 0;
          } else {
              msb = 1; lsb = 1;
          }
      }
      if ((d.real >= 0) && (d.imag < 0)) {
          if (old_qpsk_mapping) {
              msb = 1; lsb = 1;
          } else {
              msb = 1; lsb = 0;
          }
      }
      rx_bits[2*c] = msb;
      rx_bits[2*c+1] = lsb;
    }
 
    /* Extract DBPSK encoded Sync bit and fine freq offset estimate */

    norm = 1.0/(cabsolute(prev_rx_symbols[Nc])+1E-6);
    phase_difference[Nc] = cmult(rx_symbols[Nc], fcmult(norm, cconj(prev_rx_symbols[Nc])));
    if (phase_difference[Nc].real < 0) {
      *sync_bit = 1;
      ferr = phase_difference[Nc].imag;
    }
    else {
      *sync_bit = 0;
      ferr = -phase_difference[Nc].imag;
    }
    
    /* pilot carrier gets an extra pi/4 rotation to make it consistent
       with other carriers, as we need it for snr_update and scatter
       diagram */

    phase_difference[Nc] = cmult(phase_difference[Nc], pi_on_4);

    return ferr;
}