TS++ library: time series library

◆ resample()

ts::TDsfftimeseries ts::ipo::resample ( const Interpolator ip,
const libtime::TAbsoluteTime &  first,
const libtime::TRelativeTime &  dt,
const int &  n,
const bool &  shrink = false 
)

resample a time series

function to resample data

This function provides resampling on the base of a reference to an instance of an interpolator class (containing the input time series) and a definition of sampling in terms of the time of the first sample, a sampling interval and the desired number of samples.

Optionally this function adjusts the time window for which resampling is done to a time span inside the time window for which input data is available. In this case the time of the first sample is adjusted such that it is offset from the originally requested time by an integer number of sampling intervals.

If the option shrink is not used, exception ipo::ExceptionTimeWindowOutside will be thrown if not all of the requested sample values are within the time window of the original series.

Parameters
ipreference to a waveform interpolator
firsttime of first sample in new time series
dtsampling interval of new time series
nnumber of samples in new time series
shrinkif true, shrink time window such, that input data is available for the whole window
Returns
resampled time series with time header fields adjusted

Definition at line 72 of file ipo.cc.

References ts::ipo::Interpolator::debug(), ts::seife::first(), ts::ipo::Interpolator::header(), TSXX_debug, and TSXX_Xassert.

77  {
79  typedef Ttimeseries::Theader Theader;
81  using libtime::TAbsoluteTime;
82  using libtime::TRelativeTime;
83  using libtime::TRange;
84  Theader hd=ip.header();
85  TAbsoluteTime old_first=hd.date;
86  TAbsoluteTime old_last=sff::wid2lastsample(hd);
87  TAbsoluteTime new_first=first;
88  TAbsoluteTime new_last=new_first+(n-1)*dt;
89  int nsamples=n;
90  // if requested, shrink time window to available data
91  if (shrink)
92  {
93  if (old_first > new_first)
94  {
95  int noff=(old_first-new_first)/dt;
96  new_first += (dt*noff);
97  nsamples -= noff;
98  while (new_first < old_first) { new_first += dt; nsamples--; }
99  }
100  if (old_last < new_last)
101  {
102  int noff=(new_last-old_last)/dt;
103  new_last -= (dt*noff);
104  nsamples -= noff;
105  while (new_last > old_last) { new_last -= dt; nsamples--; }
106  }
107  TSXX_Xassert(nsamples > 0,
108  "new time window is empty",
109  ExceptionTimeWindowEmpty);
110  }
111  TSXX_debug(ip.debug(), "resample",
112  "window covered by input series:\n "
113  << old_first.timestring() << " - "
114  << old_last.timestring());
115  TSXX_debug(ip.debug(), "resample",
116  "window requested for output series:\n "
117  << new_first.timestring() << " - "
118  << new_last.timestring());
119  TRange inputwindow(old_first, old_last);
120  TRange outputwindow(new_first, new_last);
121  TSXX_Xassert((inputwindow.includes(outputwindow)),
122  "new time span is outside time series",
123  ExceptionTimeWindowOutside);
124  Ttimeseries retval=Ttimeseries(Tseries(nsamples), hd);
125  retval.header.date=new_first;
126  retval.header.nsamples=nsamples;
127  retval.header.dt=libtime::time2double(dt);
128  TAbsoluteTime it=new_first;
129  for (int i=0; i<nsamples; ++i) { retval(i)=ip(it); it += dt; }
130  return(retval);
131  } // ts::TDsfftimeseries resample(...)
void first(const Tseries &s)
Definition: seifexx.cc:117
#define TSXX_debug(C, N, M)
produce debug output
Definition: debug.h:51
ts::TDtimeseries Ttimeseries
use double precision time series
Definition: filterbase.h:56
Ttimeseries::Tseries Tseries
Definition: filter.cc:84
#define TSXX_Xassert(C, M, E)
Check an assertion and report by throwing an exception.
Definition: error.h:118
Here is the call graph for this function: