26 #include <lal/LALDatatypes.h>
27 #include <lal/Window.h>
28 #include <lal/XLALError.h>
29 #include <lal/LALMalloc.h>
56 if ( !strcmp (
names[i],
"Kaiser" ) ) {
58 }
else if ( !strcmp (
names[i],
"Creighton" ) ) {
59 beta = creighton_beta;
60 }
else if ( !strcmp (
names[i],
"Tukey" ) ) {
62 }
else if ( !strcmp (
names[i],
"Gauss" ) ) {
92 if ( !strcmp (
names[i],
"Kaiser" ) ) {
94 }
else if ( !strcmp (
names[i],
"Creighton" ) ) {
95 beta = creighton_beta;
96 }
else if ( !strcmp (
names[i],
"Tukey" ) ) {
98 }
else if ( !strcmp (
names[i],
"Gauss" ) ) {
125 return fabs((
a - b) /
a);
128 return fabs((
a - b) / b);
139 static int _test_sum_of_squares(
const double *correct,
int length,
double kaiser_beta,
double creighton_beta,
double tukey_beta,
double gauss_beta)
141 const double max_error = 1e-12;
152 XLAL_ERROR (
XLAL_EFAILED,
"error: single-precision %d-sample %s window fails sum-of-squares test: expected %.17g, got %.17g\n",
153 length,
names[i], correct[i], windows1[i]->sumofsquares);
156 XLAL_ERROR (
XLAL_EFAILED,
"error: double-precision %d-sample %s window fails sum-of-squares test: expected %.17g, got %.17g\n", length,
names[i], correct[i], windows1[i]->sumofsquares);
170 double correct_1024[] = {
184 double correct_1025[] = {
213 static int _test_end_and_midpoints(
int length,
double kaiser_beta,
double creighton_beta,
double tukey_beta,
double gauss_beta)
215 const double max_error = 1e-16;
216 double correct_end[] = {
224 0.014873337104763204,
230 double correct_mid[] = {
249 correct_end[7] = kaiser_beta == 0 ? 1 : kaiser_beta == HUGE_VAL ? 0 : correct_end[7];
252 correct_end[8] = creighton_beta == 0 ? 1 : correct_end[8];
255 correct_end[9] = tukey_beta == 0 ? 1 : correct_end[9];
258 correct_end[10] = exp(-0.5 * gauss_beta * gauss_beta);
266 if(fabs(windows1[i]->data->
data[0] - (
float) correct_end[i]) > max_error) {
267 XLAL_ERROR (
XLAL_EFAILED,
"error: single-precision %d-sample %s window fails end-point test: expected %.17g, got %.17g\n", length,
names[i], correct_end[i], windows1[i]->data->
data[0]);
269 if(fabs(windows2[i]->data->
data[0] - correct_end[i]) > max_error) {
270 XLAL_ERROR (
XLAL_EFAILED,
"error: double-precision %d-sample %s window fails end-point test: expected %.17g, got %.17g\n", length,
names[i], correct_end[i], windows2[i]->data->
data[0]);
272 if(fabs(windows1[i]->data->
data[length - 1] - (
float) correct_end[i]) > max_error) {
273 XLAL_ERROR (
XLAL_EFAILED,
"error: single-precision %d-sample %s window fails end-point test: expected %.17g, got %.17g\n", length,
names[i], correct_end[i], windows1[i]->data->
data[length - 1]);
275 if(fabs(windows2[i]->data->
data[length - 1] - correct_end[i]) > max_error) {
276 XLAL_ERROR (
XLAL_EFAILED,
"error: double-precision %d-sample %s window fails end-point test: expected %.17g, got %.17g\n", length,
names[i], correct_end[i], windows2[i]->data->
data[length - 1]);
281 if(windows1[i]->data->
data[length / 2] != (
float) correct_mid[i]) {
282 XLAL_ERROR (
XLAL_EFAILED,
"error: single-precision %d-sample %s window fails mid-point test: expected %.17g, got %.17g\n", length,
names[i], correct_mid[i], windows1[i]->data->
data[length / 2]);
284 if(windows2[i]->data->
data[length / 2] != correct_mid[i]) {
285 XLAL_ERROR (
XLAL_EFAILED,
"error: double-precision %d-sample %s window fails mid-point test: expected %.17g, got %.17g\n", length,
names[i], correct_mid[i], windows1[i]->data->
data[length / 2]);
343 fprintf(stderr,
"error: single-precision Kaiser window accepted out-of-range parameter\n");
350 fprintf(stderr,
"error: double-precision Kaiser window accepted out-of-range parameter\n");
357 fprintf(stderr,
"error: single-precision Creighton window accepted out-of-range parameter\n");
364 fprintf(stderr,
"error: double-precision Creighton window accepted out-of-range parameter\n");
371 fprintf(stderr,
"error: single-precision Tukey window accepted out-of-range parameter\n");
378 fprintf(stderr,
"error: single-precision Tukey window accepted out-of-range parameter\n");
385 fprintf(stderr,
"error: double-precision Tukey window accepted out-of-range parameter\n");
392 fprintf(stderr,
"error: double-precision Tukey window accepted out-of-range parameter\n");
399 fprintf(stderr,
"error: single-precision Gauss window accepted out-of-range parameter\n");
406 fprintf(stderr,
"error: double-precision Gauss window accepted out-of-range parameter\n");
420 static void _display(
int n,
double kaiser_beta,
double creighton_beta,
double tukey_beta,
double gauss_beta)
436 printf(
"n = %d\n", n);
437 printf(
"kaiser beta = %g\n", kaiser_beta);
438 printf(
"creighton beta = %g\n", creighton_beta);
439 printf(
"tukey beta = %g\n", tukey_beta);
440 printf(
"gaussian beta = %g\n", gauss_beta);
442 printf(
" rect hann welch bartlett parzen papoulis hamming kaiser creight tukey gauss lanczos\n");
443 for(i = 0; i < n; i++) {
444 printf(
"%8.6f", rectangle->
data->
data[i]);
445 printf(
" %8.6f", hann->
data->
data[i]);
446 printf(
" %8.6f", welch->
data->
data[i]);
447 printf(
" %8.6f", bartlett->
data->
data[i]);
448 printf(
" %8.6f", parzen->
data->
data[i]);
449 printf(
" %8.6f", papoulis->
data->
data[i]);
450 printf(
" %8.6f", hamming->
data->
data[i]);
451 printf(
" %8.6f", kaiser->
data->
data[i]);
452 printf(
" %8.6f", creighton->
data->
data[i]);
453 printf(
" %8.6f", tukey->
data->
data[i]);
454 printf(
" %8.6f", gauss->
data->
data[i]);
455 printf(
" %8.6f",
lanczos->data->data[i]);
481 _display(14, HUGE_VAL, HUGE_VAL, 1, HUGE_VAL);
482 _display(15, HUGE_VAL, HUGE_VAL, 1, HUGE_VAL);
489 _display(1, HUGE_VAL, HUGE_VAL, 1.0, HUGE_VAL);
501 char *hosttype = getenv(
"hosttype");
509 if(!strcmp(hosttype ? hosttype :
"",
"alpha")) {
510 fprintf(stderr,
"Window functions not computable on DEC Alpha, tests skipped! Set environment variable \"hosttype\" to something other than \"alpha\" to force tests\n");
void LALCheckMemoryLeaks(void)
static double lanczos(double t, double a)
static int test_end_and_midpoints(void)
static int _test_end_and_midpoints(int length, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
static double fractional_difference(double a, double b)
static int _test_sum_of_squares(const double *correct, int length, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
static int create_single_windows(REAL4Window **windows, int length, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
static void free_double_windows(REAL8Window **windows)
static void display(void)
static void free_single_windows(REAL4Window **windows)
static void _display(int n, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
static int test_sum_of_squares(void)
static int create_double_windows(REAL8Window **windows, int length, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
static int test_parameter_safety(void)
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
REAL8Window * XLALCreateWelchREAL8Window(UINT4 length)
REAL4Window * XLALCreateTukeyREAL4Window(UINT4 length, REAL4 beta)
REAL4Window * XLALCreateGaussREAL4Window(UINT4 length, REAL4 beta)
REAL4Window * XLALCreateKaiserREAL4Window(UINT4 length, REAL4 beta)
REAL4Window * XLALCreateNamedREAL4Window(const char *windowName, REAL8 beta, UINT4 length)
REAL8Window * XLALCreateNamedREAL8Window(const char *windowName, REAL8 beta, UINT4 length)
Generic window-function wrapper, allowing to select a window by its name.
REAL8Window * XLALCreateRectangularREAL8Window(UINT4 length)
REAL4Window * XLALCreateCreightonREAL4Window(UINT4 length, REAL4 beta)
REAL8Window * XLALCreateLanczosREAL8Window(UINT4 length)
void XLALDestroyREAL8Window(REAL8Window *window)
REAL8Window * XLALCreatePapoulisREAL8Window(UINT4 length)
REAL8Window * XLALCreateHannREAL8Window(UINT4 length)
REAL8Window * XLALCreateCreightonREAL8Window(UINT4 length, REAL8 beta)
REAL8Window * XLALCreateGaussREAL8Window(UINT4 length, REAL8 beta)
void XLALDestroyREAL4Window(REAL4Window *window)
REAL8Window * XLALCreateKaiserREAL8Window(UINT4 length, REAL8 beta)
REAL8Window * XLALCreateBartlettREAL8Window(UINT4 length)
REAL8Window * XLALCreateHammingREAL8Window(UINT4 length)
REAL8Window * XLALCreateTukeyREAL8Window(UINT4 length, REAL8 beta)
REAL8Window * XLALCreateParzenREAL8Window(UINT4 length)
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EFAILED
Generic failure.
Structure for storing REAL4 window function data, providing storage for a sequence of samples as well...
REAL4Sequence * data
The window function samples.
REAL8 * data
Pointer to the data array.
Structure for storing REAL8 window function data, providing storage for a sequence of samples as well...
REAL8Sequence * data
The window function samples.