Exemple #1
0
void xkolmog(sf_complex *trace1, sf_complex *trace2)
/*< convert Fourier-domain cross-correlation to minimum-phase >*/ 
{
    int i1;
    const double eps=1.e-32;

    for (i1=0; i1 < nk; i1++) {
#ifdef SF_HAS_COMPLEX_H
	fft1[i1] = clogf(trace1[i1]+eps)/nk;
#else
	fft1[i1] = sf_crmul(clogf(sf_cadd(trace1[i1],sf_cmplx(eps,0.))),
			    1.0/nk);
#endif
    }

    /* Inverse transform */
    kiss_fft(invs,(const kiss_fft_cpx *) fft1, (kiss_fft_cpx *) trace1);

#ifdef SF_HAS_COMPLEX_H
    trace1[0]    *= 0.5; trace2[0]    = trace1[0];
    trace1[nk/2] *= 0.5; trace2[nk/2] = trace1[nk/2];
#else
    trace1[0]    = sf_crmul(trace1[0],   0.5); trace2[0]    = trace1[0];
    trace1[nk/2] = sf_crmul(trace1[nk/2],0.5); trace2[nk/2] = trace1[nk/2];
#endif
    for (i1=1+nk/2; i1 < nk; i1++) {
	trace2[nk-i1] = trace1[i1];
	trace1[i1] = sf_cmplx(0.,0.);
	trace2[i1] = sf_cmplx(0.,0.);
    }

    /* Fourier transform */
    kiss_fft(forw,(const kiss_fft_cpx *) trace1, (kiss_fft_cpx *) fft1);
    kiss_fft(forw,(const kiss_fft_cpx *) trace2, (kiss_fft_cpx *) fft2);
    
    for (i1=0; i1 < nk; i1++) {
#ifdef SF_HAS_COMPLEX_H
	fft1[i1] = cexpf(fft1[i1])/nk;
	fft2[i1] = cexpf(fft2[i1])/nk;
#else
	fft1[i1] = sf_crmul(cexpf(fft1[i1]),1./nk);
	fft2[i1] = sf_crmul(cexpf(fft2[i1]),1./nk);
#endif
    }

    /* Inverse transform */
    kiss_fft(invs,(const kiss_fft_cpx *) fft1, (kiss_fft_cpx *) trace1);
    kiss_fft(invs,(const kiss_fft_cpx *) fft2, (kiss_fft_cpx *) trace2);

    for (i1=0; i1 < nk; i1++) {
	trace2[i1] = conjf(trace2[i1]);
    }
}
Exemple #2
0
float complex sandbox_cacosf(float complex _z)
{
    // return based on quadrant
    int sign_i = crealf(_z) > 0;
    int sign_q = cimagf(_z) > 0;

    if (sign_i == sign_q) {
        return - _Complex_I*clogf(_z + csqrtf(_z*_z - 1.0f));
    } else {
        return - _Complex_I*clogf(_z - csqrtf(_z*_z - 1.0f));
    }

    // should never get to this state
    return 0.0f;
}
Exemple #3
0
float complex 
catanf (float complex Z)
{
  float complex Res;
  float complex Tmp;
  float x = __real__ Z;
  float y = __imag__ Z;

  if ( x == 0.0f && (1.0f - fabsf (y)) == 0.0f)
    {
      errno = ERANGE;
      __real__ Res = HUGE_VALF;
      __imag__ Res = HUGE_VALF;
    }
   else if (isinf (hypotf (x, y)))
   {
     __real__ Res = (x > 0 ? M_PI_2 : -M_PI_2);
     __imag__ Res = 0.0f;
   }
  else
    {
      __real__ Tmp = - x; 
      __imag__ Tmp = 1.0f - y;

      __real__ Res = x; 
      __imag__ Res = y + 1.0f;

      Tmp = clogf (Res/Tmp);	
      __real__ Res  = - 0.5f * __imag__ Tmp;
      __imag__ Res =  0.5f * __real__ Tmp;
    }

   return Res; 
}
Exemple #4
0
float complex casinf(float complex z)
{
	float complex w;
	float x, y;

	x = crealf(z);
	y = cimagf(z);
	w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y);
	return clogf(CMPLXF(-y, x) + csqrtf(w));
}
Exemple #5
0
float complex
cacoshf(float complex z)
{
	float complex w;

#if 0 /* does not give the principal value */
	w = I * cacosf(z);
#else
	w = clogf(z + csqrtf(z + 1) * csqrtf(z - 1));
#endif
	return w;
}
Exemple #6
0
 ld = ccoshl(ld);
 TEST_TRACE(C99 7.3.6.5)
 d = csinh(d);
 f = csinhf(f);
 ld = csinhl(ld);
 TEST_TRACE(C99 7.3.6.6)
 d = ctanh(d);
 f = ctanhf(f);
 ld = ctanhl(ld);
 TEST_TRACE(C99 7.3.7.1)
 d = cexp(d);
 f = cexpf(f);
 ld = cexpl(ld);
 TEST_TRACE(C99 7.3.7.2)
 d = clog(d);
 f = clogf(f);
 ld = clogl(ld);
 TEST_TRACE(C99 7.3.8.1)
 d = cabs(d);
 f = cabsf(f);
 ld = cabsl(ld);
 TEST_TRACE(C99 7.3.8.2)
 d = cpow(d, d);
 f = cpowf(f, f);
 ld = cpowl(ld, ld);
 TEST_TRACE(C99 7.3.8.3)
 d = csqrt(d);
 f = csqrtf(f);
 ld = csqrtl(ld);
 TEST_TRACE(C99 7.3.9.1)
 d = carg(d);
