LAL  7.5.0.1-bede9b2
TriggerInterpolation.h
Go to the documentation of this file.
1 /*
2  * Interpolation of time and SNR of triggers
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with with program; see the file COPYING. If not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  *
19  * Copyright (C) 2012 Leo Singer
20  */
21 
22 #include <lal/LALAtomicDatatypes.h>
23 
24 #ifndef _TRIGGERINTERPOLATION_H
25 #define _TRIGGERINTERPOLATION_H
26 
27 #if defined(__cplusplus)
28 extern "C" {
29 #elif 0
30 } /* so that editors will match preceding brace */
31 #endif
32 
33 
34 /**
35  * \defgroup TriggerInterpolation Trigger Interpolation
36  * \ingroup lal_tools
37  *
38  * This module implements several algorithms for performing sub-sample
39  * interpolation of peaks in the output of a matched filter. The interface for
40  * each algorithm is the same. To illustrate, here is a description of the
41  * interface for the 'Lanczos' algorithm.
42  *
43  * There is an opaque data type called \c LanczosTriggerInterpolant that holds
44  * workspaces for performing the interpolation. To create one, call the
45  * function \c XLALCreateLanczosTriggerInterpolant as follows:
46  *
47  * \code{.c}
48  * LanczosTriggerInterpolant *interp = XLALCreateLanczosTriggerInterpolant(5);
49  * \endcode
50  *
51  * The '5' is the interpolation window. In this example, the interpolation will
52  * take into account a given sample, the 5 samples before, and the 5 samples
53  * after, for a total of 11 samples.
54  *
55  * To apply the interpolant to a time series, call
56  * \c XLALApplyLanczosTriggerInterpolant. It is requried that |y[0]| >= |y[i]|
57  * for all i from -\c window to +\c window. Suppose that you have a complex
58  * array \c y:
59  *
60  * \code{.c}
61  * COMPLEX16 y[] = {...};
62  * \endcode
63  *
64  * and suppose that the maximum of |y[i]| occurs at i = 8.
65  * To interpolate the time and complex value at which the maximum occurs, do
66  * the following:
67  *
68  * \code{.c}
69  * double tmax;
70  * COMPLEX16 ymax;
71  * int result = XLALApplyLanczosTriggerInterpolant(interp, &tmax, &ymax, &y[8]);
72  * \endcode
73  *
74  * Upon success, the return value of \c XLALApplyLanczosTriggerInterpolant is
75  * zero, the interpolated index of the maximum sample is 8 + \c *tmax, and the
76  * interpolated value is in \c ymax. Upon failure, the return value is nonzero
77  * and neither \c *tmax nor \c *ymax are modified.
78  *
79  * When you are done, release all of the workspace resources associated with
80  * the interpolant with:
81  *
82  * \code{.c}
83  * XLALDestroyLanczosTriggerInterpolant(interp);
84  * \endcode
85  *
86  * \{
87  */
88 
89 
90 /**
91  * Catmull-Rom cubic spline interpolation
92  *
93  * Find the Catmull-Rom cubic spline interpolants that pass through the real and
94  * imaginary parts of the data. Find the interpolated time by solving for the
95  * maximum of the sum of the squares of the two spline interpolants.
96  *
97  * \warning It is an error to request a Catmull-Rom workspace with a window size
98  * not equal to 2.
99  *
100  * \defgroup CubicSplineTriggerInterpolant Cubic Spline Trigger Interpolant
101  * \{
102  */
103 
105 typedef struct tagCubicSplineTriggerInterpolant CubicSplineTriggerInterpolant;
106 
107 /**
108  * Constructor.
109  *
110  * Allocate a new interpolation workspace and return a pointer to
111  * it, or NULL if an error occurs.
112  *
113  * \warning It is an error to request a Catmull-Rom workspace with a window size
114  * not equal to 2.
115  */
116 CubicSplineTriggerInterpolant *XLALCreateCubicSplineTriggerInterpolant(unsigned int window);
117 
118 /**
119  * Destructor.
120  *
121  * If the workspace is non-NULL, deallocate it.
122  */
123 void XLALDestroyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *);
124 
125 /**
126  * Perform interpolation using the allocated workspace.
127  *
128  * Perform interpolation around the matched-filter output data pointed to by
129  * \c y. There should exist \c window samples before and \c window samples
130  * after this pointer.
131  *
132  * On success, set \c *tmax to the interpolated time, \c *ymax to the
133  * complex interpolated signal, and return 0. On failure, return a non-zero GSL
134  * error code.
135  */
137  CubicSplineTriggerInterpolant *interp,
138  double *tmax,
139  COMPLEX16 *ymax,
140  const COMPLEX16 *y);
141 
143  CubicSplineTriggerInterpolant *interp,
144  double *tmax,
145  COMPLEX8 *ymax,
146  const COMPLEX8 *y);
147 
149  CubicSplineTriggerInterpolant *interp,
150  double *tmax,
151  REAL8 *ymax,
152  const REAL8 *y);
153 
155  CubicSplineTriggerInterpolant *interp,
156  double *tmax,
157  REAL4 *ymax,
158  const REAL4 *y);
159 
160 /** \} */
161 
162 
163 /**
164  * Lanczos interpolation
165  *
166  * Convolve the data with a Lanczos reconstruction kernel and find the maximum
167  * of the absolute value using a one-dimensional numerical method.
168  *
169  * \defgroup LanczosTriggerInterpolant Lanczos Trigger Interpolant
170  * \{
171  */
172 
174 typedef struct tagLanczosTriggerInterpolant LanczosTriggerInterpolant;
175 
176 /**
177  * Constructor.
178  *
179  * Allocate a new interpolation workspace and return a pointer to
180  * it, or NULL if an error occurs.
181  */
182 LanczosTriggerInterpolant *XLALCreateLanczosTriggerInterpolant(unsigned int window);
183 
184 /**
185  * Destructor.
186  *
187  * If the workspace is non-NULL, deallocate it.
188  */
189 void XLALDestroyLanczosTriggerInterpolant(LanczosTriggerInterpolant *);
190 
191 /**
192  * Perform interpolation using the allocated workspace.
193  *
194  * Perform interpolation around the matched-filter output data pointed to by
195  * \c y. There should exist \c window samples before and \c window samples
196  * after this pointer.
197  *
198  * On success, set \c *tmax to the interpolated time, \c *ymax to the
199  * complex interpolated signal, and return 0. On failure, return a non-zero GSL
200  * error code.
201  */
203  LanczosTriggerInterpolant *interp,
204  double *tmax,
205  COMPLEX16 *ymax,
206  const COMPLEX16 *y);
207 
209  LanczosTriggerInterpolant *interp,
210  double *tmax,
211  COMPLEX8 *ymax,
212  const COMPLEX8 *y);
213 
215  LanczosTriggerInterpolant *interp,
216  double *tmax,
217  REAL8 *ymax,
218  const REAL8 *y);
219 
221  LanczosTriggerInterpolant *interp,
222  double *tmax,
223  REAL4 *ymax,
224  const REAL4 *y);
225 
226 /** \} */
227 
228 
229 /**
230  * Nearest-neighbor interpolation
231  *
232  * Perform trivial, nearest-neighbor interpolation.
233  * Always sets <tt>*tmax = 0, *ymax = data[0]</tt>.
234  *
235  * \warning It is an error to request a nearest-neighbor workspace with a window
236  * size not equal to 0.
237  *
238  * \defgroup NearestNeighborTriggerInterpolant Nearest Neighbor Trigger Interpolant
239  * \{
240  */
241 
243 typedef struct tagNearestNeighborTriggerInterpolant NearestNeighborTriggerInterpolant;
244 
245 /**
246  * Constructor.
247  *
248  * Allocate a new interpolation workspace and return a pointer to
249  * it, or NULL if an error occurs.
250  *
251  * \warning It is an error to request a nearest-neighbor workspace with a window
252  * size not equal to 0.
253  */
254 NearestNeighborTriggerInterpolant *XLALCreateNearestNeighborTriggerInterpolant(unsigned int window);
255 
256 /**
257  * Destructor.
258  *
259  * If the workspace is non-NULL, deallocate it.
260  */
261 void XLALDestroyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *);
262 
263 /**
264  * Perform interpolation using the allocated workspace.
265  *
266  * Perform interpolation around the matched-filter output data pointed to by
267  * \c y. There should exist \c window samples before and \c window samples
268  * after this pointer.
269  *
270  * On success, set \c *tmax to the interpolated time, \c *ymax to the
271  * complex interpolated signal, and return 0. On failure, return a non-zero GSL
272  * error code.
273  */
275  NearestNeighborTriggerInterpolant *interp,
276  double *tmax,
277  COMPLEX16 *ymax,
278  const COMPLEX16 *y);
279 
281  NearestNeighborTriggerInterpolant *interp,
282  double *tmax,
283  COMPLEX8 *ymax,
284  const COMPLEX8 *y);
285 
287  NearestNeighborTriggerInterpolant *interp,
288  double *tmax,
289  REAL8 *ymax,
290  const REAL8 *y);
291 
293  NearestNeighborTriggerInterpolant *interp,
294  double *tmax,
295  REAL4 *ymax,
296  const REAL4 *y);
297 
298 /** \} */
299 
300 
301 /**
302  * Quadratic fit
303  *
304  * Fit a quadratic function to the absolute value of the data. Report the sample
305  * index of the vertex if the vertex is a maximum. Note that this is not
306  * actually an interpolant because it is not guaranteed to agree with the input
307  * data points, and that it always sets *ymax = data[0].
308  *
309  * \defgroup QuadraticFitTriggerInterpolant Quadratic Fit Trigger Interpolant
310  * \{
311  */
312 
314 typedef struct tagQuadraticFitTriggerInterpolant QuadraticFitTriggerInterpolant;
315 
316 /**
317  * Constructor.
318  *
319  * Allocate a new interpolation workspace and return a pointer to
320  * it, or NULL if an error occurs.
321  */
322 QuadraticFitTriggerInterpolant *XLALCreateQuadraticFitTriggerInterpolant(unsigned int window);
323 
324 /**
325  * Destructor.
326  *
327  * If the workspace is non-NULL, deallocate it.
328  */
329 void XLALDestroyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *);
330 
331 /**
332  * Perform interpolation using the allocated workspace.
333  *
334  * Perform interpolation around the matched-filter output data pointed to by
335  * \c y. There should exist \c window samples before and \c window samples
336  * after this pointer.
337  *
338  * On success, set \c *tmax to the interpolated time, \c *ymax to the
339  * complex interpolated signal, and return 0. On failure, return a non-zero GSL
340  * error code.
341  */
343  QuadraticFitTriggerInterpolant *interp,
344  double *tmax,
345  COMPLEX16 *ymax,
346  const COMPLEX16 *y);
347 
349  QuadraticFitTriggerInterpolant *interp,
350  double *tmax,
351  COMPLEX8 *ymax,
352  const COMPLEX8 *y);
353 
355  QuadraticFitTriggerInterpolant *interp,
356  double *tmax,
357  REAL8 *ymax,
358  const REAL8 *y);
359 
361  QuadraticFitTriggerInterpolant *interp,
362  double *tmax,
363  REAL4 *ymax,
364  const REAL4 *y);
365 
366 /** \} */
367 
368 
369 /** \} */
370 
371 
372 #if 0
373 { /* so that editors will match succeeding brace */
374 #elif defined(__cplusplus)
375 } /* extern "C" */
376 #endif
377 
378 #endif /* _TRIGGERINTERPOLATION_h */
int XLALCOMPLEX8ApplyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *interp, double *tmax, COMPLEX8 *ymax, const COMPLEX8 *y)
CubicSplineTriggerInterpolant * XLALCreateCubicSplineTriggerInterpolant(unsigned int window)
Constructor.
int XLALCOMPLEX16ApplyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *interp, double *tmax, COMPLEX16 *ymax, const COMPLEX16 *y)
Perform interpolation using the allocated workspace.
void XLALDestroyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *)
Destructor.
int XLALREAL4ApplyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *interp, double *tmax, REAL4 *ymax, const REAL4 *y)
int XLALREAL8ApplyCubicSplineTriggerInterpolant(CubicSplineTriggerInterpolant *interp, double *tmax, REAL8 *ymax, const REAL8 *y)
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
double REAL8
Double precision real floating-point number (8 bytes).
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
float REAL4
Single precision real floating-point number (4 bytes).
int XLALREAL8ApplyLanczosTriggerInterpolant(LanczosTriggerInterpolant *interp, double *tmax, REAL8 *ymax, const REAL8 *y)
void XLALDestroyLanczosTriggerInterpolant(LanczosTriggerInterpolant *)
Destructor.
int XLALREAL4ApplyLanczosTriggerInterpolant(LanczosTriggerInterpolant *interp, double *tmax, REAL4 *ymax, const REAL4 *y)
int XLALCOMPLEX16ApplyLanczosTriggerInterpolant(LanczosTriggerInterpolant *interp, double *tmax, COMPLEX16 *ymax, const COMPLEX16 *y)
Perform interpolation using the allocated workspace.
int XLALCOMPLEX8ApplyLanczosTriggerInterpolant(LanczosTriggerInterpolant *interp, double *tmax, COMPLEX8 *ymax, const COMPLEX8 *y)
LanczosTriggerInterpolant * XLALCreateLanczosTriggerInterpolant(unsigned int window)
Constructor.
NearestNeighborTriggerInterpolant * XLALCreateNearestNeighborTriggerInterpolant(unsigned int window)
Constructor.
int XLALREAL4ApplyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *interp, double *tmax, REAL4 *ymax, const REAL4 *y)
int XLALREAL8ApplyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *interp, double *tmax, REAL8 *ymax, const REAL8 *y)
int XLALCOMPLEX16ApplyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *interp, double *tmax, COMPLEX16 *ymax, const COMPLEX16 *y)
Perform interpolation using the allocated workspace.
int XLALCOMPLEX8ApplyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *interp, double *tmax, COMPLEX8 *ymax, const COMPLEX8 *y)
void XLALDestroyNearestNeighborTriggerInterpolant(NearestNeighborTriggerInterpolant *)
Destructor.
int XLALREAL8ApplyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *interp, double *tmax, REAL8 *ymax, const REAL8 *y)
int XLALCOMPLEX16ApplyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *interp, double *tmax, COMPLEX16 *ymax, const COMPLEX16 *y)
Perform interpolation using the allocated workspace.
int XLALCOMPLEX8ApplyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *interp, double *tmax, COMPLEX8 *ymax, const COMPLEX8 *y)
void XLALDestroyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *)
Destructor.
QuadraticFitTriggerInterpolant * XLALCreateQuadraticFitTriggerInterpolant(unsigned int window)
Constructor.
int XLALREAL4ApplyQuadraticFitTriggerInterpolant(QuadraticFitTriggerInterpolant *interp, double *tmax, REAL4 *ymax, const REAL4 *y)