Resample.h

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton, Teviet Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /************************************* <lalVerbatim file="ResampleHV">
00021 Author: Creighton, T. D.
00022 Revision: $Id: Resample.h,v 1.6 2007/06/08 14:41:50 bema Exp $
00023 **************************************************** </lalVerbatim> */
00024 
00025 /********************************************************** <lalLaTeX>
00026 
00027 \section{Header \texttt{Resample.h}}
00028 \label{s:Resample.h}
00029 
00030 Provides routines for resampling time series according to a new
00031 canonical time coordinate.
00032 
00033 \subsection*{Synopsis}
00034 \begin{verbatim}
00035 #include <lal/Resample.h>
00036 \end{verbatim}
00037 
00038 \noindent One of the crucial problems in searching for
00039 constant-frequency astrophysical signals is removing the effects of
00040 Doppler modulation due to the Earth's motion.  This is normally
00041 accomplished by constructing a canonical time coordinate $\tau$ of an
00042 inertial frame (i.e.\ the \emph{barycentred time}), and
00043 decimating/resampling the data at fixed intervals in $\tau$.  The
00044 reconstructed $\tau$ depends on the direction to the source relative
00045 to the Earth's motion; in addition, slow intrinsic parameterized
00046 modulations in the source frequency can also be corrected by this
00047 coordinate transformation.
00048 
00049 Most of the routines in this module assume that $\tau$ can be
00050 piecewise expanded as a Taylor series in $t$.  That is, one defines a
00051 set of fitting \emph{regions} $T_i=[t_{\mathrm{bound}(i-1)},
00052 t_{\mathrm{bound}(i)}]$, and a set of fitting \emph{points}
00053 $t_{(i)}\in T_i$.  In each region one then writes:
00054 \begin{equation}
00055 \label{eq:tau}
00056 \tau(t) = \sum_{k=0} \frac{1}{k!}c_{k(i)}(t-t_{(i)})^k \; .
00057 \end{equation}
00058 Since one is normally interested in tracking the difference
00059 $\tau(t)-t$, one can also write the expansion as:
00060 \begin{equation}
00061 \label{eq:delta-tau}
00062 \tau(t)-t = \sum_{k=0} a_{k(i)}(t-t_{(i)})^k \; ,
00063 \end{equation}
00064 where
00065 \begin{eqnarray}
00066 a_{0(i)} & = & c_{0(i)}-t_{(i)}           \; , \nonumber\\
00067 a_{1(i)} & = & c_{1(i)}-1                 \; , \nonumber\\
00068 a_{k(i)} & = & c_{k(i)}/k! \; , \; k\geq2 \; . \nonumber
00069 \label{eq:a_c}
00070 \end{eqnarray}
00071 These are the polynomial coefficients normally assumed in the modules
00072 under this header.
00073 
00074 The procedure for resampling according to $\tau$ is normally combined
00075 with \emph{decimating} the time series.  That is, one takes a time
00076 series sampled at constant intervals $\Delta t$ in $t$, and samples it
00077 at constant intervals $d\Delta t$ in $\tau$, where the
00078 \emph{decimation factor} $d$ is normally taken to be an integer
00079 $\geq1$.  When $\tau$ and $t$ are drifting out of phase relatively
00080 slowly, this means that most of the time every $d^\mathrm{th}$ sample
00081 in the original time series becomes the next sample in the decimated
00082 time series.  However, when $\tau$ and $t$ drift out of synch by an
00083 amount $\pm\Delta t$, one can force the decimated time series to track
00084 $\tau$ (rather than $t$) by sampling the $d\pm1^\mathrm{th}$ next
00085 datum (rather than the $d^\mathrm{th}$).  If the drift is sufficiently
00086 rapid or $d$ is sufficiently large, one may be forced to choose the
00087 point $d\pm2$, $d\pm3$, etc.; the size of this adjustment is called
00088 the correction \emph{shift}.  The number of (resampled) time intervals
00089 between one correction point and the next is called the correction
00090 \emph{interval}.
00091 
00092 Unless otherwise specified, all time variables and parameters in the
00093 functions under this header can be assumed to measure the detector
00094 time coordinate $t$.  Canonical times are specified by giving the
00095 difference $\tau-t$.
00096 
00097 \paragraph{Caveat emptor:} The inclusion of this header and its
00098 associated modules into LAL is provisional at this time.  The routines
00099 and the test code appear to work, but a later standalone code,
00100 operating on much larger datasets, appeared to encounter a memory
00101 leak.  I have not yet determined whether this leak was in the
00102 standalone code or in these LAL routines.
00103 
00104 ******************************************************* </lalLaTeX> */
00105 
00106 #ifndef _RESAMPLE_H
00107 #define _RESAMPLE_H
00108 
00109 #include <lal/LALStdlib.h>
00110 
00111 #ifdef __cplusplus
00112 extern "C" {
00113 #endif
00114 
00115 NRCSID(RESAMPLEH,"$Id: Resample.h,v 1.6 2007/06/08 14:41:50 bema Exp $");
00116 
00117 /********************************************************** <lalLaTeX>
00118 \subsection*{Error conditions}
00119 ****************************************** </lalLaTeX><lalErrTable> */
00120 #define RESAMPLEH_ENUL    1
00121 #define RESAMPLEH_EOUT    2
00122 #define RESAMPLEH_EMEM    3
00123 #define RESAMPLEH_EDTPOS  4
00124 #define RESAMPLEH_ELENGTH 5
00125 #define RESAMPLEH_ETIME   6
00126 
00127 #define RESAMPLEH_MSGENUL    "Unexpected null pointer in arguments"
00128 #define RESAMPLEH_MSGEOUT    "Output handle points to a non-null pointer"
00129 #define RESAMPLEH_MSGEMEM    "Memory allocation error"
00130 #define RESAMPLEH_MSGELENGTH "Vector lengths in polyco structure don't argree"
00131 #define RESAMPLEH_MSGEDTPOS  "Sampling interval is not positive"
00132 #define RESAMPLEH_MSGETIME   "Requested output time span extends beyond range of validity of input"
00133 /*************************************************** </lalErrTable> */
00134 
00135 /********************************************************** <lalLaTeX>
00136 \subsection*{Types}
00137 
00138 \subsubsection*{Structure \texttt{ResampleRules}}
00139 \idx[Type]{ResampleRules}
00140 
00141 \noindent This structure stores the rules for taking a time series
00142 $t$, sampled at constant intervals $\Delta t$, and resampling it at
00143 constant intervals $d\Delta t$ in the canonical time coordinate $\tau$,
00144 as described above.  The fields in this structure are as follows:
00145 
00146 \begin{description}
00147 \item[\texttt{LIGOTimeGPS start}] The initial time for which the rules
00148         apply.
00149 
00150 \item[\texttt{LIGOTimeGPS stop}] The final time for which the rules
00151         apply.
00152 
00153 \item[\texttt{INT4 length}] The number of correction points, i.e.\
00154         points where the resampling interval is adjusted from $d\Delta
00155         t$ to $(d\pm n)\Delta t$.
00156 
00157 \item[\texttt{INT4 *interval}] An array giving the number of resampled
00158         time intervals between correction points.
00159 
00160 \item[\texttt{INT2 *shift}] An array giving the size of the correction
00161         shift (i.e.\ the number $n$ above) at each correction point.
00162 
00163 \item[\texttt{INT4 decimate}] The decimation factor $d$.
00164 
00165 \item[\texttt{REAL8 deltaT}] The sampling interval before decimation,
00166         in seconds.
00167 
00168 \item[\texttt{REAL8 startDiff}] The difference $\tau-t$ at the time
00169         \verb@start@, in seconds.
00170 
00171 \item[\texttt{REAL8 stopDiff}] The difference $\tau-t$ at the time
00172         \verb@stop@, in seconds.
00173 \end{description}
00174 
00175 ******************************************************* </lalLaTeX> */
00176 
00177 typedef struct tagResampleRules{
00178   LIGOTimeGPS start; /* Detector time at start of resample rules. */
00179   LIGOTimeGPS stop;  /* Last time for which resample rules apply. */
00180   INT4 length;       /* Size of the following two arrays. */
00181   INT4 *interval;    /* Number of samples to the next shift point. */
00182   INT2 *shift;       /* Size of shift (usually +/- 1). */
00183   INT4 decimate;     /* Decimation factor. */
00184   REAL8 deltaT;      /* Sampling rate of the unresampled data. */
00185   REAL8 startDiff;   /* Offset between tau and t at the start. */
00186   REAL8 stopDiff;    /* Offset between tau and t at the end. */
00187 } ResampleRules;
00188 
00189 
00190 /********************************************************** <lalLaTeX>
00191 \subsubsection*{Structure \texttt{PolycoStruc}}
00192 \idx[Type]{PolycoStruc}
00193 
00194 \noindent This structure stores the parameters of the piecewise
00195 polynomial fit of $\tau-t$ as a function of $t$.  See
00196 Eq.~\ref{eq:delta-tau} for notation.  The fields of this structure
00197 are:
00198 
00199 \begin{description}
00200 \item[\texttt{REAL4 ra}] The right ascension angle of the source, in
00201         \emph{radians} in the range $[0,2\pi)$.
00202 
00203 \item[\texttt{REAL4 dec}] The declination angle of the source, in
00204         \emph{radians} in the range $[-\pi/2,pi/2]$.
00205 
00206 \item[\texttt{REAL4Vector *spindown}] A vector
00207         $\vec\lambda=(\lambda_0,\ldots,\lambda_{n-1})$ of parameters
00208         describing a slow intrisic frequency drift $f=f(t)$ of the
00209         source: $\lambda_k=f^{-1}d^{k+1}f/dt^{k+1}$ at the time given
00210         by \verb@start@ (below).
00211 
00212 \item[\texttt{LIGOTimeGPS start}] The initial time over which the
00213         polynomial fit applies.
00214 
00215 \item[\texttt{REAL4Sequence *tBound}] The sequence of times
00216         $t_{\mathrm{bound}(i)}$ defining the endpoints of the fitting
00217         regions, given in seconds after the time \verb@start@.  The
00218         first fitting region $i=0$ runs from \verb@start@ to
00219         \verb@start@+$t_{\mathrm{bound}(0)}$, the next from there to
00220         \verb@start@+$t_{\mathrm{bound}(1)}$, and so on.
00221 
00222 \item[\texttt{REAL4Sequence *t0}] The sequence of times $t_{(i)}$ in
00223         each fitting region at which the polynomial fits are computed,
00224         given in seconds after the time \verb@start@.
00225 
00226 \item[\texttt{REAL4VectorSequence *polyco}] A sequence of vectors
00227         $\vec a_{(i)}=(a_{0(i)},a_{1(i)},\ldots)$ giving the
00228         coefficients of the polynomial fit at each time $t_{(i)}$.
00229         Each element $a_{k(i)}$ has units of $\mathrm{s}^{1-k}$.
00230 \end{description}
00231 
00232 ******************************************************* </lalLaTeX> */
00233 
00234 typedef struct tagPolycoStruc{
00235   REAL4 ra;  /* Right ascension of source */
00236   REAL4 dec; /* Declination of source */
00237   REAL4Vector *spindown; /* Spindown terms: f0^{-1} d^n f/(dt)^n */
00238   LIGOTimeGPS start;  /* Start (reference) time of the polyco fit */
00239   REAL4Sequence *tBound; /* End times of each fitting region */
00240   REAL4Sequence *t0;     /* Fitting times in each region */
00241   REAL4VectorSequence *polyco; /* Polynomial fitting parameters for
00242                                   each fitting region */
00243 } PolycoStruc;
00244 
00245 
00246 /********************************************************** <lalLaTeX>
00247 \subsubsection*{Structure \texttt{ResampleParamStruc}}
00248 \idx[Type]{ResampleParamStruc}
00249 
00250 \noindent This structure stores extra parameters required to construct
00251 a \verb@ResampleRules@ object from a \verb@PolycoStruc@ object.  The
00252 fields of this structure are:
00253 
00254 \begin{description}
00255 \item[\texttt{LIGOTimeGPS start}] The initial time for which the
00256         resample rules will apply.
00257 
00258 \item[\texttt{LIGOTimeGPS stop}] The final time for which the resample
00259         rules will apply.
00260 
00261 \item[\texttt{REAL8 deltaT}] The sampling interval before decimation,
00262         in seconds.
00263 
00264 \item[\texttt{INT4 decimate}] The decimation factor.
00265 \end{description}
00266 
00267 ******************************************************* </lalLaTeX> */
00268 
00269 typedef struct tagResampleParamStruc{
00270   LIGOTimeGPS start;    /* Initial time for which the rules apply. */
00271   LIGOTimeGPS stop;     /* Final time for which the rules apply. */
00272   REAL8       deltaT;   /* Base (oversampled) sampling interval. */
00273   INT4        decimate; /* Decimation factor. */
00274 } ResampleParamStruc;
00275 
00276 
00277 /* <lalLaTeX>
00278 \vfill{\footnotesize\input{ResampleHV}}
00279 </lalLaTeX> */
00280 
00281 
00282 /* Function prototypes. */
00283 
00284 /* <lalLaTeX>
00285 \newpage\input{CreateResampleRulesC}
00286 </lalLaTeX> */
00287 void
00288 LALCreateResampleRules( LALStatus          *status,
00289                         ResampleRules      **rules,
00290                         PolycoStruc        *polyco,
00291                         ResampleParamStruc *params );
00292 
00293 /* <lalLaTeX>
00294 \newpage\input{DestroyResampleRulesC}
00295 </lalLaTeX> */
00296 void
00297 LALDestroyResampleRules( LALStatus     *status,
00298                          ResampleRules **rules );
00299 
00300 /* <lalLaTeX>
00301 \newpage\input{ApplyResampleRulesC}
00302 </lalLaTeX> */
00303 void
00304 LALApplyResampleRules( LALStatus       *status,
00305                        REAL4TimeSeries *output,
00306                        REAL4TimeSeries *input,
00307                        ResampleRules   *rules );
00308 
00309 /* Patrick: I don't know if you want ApplyResampleRules() to be a
00310    lower-level routine that operates on vectors, or whether time
00311    series are okay. */
00312 
00313 /* <lalLaTeX>
00314 \newpage\input{PolycoToTimingDifferenceC}
00315 </lalLaTeX> */
00316 void
00317 LALPolycoToTimingDifference( LALStatus       *status,
00318                              REAL4TimeSeries *difference,
00319                              PolycoStruc     *polyco );
00320 
00321 /* <lalLaTeX>
00322 \newpage\input{RulesToTimingDifferenceC}
00323 </lalLaTeX> */
00324 void
00325 LALRulesToTimingDifference( LALStatus       *status,
00326                             REAL4TimeSeries *difference,
00327                             ResampleRules   *rules );
00328 
00329 /* <lalLaTeX>
00330 \newpage\input{ResampleTestC}
00331 </lalLaTeX> */
00332 
00333 #ifdef __cplusplus
00334 }
00335 #endif
00336 
00337 #endif /* _RESAMPLE_H */

Generated on Tue Oct 7 02:40:21 2008 for LAL by  doxygen 1.5.2