void makeds (int ns, float *ts, float *as, int lds, int ifds, float *ds) /***************************************************************************** make shaping filter to correct DMO horizontal reflection response ****************************************************************************** Input: ns number of shifts ts array[ns] of time shifts (normalized by sampling interval) as array[ns] of amplitudes corresponding to time shifts lds length of shaping filter ifds index of first sample of shaping filter (see notes) Output: ds array[lds] containing shaping filter ****************************************************************************** Notes: Reasonable values for lds and ifds are lds=125 and ifds=-100. The maximum permissible lds is the dimension of dd, di, and work below. This function must be kept consistent with that used to perform DMO. ****************************************************************************** Author: Dave Hale, Colorado School of Mines, 11/04/90 *****************************************************************************/ #define LDMAX 400 #define LDSMAX 300 { int ld=LDMAX,ifd=1-ld,i,is; float one=1.0,d[LDMAX],dd[LDSMAX],di[LDSMAX],work[LDSMAX]; /* compute dmo horizontal reflection response d(t) */ for (i=0; i<ld; ++i) d[i] = 0.0; d[ld-1] = as[0]; for (is=1; is<ns; ++is) { i = (int)ts[is]; d[ld-i-1] += 2.0*as[is]; } /* compute autocorrelation of d(t) */ xcor(ld,ifd,d,ld,ifd,d,lds,0,dd); /* compute crosscorrelation of d(t) and desired impulse i(t) */ xcor(ld,ifd,d,1,0,&one,lds,ifds,di); /* solve symmetric toeplitz system of equations for filter */ stoepf(lds,dd,di,ds,work); }
main(int argc, char **argv) { int nt; /* number of points on trace */ float dt; /* time sample interval (sec) */ float *wiener; /* Wiener error filter coefficients */ float pnoise; /* pef additive noise level */ float minlag; /* start of error filter (sec) */ int iminlag; /* ... in samples */ float maxlag; /* end of error filter (sec) */ int imaxlag; /* ... in samples */ int nlag; /* length of error filter in samples */ int ncorr; /* length of corr window in samples */ float *crosscorr; /* right hand side of Wiener eqs */ float *autocorr; /* vector of autocorrelations */ float *spiker; /* spiking decon filter */ float mincorr; /* start time of correlation window */ int imincorr; /* .. in samples */ float maxcorr; /* end time of correlation window */ int imaxcorr; /* .. in samples */ int showspiker; /* flag to display spiking filter */ int showwiener; /* flag to display pred. error filter */ /* Initialize */ initargs(argc, argv); askdoc(1); /* Get info from first trace */ if (!gettr(&intrace)) err("can't get first trace"); nt = intrace.ns; dt = (float)intrace.dt/1000000.0; if (!dt) MUSTGETPARFLOAT ("dt", &dt); /* Get parameters */ if (!getparint("showwiener", &showwiener)) showwiener = 0; if (!getparint("showspiker", &showspiker)) showspiker = 0; if (!getparfloat("pnoise", &pnoise)) pnoise = PNOISE; if (getparfloat("minlag", &minlag)) iminlag = NINT(minlag/dt); else iminlag = 1; if (iminlag < 1) err("minlag=%g too small", minlag); if (getparfloat("maxlag", &maxlag)) imaxlag = NINT(maxlag/dt); else imaxlag = NINT(0.05 * nt); if (imaxlag >= nt) err("maxlag=%g too large", maxlag); if (iminlag >= imaxlag) err("minlag=%g, maxlag=%g", minlag, maxlag); if (getparfloat("mincorr", &mincorr)) imincorr = NINT(mincorr/dt); else imincorr = 0; if (imincorr < 0) err("mincorr=%g too small", mincorr); if (getparfloat("maxcorr", &maxcorr)) imaxcorr = NINT(maxcorr/dt); else imaxcorr = nt-1; if (imaxcorr >= nt) err("maxcorr=%g too large", maxcorr); if (imincorr >= imaxcorr) err("mincorr=%g, maxcorr=%g", mincorr, maxcorr); nlag = imaxlag - iminlag + 1; ncorr = imaxcorr - imincorr + 1; /* Allocate memory */ wiener = ealloc1float(nlag); spiker = ealloc1float(nlag); autocorr = ealloc1float(imaxlag); /* Set pointer to "cross" correlation */ crosscorr = autocorr + iminlag; /* Main loop over traces */ do { static int itr = 0; ++itr; /* Form autocorrelation vector */ xcor(ncorr, imincorr, intrace.data, ncorr, imincorr, intrace.data, imaxlag, 0, autocorr); /* Leave trace alone if autocorr[0] vanishes */ if (autocorr[0] == 0.0) { puttr(&intrace); if (showwiener) warn("NO Wiener filter, trace: %d", itr); if (showspiker) warn("NO spiking decon filter, trace: %d", itr); continue; } /* Whiten */ autocorr[0] *= 1.0 + pnoise; /* Get inverse filter by Wiener-Levinson */ stoepf(nlag, autocorr, crosscorr, wiener, spiker); /* Convolve pefilter with trace - don't do zero multiplies */ { register int i; for (i = 0; i < nt; ++i) { register int j; register int n = MIN(i, imaxlag); register float sum = intrace.data[i]; for (j = iminlag; j <= n; ++j) sum -= wiener[j-iminlag] * intrace.data[i-j]; outtrace.data[i] = sum; } } /* Output filtered trace */ memcpy((char*)&outtrace, (char*)&intrace, HDRBYTES); puttr(&outtrace); /* Show pefilter and/or spiker on request */ if (showwiener) { register int i; warn("Wiener filter, trace: %d", itr); for (i = 0; i < imaxlag; ++i) fprintf(stderr, "%10g%c", wiener[i], (i%6==5 || i==nlag-1) ? '\n' : ' '); } if (showspiker) { register int i; warn("spiking decon filter, trace: %d", itr); for (i = 0; i < nlag; ++i) fprintf(stderr, "%10g%c", spiker[i], (i%6==5 || i==nlag-1) ? '\n' : ' '); } } while (gettr(&intrace)); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int nt; /* number of points on trace */ float dt; /* time sample interval (sec) */ float *shaper; /* shaping filter coefficients */ float *spiker; /* spiking decon filter (not used) */ float *w; /* input wavelet */ int nw; /* length of input wavelet in samples */ float *d; /* desired output wavelet */ int nd; /* length of desired wavelet in samples */ int nshape; /* length of shaping filter in samples */ float pnoise; /* pef additive noise level */ float *crosscorr; /* right hand side of Wiener eqs */ float *autocorr; /* vector of autocorrelations */ int showshaper; /* flag to display shaping filter */ float f_zero=0.0; /* zero valued item for comparison */ cwp_String wfile=""; /* input wavelet file name */ cwp_String dfile=""; /* desired output wavelet file name */ FILE *wfp; /* input wavelet file pointer */ FILE *dfp; /* desired wavelet file pointer */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if (!gettr(&intrace)) err("can't get first trace"); nt = intrace.ns; dt = intrace.dt/1000000.0; if (!dt) MUSTGETPARFLOAT ("dt", &dt); /* Get parameters */ if (!getparint("showshaper", &showshaper)) showshaper = 0; if (!getparint("nshape", &nshape)) nshape = nt; if (!getparfloat("pnoise", &pnoise)) pnoise = PNOISE; /* Open dfile and wfile if they have been getparred */ getparstring("dfile",&dfile); getparstring("wfile",&wfile); if ((*dfile=='\0')) { /* if no dfile, then get from command line */ if (!(nd = countparval("d"))) err("must specify d= desired wavelet"); d = ealloc1float(nd); getparfloat("d", d); } else { /* read from dfile */ if((dfp=fopen(dfile,"r"))==NULL) err("cannot open dfile=%s\n",dfile); if (!fgettr(dfp,&dtr)) err("can't get input wavelet"); nd = (int) dtr.ns; d = ealloc1float(nd); memcpy((void *) d, (const void *) dtr.data, nd*FSIZE); } if ((*wfile=='\0')) { /* then get w from command line */ if (!(nw = countparval("w"))) err("must specify w= desired wavelet"); w = ealloc1float(nw); getparfloat("w", w); } else { /* read from wfile */ if((wfp=fopen(wfile,"r"))==NULL) err("cannot open wfile=%s\n",wfile); if (!fgettr(wfp,&wtr)) err("can't get desired output wavelet"); nw = (int) wtr.ns; w = ealloc1float(nw); memcpy((void *) w, (const void *) wtr.data, nw*FSIZE); } /* Get shaping filter by Wiener-Levinson */ shaper = ealloc1float(nshape); spiker = ealloc1float(nshape); /* not used */ crosscorr = ealloc1float(nshape); autocorr = ealloc1float(nshape); xcor(nw, 0, w, nw, 0, w, nshape, 0, autocorr); /* for matrix */ xcor(nw, 0, w, nd, 0, d, nshape, 0, crosscorr); /* right hand side */ if (CLOSETO(autocorr[0],f_zero)) err("can't shape with zero wavelet"); autocorr[0] *= (1.0 + pnoise); /* whiten */ stoepf(nshape, autocorr, crosscorr, shaper, spiker); /* Show shaper on request */ if (showshaper) { register int i; warn("Shaping filter:"); for (i = 0; i < nshape; ++i) fprintf(stderr, "%10g%c", shaper[i], (i%6==5 || i==nshape-1) ? '\n' : ' '); } /* Main loop over traces */ do { /* Center and convolve shaping filter with trace */ conv(nshape, (nw-nd)/2, shaper, nt, 0, intrace.data, nt, 0, outtrace.data); /* Output filtered trace */ memcpy( (void *) &outtrace, (const void *) &intrace, HDRBYTES); puttr(&outtrace); } while (gettr(&intrace)); return(CWP_Exit()); }