LAL  7.5.0.1-08ee4f4
ResampleTimeSeries.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Duncan Brown, Jolien Creighton, Patrick Brady
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 
20 #include <math.h>
21 #include <lal/LALStdlib.h>
22 #include <lal/LALStdio.h>
23 #include <lal/AVFactories.h>
24 #include <lal/LALConstants.h>
25 #include <lal/IIRFilter.h>
26 #include <lal/BandPassTimeSeries.h>
27 #include <lal/ResampleTimeSeries.h>
28 
29 #if __GNUC__
30 #define UNUSED __attribute__ ((unused))
31 #else
32 #define UNUSED
33 #endif
34 
35 /**
36  * \defgroup ResampleTimeSeries_c Module ResampleTimeSeries.c
37  * \ingroup ResampleTimeSeries_h
38  *
39  * \author Brown, D. A., Brady, P. R., Charlton, P.
40  *
41  * \brief Downsamples a time series in place by an integer power of two.
42  *
43  * The routine LALResampleREAL4TimeSeries() provided functionality to
44  * downsample a time series in place by an integer factor which is a power of
45  * two. Upsampling, non-integer resampling and resampling by a factor which is
46  * not a power of two are currently unsupported. Attempts to use this methods
47  * will cause the function to abort with an error message.
48  *
49  * On entry the input time series \c ts should contain the data to be
50  * resampled, with the data, length and sample interbal of the time series
51  * populated. The parameter structure \c params should have the value of
52  * \c deltaT set to the desired value sample interval of the output data.
53  * The type of filter used to perform the low pass filter should be set in
54  * the parameter structure field \c filterType. The parameter structure
55  * field \c filterParams may be ignored at present. It is designed to
56  * allow user defined low pass filters and is not currently implemented. The
57  * resampling function will behave correctly even if this contains garbage on
58  * entry.
59  *
60  * On exit, the time series \c ts will contain the resampled time series.
61  * The length of the time series will be reduced by the resampling ratio and
62  * the sample interval will be set correctly.
63  *
64  * <em>There is no time shift in the output time series</em> when either the
65  * #defaultButterworth or #LDASfirLP low pass filter types are
66  * used. The timestamp of each point in the output time series is the same as
67  * the timestamp of the corresponding point in input time series.
68  *
69  * <em>There will be corrupted data at the start and end of the time series</em>
70  * when either the #defaultButterworth or #LDASfirLP low pass filter
71  * types are used. This is caused by corruption due to the low pass filter.
72  * Users should take care to truncate these points from the time series before
73  * using the output in subsequent filtering applications.
74  *
75  * ### Algorithm ###
76  *
77  * The input time series is first low passed to remove any power above the new
78  * Nyquist frequency. There are two available low pass filters:
79  * <ol>
80  * <li> #defaultButterworth: The input time series has a time domain low
81  * pass filter applied by the LALDButterworthREAL4TimeSeries() function
82  * from the tdfilters package. The filter order is \f$20\f$ and the attenuation is
83  * \f$0.1\f$ at the new Nyquist frequency. Since the butterworth filter is applied
84  * forwards and backwards there is no time delay or phase shift of the output
85  * data. The disadvantage of the butterworth filter is that since it is an IIR
86  * filter, it is not possible to determine the exact length of corrupted data at
87  * the start and end of the output time series. Care should be taked to avoid
88  * using these regions of data in subsequent filtering.</li>
89  *
90  * <li> #LDASfirLP: The input time series has a time domain low
91  * pass filter applied by the LALDIIRFilterREAL4Vector() function
92  * from the tdfilters package. This applies an FIR filter with coefficents
93  * generated by the LDAS <tt>firlp()</tt> dataconditioning API action. FIR
94  * coefficents are available for downsampling by a factor of 2, 4 or 8. An
95  * attempt to downsample by any other ratio will cause an error. The FIR
96  * coeffients are equivalent to the default <tt>resample()</tt> action in the
97  * dataconditioning API.
98  *
99  * The FIR filter causes the a time delay of 10 points in the output time series
100  * and corruption of the first \f$n\f$ points. \f$n\f$ is given by the order of the
101  * filter by \f$n = 2 \times 10 \times q\f$, where \f$q\f$ is the resampling ratio. To
102  * account for this, we do the following:
103  * <ol>
104  * <li> The first \f$n/2\f$ points of the time series are deleted.</li>
105  * <li> The whole time series is shifted \f$n/2\f$ points "left" to remove the
106  * time delay.</li>
107  * <li> The first and last \f$n/2\f$ points of the output time series are set to
108  * zero to make sure that the corrupted data contains sensible numbers and not
109  * garbage or \c Inf.</li>
110  * </ol>
111  * This means that there is no time delay in the output time series, but the
112  * first and last \f$n/2q\f$ points are set to zero. Care should be taked to avoid
113  * using these regions of data in subsequent filtering. If the debug level is
114  * set to LALWARNING, a message is printed reporting how many points at the
115  * start and end of time series are corrupted.
116  *
117  * The filter coefficents used were produced by LDAS-CIT running version 0.7.0 of
118  * LDAS. See the LDAS dataconditioning API documentation for more information.
119  * </ol>
120  *
121  */
122 /** @{ */
123 
124 /** \see See \ref ResampleTimeSeries_c for documentation */
126 {
127  const INT4 filterOrder = 20;
128  const REAL8 newNyquistAmplitude = 0.1;
129  REAL8 newNyquistFrequency;
130  UINT4 resampleFactor;
131  REAL4 *dataPtr = NULL;
132  UINT4 j;
133 
134  resampleFactor = floor( dt / series->deltaT + 0.5 );
135  newNyquistFrequency = 0.5 / dt;
136 
137  /* check that the resampling factor is valid */
138  if ( resampleFactor < 1 ||
139  fabs( dt - resampleFactor * series->deltaT ) > 1e-3 * series->deltaT )
141 
142  /* just return if no resampling is required */
143  if ( resampleFactor == 1 )
144  {
145  XLALPrintInfo( "XLAL Info - %s: No resampling required", __func__ );
146  return 0;
147  }
148 
149  /* check that we are resampling by a power of two */
150  if ( resampleFactor & (resampleFactor - 1) )
152 
153  if ( XLALLowPassREAL4TimeSeries( series, newNyquistFrequency,
154  newNyquistAmplitude, filterOrder ) < 0 )
156 
157  /* decimate the time series */
158  series->deltaT = dt;
159  series->data->length /= resampleFactor;
160  dataPtr = series->data->data;
161  for ( j = 0; j < series->data->length; ++j )
162  {
163  series->data->data[j] = *dataPtr;
164  dataPtr += resampleFactor;
165  }
166  series->data->data = LALRealloc( series->data->data,
167  series->data->length * sizeof( *series->data->data ) );
168 
169  return 0;
170 }
171 
172 /** \see See \ref ResampleTimeSeries_c for documentation */
174 {
175  const INT4 filterOrder = 20;
176  const REAL8 newNyquistAmplitude = 0.1;
177  REAL8 newNyquistFrequency;
178  UINT4 resampleFactor;
179  REAL8 *dataPtr = NULL;
180  UINT4 j;
181 
182  resampleFactor = floor( dt / series->deltaT + 0.5 );
183  newNyquistFrequency = 0.5 / dt;
184 
185  /* check that the resampling factor is valid */
186  if ( resampleFactor < 1 ||
187  fabs( dt - resampleFactor * series->deltaT ) > 1e-3 * series->deltaT )
189 
190  /* just return if no resampling is required */
191  if ( resampleFactor == 1 )
192  {
193  XLALPrintInfo( "XLAL Info - %s: No resampling required", __func__ );
194  return 0;
195  }
196 
197  /* check that we are resampling by a power of two */
198  if ( resampleFactor & (resampleFactor - 1) )
200 
201  if ( XLALLowPassREAL8TimeSeries( series, newNyquistFrequency,
202  newNyquistAmplitude, filterOrder ) < 0 )
204 
205  /* decimate the time series */
206  series->deltaT = dt;
207  series->data->length /= resampleFactor;
208  dataPtr = series->data->data;
209  for ( j = 0; j < series->data->length; ++j )
210  {
211  series->data->data[j] = *dataPtr;
212  dataPtr += resampleFactor;
213  }
214  series->data->data = LALRealloc( series->data->data,
215  series->data->length * sizeof( *series->data->data ) );
216 
217  return 0;
218 }
219 
220 
221 /**
222  * \deprecated Use XLALResampleREAL4TimeSeries() instead.
223  */
224 void
226  LALStatus *status,
227  REAL4TimeSeries *ts,
228  ResampleTSParams *params
229  )
230 {
231  UINT4 resampleFactor;
232  UINT4 j;
233  REAL4 *dataPtr = NULL;
234  /* INT8 startTimeNS = 0; */
235  CHAR warnMsg[256];
236  UINT4 corrupted = 0;
237  UINT4 filterOrder = 0;
238  REAL8Vector recursCoef;
239  REAL8Vector directCoef;
240  REAL8 recursd0 = -1;
241 
242  /* LDAS low pass FIR filter coefficents for resampling by 2, 4 and 8 */
243  /* thse were generated using the firlp action to get the FIR coeffs */
244  /* used by the resample action. FIR coeffs are provided for the default */
245  /* resample action that used a Kaiser window with beta = 5 and a filter */
246  /* order parameter n = 10. The order of the filter is 2 * n * resampRatio */
247  /* UINT4 ldasFilterOrderParameter = 10; */
248  UINT4 ldasByTwoOrder = 40;
249  UNUSED CHAR ldasByTwoMsg[] =
250  "LDAS FIR filter generated by firlp(0.5,40) using LDAS-CIT 0.7.0";
251  REAL8 ldasByTwo[] =
252  {
253  -7.1587345178999983e-19, -1.0514587726686521e-03, 1.8542385840153159e-18,
254  2.5089668121365313e-03, -3.4940298359108189e-18, -4.8948343392593557e-03,
255  5.6062660030794468e-18, 8.5565590024681924e-03, -8.0907458797357440e-18,
256  -1.3989973238439804e-02, 1.0780775955476128e-17, 2.2023120574050724e-02,
257  -1.3459232902020823e-17, -3.4340179881765416e-02, 1.5884076076327108e-17,
258  5.5288283911880384e-02, -1.7819618555760906e-17, -1.0093019739775573e-01,
259  1.9068667053692095e-17, 3.1670034568032440e-01, 5.0025873529805742e-01,
260  3.1670034568032440e-01, 1.9068667053692095e-17, -1.0093019739775573e-01,
261  -1.7819618555760906e-17, 5.5288283911880384e-02, 1.5884076076327108e-17,
262  -3.4340179881765416e-02, -1.3459232902020823e-17, 2.2023120574050724e-02,
263  1.0780775955476128e-17, -1.3989973238439804e-02, -8.0907458797357440e-18,
264  8.5565590024681924e-03, 5.6062660030794468e-18, -4.8948343392593557e-03,
265  -3.4940298359108189e-18, 2.5089668121365313e-03, 1.8542385840153159e-18,
266  -1.0514587726686521e-03, -7.1587345178999983e-19
267  };
268  UINT4 ldasByFourOrder = 80;
269  UNUSED CHAR ldasByFourMsg[] =
270  "LDAS FIR filter generated by firlp(0.25,80) using LDAS-CIT 0.7.0";
271  REAL8 ldasByFour[] =
272  {
273  -3.5797933214045194e-19, -2.8264939479410322e-04, -5.2579196542625766e-04,
274  -4.7541698372288916e-04, 9.2722964970291765e-19, 7.3162852724022317e-04,
275  1.2546327308624197e-03, 1.0630797667142953e-03, -1.7472228702023229e-18,
276  -1.4830129609431080e-03, -2.4477084927857239e-03, -2.0065313653173720e-03,
277  2.8034666665817767e-18, 2.6512725192001795e-03, 4.2787887572376141e-03,
278  3.4384897676469164e-03, -4.0458544723286438e-18, -4.3947913127916887e-03,
279  -6.9958192527421722e-03, -5.5549713919258352e-03, 5.3910296112353999e-18,
280  6.9667290898765182e-03, 1.1012871024947616e-02, 8.6988136875756853e-03,
281  -6.7304174967527627e-18, -1.0855771610536039e-02, -1.7172133746431371e-02,
282  -1.3606372767203865e-02, 7.9429834019598979e-18, 1.7243084699552668e-02,
283  2.7647432518244298e-02, 2.2320837133020830e-02, -8.9108698382911643e-18,
284  -3.0033587538646083e-02, -5.0471105705777050e-02, -4.3494435742894542e-02,
285  9.5354684261874058e-18, 7.4135704901104452e-02, 1.5836902171998732e-01,
286  2.2490814275257559e-01, 2.5015914127230293e-01, 2.2490814275257559e-01,
287  1.5836902171998732e-01, 7.4135704901104452e-02, 9.5354684261874058e-18,
288  -4.3494435742894542e-02, -5.0471105705777050e-02, -3.0033587538646083e-02,
289  -8.9108698382911643e-18, 2.2320837133020830e-02, 2.7647432518244298e-02,
290  1.7243084699552668e-02, 7.9429834019598979e-18, -1.3606372767203865e-02,
291  -1.7172133746431371e-02, -1.0855771610536039e-02, -6.7304174967527627e-18,
292  8.6988136875756853e-03, 1.1012871024947616e-02, 6.9667290898765182e-03,
293  5.3910296112353999e-18, -5.5549713919258352e-03, -6.9958192527421722e-03,
294  -4.3947913127916887e-03, -4.0458544723286438e-18, 3.4384897676469164e-03,
295  4.2787887572376141e-03, 2.6512725192001795e-03, 2.8034666665817767e-18,
296  -2.0065313653173720e-03, -2.4477084927857239e-03, -1.4830129609431080e-03,
297  -1.7472228702023229e-18, 1.0630797667142953e-03, 1.2546327308624197e-03,
298  7.3162852724022317e-04, 9.2722964970291765e-19, -4.7541698372288916e-04,
299  -5.2579196542625766e-04, -2.8264939479410322e-04, -3.5797933214045194e-19
300  };
301  UINT4 ldasByEightOrder = 160;
302  UNUSED CHAR ldasByEightMsg[] =
303  "LDAS FIR filter generated by firlp(0.125,160) using LDAS-CIT 0.7.0";
304  REAL8 ldasByEight[] =
305  {
306  -1.7899485045886187e-19, -6.5785565693739621e-05, -1.4132879082976897e-04,
307  -2.1264395052204678e-04, -2.6290359742617416e-04, -2.7550349276906565e-04,
308  -2.3771537702543715e-04, -1.4425544130102367e-04, 4.6362825333301403e-19,
309  1.7887185358663154e-04, 3.6582485933411455e-04, 5.2717915649190441e-04,
310  6.2733453548486414e-04, 6.3531304436406394e-04, 5.3155527927017054e-04,
311  3.1369007704874736e-04, -8.7363673902677791e-19, -3.7044471629615059e-04,
312  -7.4152795801187910e-04, -1.0475948732225806e-03, -1.2238896950094572e-03,
313  -1.2184233937642017e-03, -1.0032947419855074e-03, -5.8331646493291016e-04,
314  1.4017739341284856e-18, 6.7046275382674411e-04, 1.3256746563059471e-03,
315  1.8513153796509275e-03, 2.1394563456147114e-03, 2.1081914808740686e-03,
316  1.7192946812996687e-03, 9.9055884251036106e-04, -2.0229858297200544e-18,
317  -1.1198042255458091e-03, -2.1974593033835155e-03, -3.0470761300287886e-03,
318  -3.4980109424040981e-03, -3.4255709083983424e-03, -2.7775661451061263e-03,
319  -1.5917261396652274e-03, 2.6955928804956133e-18, 1.7824568219118389e-03,
320  3.4834654396768100e-03, 4.8124727581638303e-03, 5.5065950049312329e-03,
321  5.3772206622082304e-03, 4.3495328232139681e-03, 2.4876883619736412e-03,
322  -3.3653062207633390e-18, -2.7788423673236681e-03, -5.4280430225538204e-03,
323  -7.4993135801407406e-03, -8.5863155663860897e-03, -8.3949478976005458e-03,
324  -6.8033834361075291e-03, -3.9013002754523102e-03, 3.9716067341932858e-18,
325  4.3911559143580796e-03, 8.6217920704845935e-03, 1.1985707616989357e-02,
326  1.3824116659430464e-02, 1.3633243414968320e-02, 1.1160741825101029e-02,
327  6.4757499732487761e-03, -4.4555639696470439e-18, -7.5079556703908984e-03,
328  -1.5017228726807877e-02, -2.1332840162384223e-02, -2.5236283794044537e-02,
329  -2.5641711624359045e-02, -2.1747847773897343e-02, -1.3165154002435106e-02,
330  4.7678723092621354e-18, 1.7117561087684679e-02, 3.7068926111156336e-02,
331  5.8343464299929801e-02, 7.9186804418539564e-02, 9.7784206656366959e-02,
332  1.1245732857891018e-01, 1.2185045954177413e-01, 1.2508319353304170e-01,
333  1.2185045954177413e-01, 1.1245732857891018e-01, 9.7784206656366959e-02,
334  7.9186804418539564e-02, 5.8343464299929801e-02, 3.7068926111156336e-02,
335  1.7117561087684679e-02, 4.7678723092621354e-18, -1.3165154002435106e-02,
336  -2.1747847773897343e-02, -2.5641711624359045e-02, -2.5236283794044537e-02,
337  -2.1332840162384223e-02, -1.5017228726807877e-02, -7.5079556703908984e-03,
338  -4.4555639696470439e-18, 6.4757499732487761e-03, 1.1160741825101029e-02,
339  1.3633243414968320e-02, 1.3824116659430464e-02, 1.1985707616989357e-02,
340  8.6217920704845935e-03, 4.3911559143580796e-03, 3.9716067341932858e-18,
341  -3.9013002754523102e-03, -6.8033834361075291e-03, -8.3949478976005458e-03,
342  -8.5863155663860897e-03, -7.4993135801407406e-03, -5.4280430225538204e-03,
343  -2.7788423673236681e-03, -3.3653062207633390e-18, 2.4876883619736412e-03,
344  4.3495328232139681e-03, 5.3772206622082304e-03, 5.5065950049312329e-03,
345  4.8124727581638303e-03, 3.4834654396768100e-03, 1.7824568219118389e-03,
346  2.6955928804956133e-18, -1.5917261396652274e-03, -2.7775661451061263e-03,
347  -3.4255709083983424e-03, -3.4980109424040981e-03, -3.0470761300287886e-03,
348  -2.1974593033835155e-03, -1.1198042255458091e-03, -2.0229858297200544e-18,
349  9.9055884251036106e-04, 1.7192946812996687e-03, 2.1081914808740686e-03,
350  2.1394563456147114e-03, 1.8513153796509275e-03, 1.3256746563059471e-03,
351  6.7046275382674411e-04, 1.4017739341284856e-18, -5.8331646493291016e-04,
352  -1.0032947419855074e-03, -1.2184233937642017e-03, -1.2238896950094572e-03,
353  -1.0475948732225806e-03, -7.4152795801187910e-04, -3.7044471629615059e-04,
354  -8.7363673902677791e-19, 3.1369007704874736e-04, 5.3155527927017054e-04,
355  6.3531304436406394e-04, 6.2733453548486414e-04, 5.2717915649190441e-04,
356  3.6582485933411455e-04, 1.7887185358663154e-04, 4.6362825333301403e-19,
357  -1.4425544130102367e-04, -2.3771537702543715e-04, -2.7550349276906565e-04,
358  -2.6290359742617416e-04, -2.1264395052204678e-04, -1.4132879082976897e-04,
359  -6.5785565693739621e-05, -1.7899485045886187e-19
360  };
361 
364 
365  ASSERT( ts, status,
366  RESAMPLETIMESERIESH_ENULL, RESAMPLETIMESERIESH_MSGENULL );
367  ASSERT( ts->deltaT > 0, status,
368  RESAMPLETIMESERIESH_ERATE, RESAMPLETIMESERIESH_MSGERATE );
369  ASSERT( ts->data, status,
370  RESAMPLETIMESERIESH_ENULL, RESAMPLETIMESERIESH_MSGENULL );
371  ASSERT( ts->data->length, status,
372  RESAMPLETIMESERIESH_EZERO, RESAMPLETIMESERIESH_MSGEZERO );
373  ASSERT( ts->data->data, status,
374  RESAMPLETIMESERIESH_ENULL, RESAMPLETIMESERIESH_MSGENULL );
375  ASSERT( params, status,
376  RESAMPLETIMESERIESH_ENULL, RESAMPLETIMESERIESH_MSGENULL );
377  ASSERT( params->deltaT > 0, status,
378  RESAMPLETIMESERIESH_ERATE, RESAMPLETIMESERIESH_MSGERATE );
379 
380  /* determine the factor by which to resample */
381  resampleFactor = floor( params->deltaT / ts->deltaT + 0.5 );
382 
383  /* check that the resampling factor is valid */
384  if ( resampleFactor < 1 ||
385  fabs( params->deltaT - resampleFactor * ts->deltaT )
386  > 1e-3 * ts->deltaT )
387  {
388  ABORT( status, RESAMPLETIMESERIESH_EINVD, RESAMPLETIMESERIESH_MSGEINVD );
389  }
390 
391  /* just return if no resampling is required */
392  if ( resampleFactor == 1 )
393  {
394  LALInfo( status, "No resampling required" );
396  RETURN( status );
397  }
398 
399  /* check that we are resampling by a power of two */
400  if ( resampleFactor & (resampleFactor - 1) )
401  {
402  ABORT( status, RESAMPLETIMESERIESH_ELOG2, RESAMPLETIMESERIESH_MSGELOG2 );
403  }
404 
405  if ( params->filterType == defaultButterworth )
406  {
407  params->filterParams.butterworth.nMax = 20;
408  params->filterParams.butterworth.f1 = 0.5 / params->deltaT;
409  params->filterParams.butterworth.a1 = 0.1;
411  params->filterParams.butterworth.a1 = 0.0;
412 
413  LALDButterworthREAL4TimeSeries( status->statusPtr, ts,
414  &(params->filterParams.butterworth) );
416  }
417  else if ( params->filterType == LDASfirLP )
418  {
419  recursCoef.length = 1;
420  recursCoef.data = &recursd0;
421  params->filterParams.iirfilter.name = "FIR filter";
422  params->filterParams.iirfilter.deltaT = ts->deltaT;
423  params->filterParams.iirfilter.recursCoef = &recursCoef;
424  params->filterParams.iirfilter.directCoef = &directCoef;
425  params->filterParams.iirfilter.history = NULL;
426 
427  if ( resampleFactor == 2 )
428  {
429  directCoef.data = ldasByTwo;
430  filterOrder = ldasByTwoOrder;
431  LALInfo( status, ldasByTwoMsg );
432  }
433  else if ( resampleFactor == 4 )
434  {
435  directCoef.data = ldasByFour;
436  filterOrder = ldasByFourOrder;
437  LALInfo( status, ldasByFourMsg );
438  }
439  else if ( resampleFactor == 8 )
440  {
441  directCoef.data = ldasByEight;
442  filterOrder = ldasByEightOrder;
443  LALInfo( status, ldasByEightMsg );
444  }
445  else
446  {
447  ABORT( status, RESAMPLETIMESERIESH_ELDAS, RESAMPLETIMESERIESH_MSGELDAS );
448  }
449 
450  directCoef.length = filterOrder + 1;
451 
452  LALDCreateVector( status->statusPtr,
453  &(params->filterParams.iirfilter.history), filterOrder );
455 
456  LALDIIRFilterREAL4Vector( status->statusPtr, ts->data,
457  &(params->filterParams.iirfilter) );
459 
460  /* account for the corruption of the data by the fir filter */
461  corrupted = filterOrder;
462  snprintf( warnMsg, 256 * sizeof(CHAR),
463  "Corrupted %d points at start and end of time series", corrupted / 2 );
464  LALWarning( status, warnMsg );
465  for ( j = 0; j < corrupted; ++j )
466  {
467  ts->data->data[j] = 0.0;
468  }
469  memmove( ts->data->data, ts->data->data + corrupted / 2,
470  (ts->data->length - corrupted / 2) * sizeof(REAL4) );
471  for ( j = ts->data->length - corrupted / 2; j < ts->data->length; ++j )
472  {
473  ts->data->data[j] = 0.0;
474  }
475 
476  LALDDestroyVector( status->statusPtr,
477  &(params->filterParams.iirfilter.history) );
479  }
480 
481  /* decimate the time series */
482  ts->deltaT = params->deltaT;
483  ts->data->length /= resampleFactor;
484  dataPtr = ts->data->data;
485  for ( j = 0; j < ts->data->length; ++j )
486  {
487  ts->data->data[j] = *dataPtr;
488  dataPtr += resampleFactor;
489  }
490  if ( LALRealloc( ts->data->data, ts->data->length * sizeof(REAL4) ) == NULL ) {
491  XLALPrintError ("LALRealloc() failed!\n");
492  ABORT( status, RESAMPLETIMESERIESH_ENULL, RESAMPLETIMESERIESH_MSGENULL );
493  }
494 
496  RETURN( status );
497 }
498 /** @} */
int XLALLowPassREAL8TimeSeries(REAL8TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
int XLALLowPassREAL4TimeSeries(REAL4TimeSeries *series, REAL8 frequency, REAL8 amplitude, INT4 filtorder)
#define LALInfo(statusptr, info)
Definition: LALError.h:110
#define LALWarning(statusptr, warning)
Definition: LALError.h:103
#define LALRealloc(p, n)
Definition: LALMalloc.h:95
#define ABORT(statusptr, code, mesg)
#define CHECKSTATUSPTR(statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
int XLALPrintInfo(const char *fmt,...)
Definition: XLALError.c:90
int XLALPrintError(const char *fmt,...)
Definition: XLALError.c:68
void LALDButterworthREAL4TimeSeries(LALStatus *status, REAL4TimeSeries *series, PassBandParamStruc *params)
Deprecated.
void LALDIIRFilterREAL4Vector(LALStatus *status, REAL4Vector *vector, REAL8IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
#define LAL_REAL4_MAX
Largest normalized REAL4 number (2-2^-23)*2^127.
Definition: LALConstants.h:55
double REAL8
Double precision real floating-point number (8 bytes).
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
int XLALResampleREAL4TimeSeries(REAL4TimeSeries *series, REAL8 dt)
int XLALResampleREAL8TimeSeries(REAL8TimeSeries *series, REAL8 dt)
void LALResampleREAL4TimeSeries(LALStatus *status, REAL4TimeSeries *ts, ResampleTSParams *params)
#define RESAMPLETIMESERIESH_ERATE
Sample rate is zero.
#define RESAMPLETIMESERIESH_ELOG2
Only power-of-two resampling is avaliable.
#define RESAMPLETIMESERIESH_ELDAS
Input resample factor with LDAS FIR.
#define RESAMPLETIMESERIESH_EINVD
Invalid or non-integer resample factor.
#define RESAMPLETIMESERIESH_EZERO
Length of input time series is zero.
#define RESAMPLETIMESERIESH_ENULL
Null pointer.
@ LDASfirLP
For downsampling by a factor of 2, 4 or 8 an implementation of the FIR filter used by the LDAS dataco...
@ defaultButterworth
An IIR butterwoth filter of order 20 with attenuation 0.1 at the new Nyquist frequency.
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
Definition: XLALError.h:700
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
REAL8 a1
The minimal desired attenuation factors at the reference frequencies.
REAL8 f1
The reference frequencies of the transition band.
INT4 nMax
The maximum desired filter order (actual order may be less if specified attenuations do not require a...
REAL8 f2
The reference frequencies of the transition band.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:570
REAL4Sequence * data
The sequence of sampled data.
Definition: LALDatatypes.h:576
REAL8 deltaT
The time step between samples of the time series in seconds.
Definition: LALDatatypes.h:573
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149
const CHAR * name
User assigned name.
Definition: IIRFilter.h:169
REAL8Vector * history
The previous values of w.
Definition: IIRFilter.h:173
REAL8Vector * recursCoef
The recursive filter coefficients.
Definition: IIRFilter.h:172
REAL8Vector * directCoef
The direct filter coefficients.
Definition: IIRFilter.h:171
REAL8 deltaT
Sampling time interval of the filter; If , it will be ignored (ie it will be taken from the data stre...
Definition: IIRFilter.h:170
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:580
REAL8Sequence * data
The sequence of sampled data.
Definition: LALDatatypes.h:586
REAL8 deltaT
The time step between samples of the time series in seconds.
Definition: LALDatatypes.h:583
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158
This structure controls the behaviour of the resampling function.
ResampleTSFilter filterType
The type of filter with which to perform the low pass filtering.
REAL8 deltaT
The sample interval desired in the down sampled time series.
ResampleTSFilterParams filterParams
Filter parameters for the low pass filter (Presently ignored)
REAL8IIRFilter iirfilter
A structure of type REAL8IIRFilter used to store the parameters of the IIR or FIR filter used to perf...
PassBandParamStruc butterworth
A structure of type PassBandParamStruc used to store the parameters of the butterworth filter used to...