33 #include <gsl/gsl_sf_bessel.h>
34 #include <lal/LALConstants.h>
35 #include <lal/LALStdlib.h>
36 #include <lal/LALString.h>
37 #include <lal/Sequence.h>
38 #include <lal/Window.h>
39 #include <lal/XLALError.h>
77 for(i = 0; i < data->
length; i++)
109 static double Y(
int length,
int i)
112 return length > 0 ? (2 * i - length) / (
double) length : 0;
138 for(; start <
end; start++,
end--) {
152 sum += *start * *start + e;
168 for(; start <
end; start++,
end--) {
214 new->data = sequence;
215 new->sumofsquares =
sum_squares(new->data->data, new->data->length);
216 new->sum =
sum_samples(new->data->data, new->data->length);
237 if(!workspace || !
new) {
244 for(i = 0; i < workspace->
length; i++)
245 workspace->
data[i] = sequence->
data[i];
247 new->data = sequence;
360 for(i = 0; i < length; i++)
361 sequence->
data[i] = 1;
377 for(i = 0; i < (length + 1) / 2; i++)
378 sequence->
data[i] = sequence->
data[length - 1 - i] = pow(sin(
LAL_PI_2 * (
Y(length, i) + 1)), 2);
395 for(i = 0; i < (length + 1) / 2; i++)
396 sequence->
data[i] = sequence->
data[length - 1 - i] = 1 - pow(
Y(length, i), 2.0);
414 for(i = 0; i < (length + 1) / 2; i++)
415 sequence->
data[i] = sequence->
data[length - 1 - i] = 1 +
Y(length, i);
431 for(i = 0; i < (length + 1) / 4; i++)
432 sequence->
data[i] = sequence->
data[length - 1 - i] = 2 * pow(1 +
Y(length, i), 3);
433 for(; i < (length + 1) / 2; i++) {
434 double y =
Y(length, i);
435 sequence->
data[i] = sequence->
data[length - 1 - i] = 1 - 6 *
y *
y * (1 +
y);
452 for(i = 0; i < (length + 1) / 2; i++) {
453 double y =
Y(length, i);
471 for(i = 0; i < (length + 1) / 2; i++)
472 sequence->
data[i] = sequence->
data[length - 1 - i] = 0.08 + 0.92 * pow(cos(
LAL_PI_2 *
Y(length, i)), 2);
493 I0beta = gsl_sf_bessel_I0(beta);
524 for(i = 0; i < (length + 1) / 2; i++) {
525 double y =
Y(length, i);
526 double x = sqrt(1 -
y *
y);
530 w1 = gsl_sf_bessel_I0(beta *
x) / I0beta;
538 w2 =
y == 0 ? 1 : gsl_sf_bessel_I0(beta *
x) * sqrt(
LAL_2_PI * beta) / exp(beta);
547 w2 =
y == 0 ? 1 :
x == 0 ? 0 : exp(-beta * (1 -
x)) / sqrt(
x);
551 sequence->
data[i] = sequence->
data[length - 1 - i] = w1;
552 else if(beta < 705) {
553 double r = (beta - 695) / (705 - 695);
554 sequence->
data[i] = sequence->
data[length - 1 - i] = (1 -
r) * w1 +
r * w2;
556 sequence->
data[i] = sequence->
data[length - 1 - i] = w2;
576 for(i = 0; i < (length + 1) / 2; i++) {
577 double y =
Y(length, i);
590 sequence->
data[i] = sequence->
data[length - 1 - i] = (beta == 0 &&
y == -1) ||
y == 0 ? 1 : exp(-beta *
y *
y / fabs(1 -
y *
y));
600 UINT4 transition_length = round(beta * length);
603 if(beta < 0 || beta > 1)
614 for(i = 0; i < (transition_length + 1) / 2; i++)
615 sequence->
data[i] = sequence->
data[length - 1 - i] = pow(cos(
LAL_PI_2 *
Y(transition_length, i)), 2);
616 for(; i < (length + 1) / 2; i++)
617 sequence->
data[i] = sequence->
data[length - 1 - i] = 1;
636 beta = -0.5 * beta * beta;
639 for(i = 0; i < (length + 1) / 2; i++) {
640 double y =
Y(length, i);
643 sequence->
data[i] = sequence->
data[length - 1 - i] =
y == 0 ? 1 : exp(
y *
y * beta);
659 for(i = 0; i < length; i++) {
660 double pi_y =
LAL_PI *
Y(length, i);
661 sequence->
data[i] = pi_y != 0. ? sin(pi_y) / pi_y : 1.0;
774 typedef enum tagLALWindowType
826 char windowNameLC [ strlen(windowName) + 1 ];
827 strcpy ( windowNameLC, windowName );
862 "Inconsistent Window-option: '%s' requires parameter = %s, but user supplied parameter = %s\n",
865 haveBeta ?
"yes" :
"no" );
static REAL8 sum_samples(REAL8 *start, int length)
const BOOLEAN hasBeta
does this window need a 'beta' parameter?
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...
@ LAL_WINDOWTYPE_CREIGHTON
@ LAL_WINDOWTYPE_PAPOULIS
@ LAL_WINDOWTYPE_BARTLETT
@ LAL_WINDOWTYPE_RECTANGULAR
static int XLALParseWindowNameAndCheckBeta(const char *windowName, REAL8 beta)
Parse window-name string (case-insensitive) into an internal window-type index (>=0,...
static REAL8 sum_squares(REAL8 *start, int length)
Computes the sum of squares, and sum, of the samples in a window function.
const struct @16 AllowedWindows[LAL_WINDOWTYPE_LAST]
static REAL4Window * XLALREAL4Window_from_REAL8Window(REAL8Window *orig)
Constructs a REAL4Window from a REAL8Window by quantizing the double-precision data to single-precisi...
const char *const name
window name
int XLALPrintError(const char *fmt,...)
#define LAL_2_PI
2/pi is Buffon's constant
#define LAL_PI
Archimedes's constant, pi.
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
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).
int XLALStringToLowerCase(char *string)
Turn a string in-place into lowercase without using locale-dependent functions.
void XLALDestroyREAL8Sequence(REAL8Sequence *sequence)
void XLALDestroyREAL4Sequence(REAL4Sequence *sequence)
REAL4Sequence * XLALCreateREAL4Sequence(size_t length)
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
REAL8Window * XLALCreateWelchREAL8Window(UINT4 length)
REAL4Window * XLALCreateTukeyREAL4Window(UINT4 length, REAL4 beta)
REAL4Window * XLALCreateGaussREAL4Window(UINT4 length, REAL4 beta)
REAL4Window * XLALCreateBartlettREAL4Window(UINT4 length)
REAL4Window * XLALCreateRectangularREAL4Window(UINT4 length)
REAL4Window * XLALCreateLanczosREAL4Window(UINT4 length)
COMPLEX16Sequence * XLALUnitaryWindowCOMPLEX16Sequence(COMPLEX16Sequence *sequence, const REAL8Window *window)
Double-precision complex version of XLALUnitaryWindowREAL8Sequence().
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 * XLALCreateParzenREAL4Window(UINT4 length)
REAL4Window * XLALCreateHannREAL4Window(UINT4 length)
REAL4Window * XLALCreatePapoulisREAL4Window(UINT4 length)
REAL4Window * XLALCreateHammingREAL4Window(UINT4 length)
REAL4Window * XLALCreateCreightonREAL4Window(UINT4 length, REAL4 beta)
REAL8Window * XLALCreateLanczosREAL8Window(UINT4 length)
void XLALDestroyREAL8Window(REAL8Window *window)
REAL8Window * XLALCreatePapoulisREAL8Window(UINT4 length)
REAL8Window * XLALCreateHannREAL8Window(UINT4 length)
COMPLEX8Sequence * XLALUnitaryWindowCOMPLEX8Sequence(COMPLEX8Sequence *sequence, const REAL4Window *window)
Single-precision complex version of XLALUnitaryWindowREAL8Sequence().
REAL8Window * XLALCreateCreightonREAL8Window(UINT4 length, REAL8 beta)
REAL4Sequence * XLALUnitaryWindowREAL4Sequence(REAL4Sequence *sequence, const REAL4Window *window)
Single-precision version of XLALUnitaryWindowREAL8Sequence().
REAL8Sequence * XLALUnitaryWindowREAL8Sequence(REAL8Sequence *sequence, const REAL8Window *window)
Multiply a REAL8Sequence in-place by a REAL8Window with a normalization that preserves the variance o...
int XLALCheckNamedWindow(const char *windowName, const BOOLEAN haveBeta)
Check whether a named window-function exists and whether it requires a parameter.
REAL8Window * XLALCreateGaussREAL8Window(UINT4 length, REAL8 beta)
void XLALDestroyREAL4Window(REAL4Window *window)
REAL4Window * XLALCreateWelchREAL4Window(UINT4 length)
REAL8Window * XLALCreateKaiserREAL8Window(UINT4 length, REAL8 beta)
REAL8Window * XLALCreateBartlettREAL8Window(UINT4 length)
REAL8Window * XLALCreateHammingREAL8Window(UINT4 length)
REAL8Window * XLALCreateTukeyREAL8Window(UINT4 length, REAL8 beta)
REAL4Window * XLALCreateREAL4WindowFromSequence(REAL4Sequence *sequence)
Single-precision version of XLALCreateREAL8WindowFromSequence().
REAL8Window * XLALCreateREAL8WindowFromSequence(REAL8Sequence *sequence)
Constructs a new REAL8Window from a REAL8Sequence.
REAL8Window * XLALCreateParzenREAL8Window(UINT4 length)
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#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...
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_ERANGE
Output range error.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EERR
Internal error.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
COMPLEX16 * data
Pointer to the data array.
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
COMPLEX8 * data
Pointer to the data array.
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...
REAL4Sequence * data
The window function samples.
REAL8 sumofsquares
The sum of the squares of the window function samples.
Vector of type REAL8, see DATATYPE-Vector types for more details.
REAL8 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
Structure for storing REAL8 window function data, providing storage for a sequence of samples as well...
REAL8Sequence * data
The window function samples.
REAL8 sumofsquares
The sum of the squares of the window function samples.
REAL8 sum
The sum of the window function samples.