59 #include <lal/LALStdlib.h>
60 #include <lal/LALgetopt.h>
61 #include <lal/LALConstants.h>
62 #include <lal/LALStdio.h>
63 #include <lal/AVFactories.h>
64 #include <lal/Units.h>
65 #include <lal/Random.h>
66 #include <lal/PrintFTSeries.h>
67 #include <lal/TimeFreqFFT.h>
70 #define CODES(x) CODES_(x)
81 TestStatus(
LALStatus *
status,
const char *expectedCodes,
int exitCode );
83 int main(
int argc,
char *argv[] )
85 const UINT4 n = 65536;
86 const REAL4 dt = 1.0 / 16384.0;
104 UINT4 srate[] = { 4096, 9000 };
105 UINT4 npts[] = { 262144, 1048576 };
106 REAL4 var[] = { 5, 16 };
116 TestStatus( &
status, CODES( 0 ), 1 );
118 TestStatus( &
status, CODES( 0 ), 1 );
121 TestStatus( &
status, CODES( 0 ), 1 );
123 TestStatus( &
status, CODES( 0 ), 1 );
129 TestStatus( &
status, CODES( 0 ), 1 );
144 snprintf(
x.name,
sizeof(
x.name ),
"x" );
146 for ( j = 0; j < n; ++j )
149 x.data->data[j] += 0.1 * cos(
LAL_TWOPI * 60.0 * t );
153 snprintf( X.
name,
sizeof( X.
name ),
"X" );
173 UINT4 tsLength = npts[np] * 7 - 6 * npts[np] / 2;
175 TestStatus( &
status, CODES( 0 ), 1 );
177 TestStatus( &
status, CODES( 0 ), 1 );
182 y.deltaT = 1.0 / (
REAL8) srate[sr];
186 REAL4 Sfk = 2.0 * var[vr] * var[vr] *
y.deltaT;
196 for ( j = 0; j <
y.data->length; ++j )
198 y.data->data[j] *= var[vr];
199 ssq +=
y.data->data[j] *
y.data->data[j];
203 lbn = log(
y.data->length ) / log( 2 );
204 sig = sqrt( 2.5 * lbn *
eps *
eps * ssq /
y.data->length );
209 TestStatus( &
status, CODES( 0 ), 1 );
212 for(sfk = 0., k = 0; k <
Y.data->length; sfk +=
Y.data->data[k++])
214 sfk /=
Y.data->length;
218 if ( fabs(Sfk-sfk) > tol )
220 fprintf( stderr,
"FAIL: PSD estimate appears incorrect\n");
221 fprintf( stderr,
"expected %e, got %e ", Sfk, sfk );
222 fprintf( stderr,
"(difference = %e, tolerance = %e)\n",
223 fabs(Sfk-sfk), tol );
234 TestStatus( &
status, CODES( 0 ), 1 );
236 TestStatus( &
status, CODES( 0 ), 1 );
250 snprintf( z.
name,
sizeof( z.
name ),
"z" );
257 for ( j = 0; j < n; ++j )
264 TestStatus( &
status, CODES( 0 ), 1 );
266 snprintf( Z.
name,
sizeof( Z.
name ),
"Z" );
271 TestStatus( &
status, CODES( 0 ), 1 );
282 TestStatus( &
status, CODES( 0 ), 1 );
284 TestStatus( &
status, CODES( 0 ), 1 );
287 TestStatus( &
status, CODES( 0 ), 1 );
289 TestStatus( &
status, CODES( 0 ), 1 );
315 if ( strncpy( str, ignored,
sizeof( str ) ) )
317 if ( (tok = strtok( str,
" " ) ) )
321 if (
status->statusCode == atoi( tok ) )
326 while ( ( tok = strtok( NULL,
" " ) ) );
330 if (
status->statusCode == atoi( str ) )
337 fprintf( stderr,
"\nExiting to system with code %d\n", exitcode );
352 fprintf( stderr,
"Options:\n" );
353 fprintf( stderr,
" -h print this message\n" );
354 fprintf( stderr,
" -q quiet: run silently\n" );
355 fprintf( stderr,
" -v verbose: print extra information\n" );
356 fprintf( stderr,
" -d level set lalDebugLevel to level\n" );
392 fp = freopen(
"/dev/null",
"w", stderr );
395 fprintf(stderr,
"Error: Unable to open /dev/null\n");
398 fp = freopen(
"/dev/null",
"w", stdout );
401 fprintf(stderr,
"Error: Unable to open /dev/null\n");
void REPORTSTATUS(LALStatus *status)
void LALCheckMemoryLeaks(void)
int LALgetopt(int argc, char *const *argv, const char *optstring)
static double Y(int length, int i)
Maps the length of a window and the offset within the window to the "y" co-ordinate of the LAL docume...
static void Usage(const char *program, int exitcode)
static void ParseOptions(int argc, char *argv[])
int main(int argc, char *argv[])
COMPLEX8FFTPlan * XLALCreateReverseCOMPLEX8FFTPlan(UINT4 size, int measurelvl)
Returns a new COMPLEX8FFTPlan for a reverse transform.
COMPLEX8FFTPlan * XLALCreateForwardCOMPLEX8FFTPlan(UINT4 size, int measurelvl)
Returns a new COMPLEX8FFTPlan for a forward transform.
void XLALDestroyCOMPLEX8FFTPlan(COMPLEX8FFTPlan *plan)
Destroys a COMPLEX8FFTPlan.
#define LAL_TWOPI
2*pi is circumference of a circle divided by its radius
#define XLAL_NUM_ELEM(x)
MACRO which gives the number of elements in a fixed-size array.
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
float REAL4
Single precision real floating-point number (4 bytes).
void LALCPrintFrequencySeries(COMPLEX8FrequencySeries *series, const CHAR *filename)
void LALCPrintTimeSeries(COMPLEX8TimeSeries *series, const CHAR *filename)
void LALSPrintTimeSeries(REAL4TimeSeries *series, const CHAR *filename)
RandomParams * XLALCreateRandomParams(INT4 seed)
void XLALDestroyRandomParams(RandomParams *params)
int XLALNormalDeviates(REAL4Vector *deviates, RandomParams *params)
REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a reverse transform.
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a forward transform.
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
Destroys a REAL4FFTPlan.
int XLALCOMPLEX8FreqTimeFFT(COMPLEX8TimeSeries *time, const COMPLEX8FrequencySeries *freq, const COMPLEX8FFTPlan *plan)
int XLALREAL4AverageSpectrumWelch(REAL4FrequencySeries *spectrum, const REAL4TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL4Window *window, const REAL4FFTPlan *plan)
Use Welch's method to compute the average power spectrum of a time series.
int XLALREAL4FreqTimeFFT(REAL4TimeSeries *time, const COMPLEX8FrequencySeries *freq, const REAL4FFTPlan *plan)
int XLALCOMPLEX8TimeFreqFFT(COMPLEX8FrequencySeries *freq, const COMPLEX8TimeSeries *time, const COMPLEX8FFTPlan *plan)
int XLALREAL4TimeFreqFFT(COMPLEX8FrequencySeries *freq, const REAL4TimeSeries *time, const REAL4FFTPlan *plan)
const LALUnit lalMeterUnit
meter [m]
const LALUnit lalVoltUnit
Volt [V].
void LALCCreateVector(LALStatus *, COMPLEX8Vector **, UINT4)
void LALDestroyVector(LALStatus *, REAL4Vector **)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALCreateVector(LALStatus *, REAL4Vector **, UINT4)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
REAL4Window * XLALCreateHannREAL4Window(UINT4 length)
void XLALDestroyREAL4Window(REAL4Window *window)
See DATATYPE-FrequencySeries types for documentation.
Time series of COMPLEX8 data, see DATATYPE-TimeSeries types for more details.
CHAR name[LALNameLength]
The name of the time series.
LALUnit sampleUnits
The physical units of the quantity being sampled.
REAL8 f0
The heterodyning frequency, in Hertz (zero if not heterodyned).
REAL8 deltaT
The time step between samples of the time series in seconds.
COMPLEX8Sequence * data
The sequence of sampled data.
UINT4 length
Number of elements in array.
COMPLEX8 * data
Pointer to the data array.
LAL status structure, see The LALStatus structure for more details.
See DATATYPE-FrequencySeries types for documentation.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
Vector of type REAL4, see DATATYPE-Vector types for more details.
REAL4 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Structure for storing REAL4 window function data, providing storage for a sequence of samples as well...
This structure contains the parameters necessary for generating the current sequence of random number...