#include "resample.h" Time Series& ResampleTimeSeries(TimeSeries& ts, ResamplingDefinitions& rd, double dtout, bool trim); class ResamplingDefinitions { public: map<Interval,ResampleOperator,IntervalCompare> decset; ResamplingDefinitions(Pf *pf); };
Resampling modern seismic data to a common sample rate is often needed in data processing to simplify many algorithms. This set of functions provide a very general way to accomplish this in the framework of the seispp library. The main procedure, ResampleTimeSeries, will both upsample and downsample to integer or noninteger multiples of an original sample rate. What exactly is done is driven by the ResamplingDefinitions object. The ResamplingDefinitions contains the recipes used to define how resampling is to be done for different sample rates. The interface selects the recipe for handling input automatically based on the original sample rate of the data.
The constructor for a ResamplingDefinitions object is driven by a parameter file description (see pf(3)). The pf object to be passed to the constructor would normally be built itself using pfread as part of a program's initialization. The format of the parameter file assumed to be used to construct pf is fairly complex and is described in detail in dbresample(1), which is an application built around this function. As usual for this kind of thing the best advice is to edit the default dbresample.pf file to set this up rather than start from scratch.
Downsampling always requires a decimator unless the degree of downsampling is small (currently 10%). In downsampling a decimation FIR filter is used and the output is constructed as dot products of this FIR filter skipping through the data at the integral decimation factor defined for that filter (see description of the parameter file format in dbresample(1)). The FIR filters are assumed to be symmetric zero phase filters with the zero lag point at the center of the vector of coefficients. This is the norm for most FIR filters used in data loggers that would be the normal choice for defining decimators for this function.
Upsampling is defined by a decimation stage with a decimation factor smaller than unity. Upsamping is accomplished by simple linear interpolation between data points.
The ResampleTimeSeries function returns a TimeSeries(3) object resampled to the target sample interval dtout. The trim variable is a switch to control how the function handles the transients at the ends of the data that are the norm for a FIR filter. When set true, the edges of the data are trimmed to remove all transients. When false the edges may contain filter startup transients at the edges due to incomplete coverage. The trim switch has no effect when upsampling since no antialiasing filter is required in that case.
See dbresample(1) for a sample that could be used to define a resampling set.
This is a template for a function that would use this function.
... other parts of program ... string pfname("mypf"); Pf *pf; //the oddities here are the standard C++ interface to C function pfread(const_cast<char *>(pffile.c_str()),&pf); ResamplingDefinitions rd(pf); ... TimeSeries ts(db,mdl,am); // see TimeSeries(3) tsnew = ResampleTimeSeries(ts,rd,0.1,true); // resample to 10 sps dbsave(tsnew,db,"wfdisc",mdl,am); ...
The Resampling_Defininitions constructor and the ResampleTimeSeries function will throw a SeisppError(3) in the event of a serious problem. In both cases the result is null. For the constructor one would normally abort. For data processing, handling failure of the resampling function is application dependent.
BasicTimeSeries(3), TimeSeries(3), dbresample(1), SeisppError(3), http://geology.indiana.edu/pavlis/software/seispp/html/index.html
It might be nice to allow something other than a FIR filter for the antialiasing definitions in decimation, but this has not been implemented.
Gary L. Pavlis Indiana University pavlis@indiana.edu