Пример #1
0
main()
{
	int n1,n2,j;
	float scale,sumz,sume;
 
	for (n1=1,n2=npfa(n1+1); n2<NMAX; n1=n2,n2=npfa(n1+1)) {
		for (j=0; j<n1*n2; j++)
			c[j] = z[j] = cmplx(franuni(),franuni());
		pfamcc(1,n1,n2,1,n1,z);
		pfamcc(1,n2,n1,n1,1,z);
		pfamcc(-1,n1,n2,1,n1,z);
		pfamcc(-1,n2,n1,n1,1,z);
		scale = 1.0/(float)(n1*n2);
		for (j=0; j<n1*n2; j++)
			z[j] = crmul(z[j],scale);

		for (j=0,sumz=sume=0.0; j<n1*n2; j++) {
			sumz += fcabs(z[j]);
			sume += fcabs(csub(z[j],c[j]));
		}
		printf("n1 = %d  n2 = %d  sume/sumz = %0.10f\n",
			n1,n2,sume/sumz);
		if (sume/sumz>1.0e-6) printf("!!! warning !!!\n");
	}
}
Пример #2
0
void
z_log(dcomplex *r, dcomplex *z)
{

	r->dimag = atan2(z->dimag, z->dreal);
	r->dreal = log( fcabs( z->dreal, z->dimag ) );
}
Пример #3
0
void
c_log(complex *r, complex *z)
{

	r->imag = atan2(z->imag, z->real);
	r->real = log( fcabs(z->real, z->imag) );
}
Пример #4
0
main()
{
	int npoles,nfft,i;
	float f3db,zero=0.0,fpass,apass,fstop,astop;

/*
	printf("Enter npoles f3db:\n");
	scanf("%d %f",&npoles,&f3db);
*/
	printf("Enter fpass apass fstop astop:\n");
	scanf("%f %f %f %f",&fpass,&apass,&fstop,&astop);
	bfdesign(fpass,apass,fstop,astop,&npoles,&f3db);
	printf("npoles = %d  f3db = %f\n",npoles,f3db);

	/* impulse response */
	scopy(N,&zero,0,p,1);
	p[0] = 1.0;
	bflowpass(npoles,f3db,N,p,q);
	pp1d(stdout,"impulse response",N,0,q);

	/* amplitude spectrum */
	nfft = npfa(N);
	for (i=0; i<N; i++)
		z[i] = cmplx(q[i],0.0);
	for (i=N; i<nfft; i++)
		z[i] = cmplx(0.0,0.0);
	pfacc(1,nfft,z);
	for (i=0; i<nfft; i++)
		zamp[i] = fcabs(z[i]);
	pp1d(stdout,"amplitude spectrum",nfft/2+1,0,zamp);
}
Пример #5
0
void
z_sqrt(dcomplex *r, dcomplex *z)
{
	double mag;

	if( (mag = fcabs(z->dreal, z->dimag)) == 0.)
		r->dreal = r->dimag = 0.;
	else if(z->dreal > 0) {
		r->dreal = sqrt(0.5 * (mag + z->dreal) );
		r->dimag = z->dimag / r->dreal / 2;
	} else {
		r->dimag = sqrt(0.5 * (mag - z->dreal) );
		if(z->dimag < 0)
			z->dimag = - z->dimag;
		r->dreal = z->dimag / r->dimag / 2;
	}
}
Пример #6
0
void
c_sqrt(complex *r, complex *z)
{
	double mag;

	if( (mag = fcabs(z->real, z->imag)) == 0.)
		r->real = r->imag = 0.;
	else if(z->real > 0) {
		r->real = sqrt(0.5 * (mag + z->real) );
		r->imag = z->imag / r->real / 2;
	} else {
		r->imag = sqrt(0.5 * (mag - z->real) );
		if(z->imag < 0)
			r->imag = - r->imag;
		r->real = z->imag / r->imag /2;
	}
}
Пример #7
0
double
z_abs(dcomplex *z)
{

	return( fcabs( z->dreal, z->dimag ) );
}
Пример #8
0
float
c_abs(complex *z)
{
	return( fcabs( z->real, z->imag ) );
}
Пример #9
0
main(int argc, char **argv)
{
	int nt,nx;		/* numbers of samples			*/
	float dt,dx;		/* sampling intervals			*/
	float d1,d2;		/* output intervals in F, K		*/
	float f1,f2;		/* output first samples in F, K		*/
	int it,ix;		/* sample indices			*/
	int ntfft,nxfft;	/* dimensions after padding for FFT	*/
	int nF,nK;		/* transform (output) dimensions	*/
	int iF,iK;		/* transform sample indices		*/
	register complex **ct;	/* complex FFT workspace		*/
	register float **rt;	/* float FFT workspace			*/
	FILE *tracefp;		/* temp file to hold traces		*/


	/* Hook up getpar to handle the parameters */
	initargs(argc,argv);
	askdoc(1);


	/* Get info from first trace */ 
	if (!gettr(&intrace))  err("can't get first trace");
	nt = intrace.ns;


	/* dt is used only to set output header value d1 */
	if (!getparfloat("dt", &dt)) {
		if (intrace.dt) { /* is dt field set? */
			dt = (float) intrace.dt / 1000000.0;
		} else { /* dt not set, assume 4 ms */
			dt = 0.004;
			warn("tr.dt not set, assuming dt=0.004");
		}
	}
	if (!getparfloat("dx",&dx)) {
		if (intrace.d2) { /* is d2 field set? */
			dx = intrace.d2;
		} else {
			dx = 1.0;
			warn("tr.d2 not set, assuming d2=1.0");
		}
	}


	/* Store traces in tmpfile while getting a count */
	/*tracefp = etmpfile();*/
	tracefp = etempfile(NULL);
	nx = 0;
	do { 
		++nx;
		efwrite(intrace.data, FSIZE, nt, tracefp);
	} while (gettr(&intrace));


	/* Determine lengths for prime-factor FFTs */
	ntfft = npfar(nt);
	nxfft = npfa(nx);
	if (ntfft >= MIN(SU_NFLTS, PFA_MAX)) err("Padded nt=%d--too big",ntfft);
	if (nxfft >= MIN(SU_NFLTS, PFA_MAX)) err("Padded nx=%d--too big",nxfft);


	/* Determine output header values */
	d1 = 1.0/(ntfft*dt);
	d2 = 1.0/(nxfft*dx);
	f1 = 0.0;
	f2 = -1.0/(2*dx);


	/* Determine complex transform sizes */
	nF = ntfft/2+1;
	nK = nxfft;


	/* Allocate space */
	ct = alloc2complex(nF, nK);
	rt = alloc2float(ntfft, nxfft);


	/* Load traces into fft arrays and close tmpfile */
	rewind(tracefp);
	for (ix=0; ix<nx; ++ix) {

		efread(rt[ix], FSIZE, nt, tracefp);

                /* if ix odd, negate to center transform of dimension 2 */
                if (ISODD(ix))
			for (it=0; it<nt; ++it)  rt[ix][it] = -rt[ix][it];

		/* pad dimension 1 with zeros */
		for (it=nt; it<ntfft; ++it)  rt[ix][it] = 0.0;
	}
	efclose(tracefp);


	/* Pad dimension 2 with zeros */
	for (ix=nx; ix<nxfft; ++ix)
		for (it=0; it<ntfft; ++it)  rt[ix][it] = 0.0;

	
	/* Fourier transform dimension 1 */
	pfa2rc(1,1,ntfft,nx,rt[0],ct[0]);
	

	/* Fourier transform dimension 2 */
	pfa2cc(-1,2,nF,nxfft,ct[0]);
	

	/* Compute and output amplitude spectrum */
	for (iK=0; iK<nK; ++iK) {
		for (iF=0; iF<nF; ++iF)  outtrace.data[iF] = fcabs(ct[iK][iF]);

		/* set header values */
		outtrace.tracl = iK + 1;
		outtrace.ns = nF;
		outtrace.dt = 0;  /* d1 is now the relevant step size */
		outtrace.trid = KOMEGA;
		outtrace.d1 = d1;
		outtrace.f1 = f1;
		outtrace.d2 = d2;
		outtrace.f2 = f2;

		puttr(&outtrace);
	}
}