Exemple #7
0
float complex
cpowf (float complex base, float complex power)
{
  return cexpf (power * clogf (base));
}
Exemple #8
0
complex float
cacosf (complex float z)
{
  return -I*clogf (z + I*csqrtf (1.0f-z*z));
}
int main() {
    unsigned int n=32;  // number of tests
    unsigned int d=2;   // number items per line

    // data arrays
    float complex z[n];
    float complex test[n];

    unsigned int i;
    float complex err_max = 0.0f;
    for (i=0; i<n; i++) {
        // generate random complex number
        z[i] = 4.0f*(2.0f*sandbox_randf() - 1.0f) +
               4.0f*(2.0f*sandbox_randf() - 1.0f) * _Complex_I;

        test[i] = clogf(z[i]);
        float complex logz_hat = sandbox_clogf(z[i]);

        float complex err = test[i] - logz_hat;

        printf("%3u: z=%6.2f+j%6.2f, log(z)=%6.2f+j%6.2f (%6.2f+j%6.2f) e=%12.4e\n",
                i,
                crealf(z[i]),       cimagf(z[i]),
                crealf(test[i]),    cimagf(test[i]),
                crealf(logz_hat),   cimagf(logz_hat),
                cabsf(err));

        if ( cabsf(err) > cabsf(err_max) )
            err_max = err;
    }

    printf("maximum error: %12.4e;\n", cabsf(err_max));

    // 
    // print autotest lines
    //

    printf("\n");
    printf("    float complex z[%u] = {\n      ", n);
    for (i=0; i<n; i++) {
        printf("%12.4e+_Complex_I*%12.4e", crealf(z[i]), cimagf(z[i]));

        if ( i == n-1)
            printf(" ");
        else if ( ((i+1)%d)==0 )
            printf(",\n      ");
        else
            printf(", ");
    }
    printf("};\n");

    printf("\n");
    printf("    float complex test[%u] = {\n      ", n);
    for (i=0; i<n; i++) {
        printf("%12.4e+_Complex_I*%12.4e", crealf(test[i]), cimagf(test[i]));

        if ( i == n-1)
            printf(" ");
        else if ( ((i+1)%d)==0 )
            printf(",\n      ");
        else
            printf(", ");
    }
    printf("};\n");

    printf("done.\n");
    return 0;
}
Exemple #10
0
float complex sandbox_catanf(float complex _z)
{
    return 0.5f*_Complex_I*clogf( (1.0f-_Complex_I*_z)/(1.0f+_Complex_I*_z) );
}
Exemple #11
0
complex float
catanhf (complex float z)
{
  return clogf ((1.0f+z)/(1.0f-z))/2.0f;
}
Exemple #12
0
complex float
cacoshf (complex float z)
{
  return clogf (z + csqrtf (z-1.0f) * csqrtf (z+1.0f));
}
Exemple #13
0
complex float
casinhf (complex float z)
{
  return clogf (z + csqrtf (z*z+1.0f));
}
Exemple #14
0
complex float
catanf (complex float z)
{
  return I*clogf ((I+z)/(I-z))/2.0f;
}
/* pow(base, power) = cexp (power * clog (base))  */
GFC_COMPLEX_4
cpowf (GFC_COMPLEX_4 base, GFC_COMPLEX_4 power)
{
  return cexpf (power * clogf (base));
}
Exemple #16
0
float complex
casinf(float complex z)
{
	float complex w;
	float complex ca, ct, zz, z2;
	float x, y;

	x = crealf(z);
	y = cimagf(z);

#if 0 /* MD: test is incorrect, casin(>1) is defined */
	if (y == 0.0f) {
		if (fabsf(x) > 1.0) {
			w = M_PI_2 + 0.0f * I;
#if 0
			mtherr ("casin", DOMAIN);
#endif
		} else {
			w = asinf(x) + 0.0f * I;
		}
		return w;
	}
#endif

/* Power series expansion */
/*
b = cabsf(z);
if( b < 0.125 )
{
z2.r = (x - y) * (x + y);
z2.i = 2.0 * x * y;

cn = 1.0;
n = 1.0;
ca.r = x;
ca.i = y;
sum.r = x;
sum.i = y;
do
	{
	ct.r = z2.r * ca.r  -  z2.i * ca.i;
	ct.i = z2.r * ca.i  +  z2.i * ca.r;
	ca.r = ct.r;
	ca.i = ct.i;

	cn *= n;
	n += 1.0;
	cn /= n;
	n += 1.0;
	b = cn/n;

	ct.r *= b;
	ct.i *= b;
	sum.r += ct.r;
	sum.i += ct.i;
	b = fabsf(ct.r) + fabsf(ct.i);
	}
while( b > MACHEP );
w->r = sum.r;
w->i = sum.i;
return;
}
*/


	ca = x + y * I;
	ct = ca * I;
	/* sqrt( 1 - z*z) */
	/* cmul( &ca, &ca, &zz ) */
	/*x * x  -  y * y */
	zz = (x - y) * (x + y) + (2.0f * x * y) * I;

	zz = 1.0f - crealf(zz) - cimagf(zz) * I;
	z2 = csqrtf(zz);

	zz = ct + z2;
	zz = clogf(zz);
	/* multiply by 1/i = -i */
	w = zz * (-1.0f * I);
	return w;
}
Exemple #17
0
void
docomplexf (void)
{
#ifndef NO_FLOAT
  complex float ca, cb, cc;
  float f1;

  ca = 1.0 + 1.0 * I;
  cb = 1.0 - 1.0 * I;

  f1 = cabsf (ca);
  fprintf (stdout, "cabsf  : %f\n", f1);

  cc = cacosf (ca);
  fprintf (stdout, "cacosf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = cacoshf (ca);
  fprintf (stdout, "cacoshf: %f %fi\n", crealf (cc),
	   cimagf (cc));

  f1 = cargf (ca);
  fprintf (stdout, "cargf  : %f\n", f1);

  cc = casinf (ca);
  fprintf (stdout, "casinf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = casinhf (ca);
  fprintf (stdout, "casinhf: %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = catanf (ca);
  fprintf (stdout, "catanf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = catanhf (ca);
  fprintf (stdout, "catanhf: %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = ccosf (ca);
  fprintf (stdout, "ccosf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = ccoshf (ca);
  fprintf (stdout, "ccoshf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = cexpf (ca);
  fprintf (stdout, "cexpf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  f1 = cimagf (ca);
  fprintf (stdout, "cimagf : %f\n", f1);

  cc = clogf (ca);
  fprintf (stdout, "clogf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = conjf (ca);
  fprintf (stdout, "conjf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = cpowf (ca, cb);
  fprintf (stdout, "cpowf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = cprojf (ca);
  fprintf (stdout, "cprojf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  f1 = crealf (ca);
  fprintf (stdout, "crealf : %f\n", f1);

  cc = csinf (ca);
  fprintf (stdout, "csinf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = csinhf (ca);
  fprintf (stdout, "csinhf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = csqrtf (ca);
  fprintf (stdout, "csqrtf : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = ctanf (ca);
  fprintf (stdout, "ctanf  : %f %fi\n", crealf (cc),
	   cimagf (cc));

  cc = ctanhf (ca);
  fprintf (stdout, "ctanhf : %f %fi\n", crealf (cc),
	   cimagf (cc));
#endif
}
Exemple #18
0
float complex
casinf(float complex z)
{
	float complex w;
	float x, y;
	static float complex ca, ct, zz, z2;
	/*
	float cn, n;
	static float a, b, s, t, u, v, y2;
	static cmplxf sum;
	*/

	x = crealf(z);
	y = cimagf(z);

#if 0
	if(y == 0.0f) {
		if(fabsf(x) > 1.0f) {
			w = (float)M_PI_2 + 0.0f * I;
			/*mtherr( "casinf", DOMAIN );*/
		}
		else {
			w = asinf (x) + 0.0f * I;
		}
		return (w);
	}
#endif

	/* Power series expansion */
	/*
	b = cabsf(z);
	if(b < 0.125) {
		z2.r = (x - y) * (x + y);
		z2.i = 2.0 * x * y;

		cn = 1.0;
		n = 1.0;
		ca.r = x;
		ca.i = y;
		sum.r = x;
		sum.i = y;
		do {
			ct.r = z2.r * ca.r  -  z2.i * ca.i;
			ct.i = z2.r * ca.i  +  z2.i * ca.r;
			ca.r = ct.r;
			ca.i = ct.i;

			cn *= n;
			n += 1.0;
			cn /= n;
			n += 1.0;
			b = cn/n;

			ct.r *= b;
			ct.i *= b;
			sum.r += ct.r;
			sum.i += ct.i;
			b = fabsf(ct.r) + fabsf(ct.i);
		}
		while(b > MACHEPF);
		w->r = sum.r;
		w->i = sum.i;
		return;
	}
	*/


	ca = x + y * I;
	ct = ca * I;	/* iz */
	/* sqrt( 1 - z*z) */
	/* cmul( &ca, &ca, &zz ) */
	/*x * x  -  y * y */
	zz = (x - y) * (x + y) + (2.0f * x * y) * I;
	zz = 1.0f - crealf(zz) - cimagf(zz) * I;
	z2 = csqrtf (zz);

	zz = ct + z2;
	zz = clogf (zz);
	/* multiply by 1/i = -i */
	w = zz * (-1.0f * I);
	return (w);
}
Exemple #19
0
complex float
casinf (complex float z)
{
  return -I*clogf (I*z + csqrtf (1.0f-z*z));
}