23 #include <lal/LALStdlib.h>
24 #include <lal/LALConstants.h>
25 #include <lal/Calibration.h>
26 #include <lal/LALDatatypes.h>
27 #include <lal/LALStdlib.h>
28 #include <lal/LALStdio.h>
29 #include <lal/AVFactories.h>
30 #include <lal/Window.h>
31 #include <lal/BandPassTimeSeries.h>
32 #include <lal/TimeFreqFFT.h>
33 #include <lal/RealFFT.h>
34 #include <lal/AVFactories.h>
35 #include <lal/FrequencySeries.h>
36 #include <lal/TimeSeries.h>
38 #include <gsl/gsl_interp.h>
39 #include <gsl/gsl_spline.h>
41 #define MAXALPHAS 10000
43 #define N_FIR_LP_ALPHAS 8192
44 #define fhigh_FIRLP_ALPHAS 0.00001220703125
48 #define fhigh_FIRLP .9
51 #define fhigh_FIRHP 0.00244140625
59 static void remove_transients(
StrainIn *input);
87 if (!
status->statusPtr)
return;
96 for (
p=0;
p<(int)
output->hR.data->length;
p++)
104 for (
p=0;
p<(int)
output->hC.data->length;
p++)
110 output->hC.sampleUnits.powerOfTen = 0;
113 output->hC.sampleUnits.unitNumerator[
p] = 0;
114 output->hC.sampleUnits.unitDenominatorMinusOne[
p] = 0;
121 for (
p=0;
p<(int)
output->hC.data->length;
p++)
130 for (
p=0;
p<(int)
output->hR.data->length;
p++)
140 for (
p=0;
p<(int)
output->hC.data->length;
p++)
152 ABORT(
status, 117,
"Upsampling factor != 1, this is not a good filters file.");
177 if ( (
r < 0.8) || (
r > 1.2) || (isnan(
r)) || isinf(
r))
224 for (
p=0;
p<(int)
output->hR.data->length;
p++) {
293 for(k = 0; k < (int)
output->hC.data->length; k++){
299 fprintf(stdout,
"Warning: Not adding calibration lines to control signal.\n");
316 for (
p=0;
p< (int)
output->h.data->length;
p++){
365 exp(-0.5*pow(3.0*(
double)k[l]/(
double)
N_FIR_LP,2));
410 exp(-0.5*pow(3.0*(
double)k[l]/(
double)
N_FIR_LP_ALPHAS,2))/8.318081379762647e-02;
454 exp(-0.5*pow(3.0*(
double)k[l]/(
double)
N_FIR_HP,2));
503 if(n < hR->data->length-1) y_2=hR->
data->
data[n+1];
506 for (
m=0;
m < (
UINT4)up_factor;
m++)
508 uphR->
data->
data[n*up_factor+
m] = y_1+
m*(y_2-y_1)/up_factor;
523 fprintf(stderr,
"Length of residual strin time series (%d), not the same as factors time series, (%d)\n"
548 REAL4Window *asqwin=NULL, *excwin=NULL, *darmwin=NULL;
584 for(
m=0;
m < (
UINT4)(deltaT*length) / To;
m++)
626 fprintf(stderr,
"Too many values of the factors, maximum allowed is %d\n",
MAXALPHAS);
665 for (n = Ntseries-1; n >= Nfir-1; n--)
668 for (
m = Nfir-1;
m >= 0;
m--)
670 sum += b[
m] *
x[n-
m];
690 REAL8FFTPlan *fplan = NULL, *rplan = NULL;
700 fprintf(stderr,
"ERROR. tseries length (=%d) < filter length (=%d)",
702 ABORT(
status,118,
"Time series is smaller than filter length.");
720 for (n = 0; n < (int)tseriesDATA->
data->
length; n++)
732 for (n = 0; n < (int)tseries->
data->
length; n++)
761 fprintf(stderr,
"Failed creating FT of time series. Errorcode: %d\n",xlerr);
768 fprintf(stderr,
"Failed creating FT of FIR filter time series. Errorcode: %d\n",xlerr);
774 for (n = 0; n < (int)vtilde->
data->
length; n++)
776 vtilde->
data->
data[n] *= vtildeFIR->data->data[n];
783 fprintf(stderr,
"Failed creating IFT of FIR and time series. Errorcode: %d\n",xlerr);
788 for (n = 0; n < (int)tseries->
data->
length; n++)
819 if (isnan(
x) || isinf(
x)) {
820 fprintf(stderr,
"ERROR: bad DARM_ERR\n");
829 if (isnan(
x) || isinf(
x)) {
830 fprintf(stderr,
"ERROR: bad DARM_CTRL\n");
859 static void remove_transients(
StrainIn *input)
867 int r_sv, r_light, r_darm;
869 const double DARM_ERR_THRESHOLD = 1e0;
871 const double DERIV_THRESHOLD = 1e-3;
881 for (i = 0; i < nsecs; i++) {
890 for (j = 0; j < r_light; j++) {
895 light = (sum_x/r_light > 100 && sum_y/r_light > 100);
901 for (j = 0; j < r_sv; j++) {
904 if ((s & (1 << 2)) == 0) up = 0;
912 for (j = 0; j < r_darm; j++)
913 if (fabs(derr[i*r_darm + j]) > DARM_ERR_THRESHOLD)
918 for (j = 0; j < r_darm-1; j++)
919 if (fabs(derr[i*r_darm + j+1] - derr[i*r_darm + j]) > DERIV_THRESHOLD)
925 if (up && !(derr_small && deriv_small))
926 fprintf(stderr,
"WARNING: glitch found by non-conventional methods. "
927 "Zeroing presumed bad data so it doesn't affect the rest of the frame.\n");
932 if (! (up && derr_small && deriv_small) ) {
933 for (j = 0; j < r_darm; j++) {
void LALComputeCalibrationFactors(LALStatus *status, CalFactors *output, UpdateFactorsParams *input)
void LALComputeStrain(LALStatus *status, StrainOut *output, StrainIn *input)
static void set_output_to_zero(StrainOut *output)
static void check_nans_infs(LALStatus *status, StrainIn *input)
#define fhigh_FIRLP_ALPHAS
int XLALUpsample(REAL8TimeSeries *uphR, REAL8TimeSeries *hR, int up_factor)
void LALMakeFIRLP(LALStatus *status, REAL8IIRFilter *LPFIR, int USF)
void LALGetFactors(LALStatus *status, StrainOut *output, StrainIn *input)
int XLALUpsampleLinear(REAL8TimeSeries *uphR, REAL8TimeSeries *hR, int up_factor)
void LALMakeFIRLPALPHAS(LALStatus *status, REAL8IIRFilter *LPFIR)
int XLALDivideTimeSeries(REAL8TimeSeries *hR, REAL8TimeSeries *ALPHAS)
void LALFFTFIRFilter(LALStatus *status, REAL8TimeSeries *tseries, REAL8IIRFilter *FIR)
void LALMakeFIRHP(LALStatus *status, REAL8IIRFilter *HPFIR)
int XLALFIRFilter(REAL8TimeSeries *tseries, REAL8IIRFilter *FIR)
#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)
COMPLEX16FrequencySeries * XLALCreateCOMPLEX16FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX16FrequencySeries(COMPLEX16FrequencySeries *series)
#define LAL_PI
Archimedes's constant, pi.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
@ LALNumUnits
The number of units.
void XLALDestroyREAL8FFTPlan(REAL8FFTPlan *plan)
Destroys a REAL8FFTPlan.
REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a reverse transform.
REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a forward transform.
int XLALREAL8TimeFreqFFT(COMPLEX16FrequencySeries *freq, const REAL8TimeSeries *time, const REAL8FFTPlan *plan)
int XLALREAL8FreqTimeFFT(REAL8TimeSeries *time, const COMPLEX16FrequencySeries *freq, const REAL8FFTPlan *plan)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
void LALDestroyVector(LALStatus *, REAL4Vector **)
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALCreateVector(LALStatus *, REAL4Vector **, UINT4)
REAL4Window * XLALCreateHannREAL4Window(UINT4 length)
void XLALDestroyREAL4Window(REAL4Window *window)
See DATATYPE-FrequencySeries types for documentation.
UINT4 length
Number of elements in array.
COMPLEX16 * data
Pointer to the data array.
LAL status structure, see The LALStatus structure for more details.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
REAL4Sequence * data
The sequence of sampled data.
REAL8 deltaT
The time step between samples of the time series in seconds.
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.
This structure stores the direct and recursive REAL8 filter coefficients, as well as the history of t...
REAL8Vector * history
The previous values of w.
REAL8Vector * recursCoef
The recursive filter coefficients.
REAL8Vector * directCoef
The direct filter coefficients.
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
REAL8Sequence * data
The sequence of sampled data.
LALUnit sampleUnits
The physical units of the quantity being sampled.
REAL8 deltaT
The time step between samples of the time series in seconds.
LIGOTimeGPS epoch
The start time of the time series.
CHAR name[LALNameLength]
The name of the time series.
REAL8 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
REAL4TimeSeries EXC
timeseries containing the excitation
COMPLEX16 Do
digital filter at cal line frequency
REAL8IIRFilter * Cinv
Filters for inverse of sensing function.
INT4 usefactors
UNDOCUMENTED.
REAL8IIRFilter * D
Filters for analog actuation function.
REAL8 f
calibration line frequency
INT4 fftconv
UNDOCUMENTED.
INT4 outalphas
UNDOCUMENTED.
REAL8IIRFilter * A
Filters for analog actuation function.
REAL8IIRFilter * AW
Filters for analog actuation function.
REAL4TimeSeries AS_Q
timeseries containing ASQ
REAL4TimeSeries StateVector
timeseries containing the State Vector (IFO-SV_STATE_VECTOR)
REAL4TimeSeries DARM
timeseries containing DARM_CTRL
INT4 CinvUSF
Upsampling factor for sensing function.
COMPLEX16 Wo
Whitening filter at cal line frequency.
INT4 darmctrl
UNDOCUMENTED.
COMPLEX16 Go
OLG at cal line frequency.
INT4 CinvDelay
Overall inverse sensing function delay.
REAL4TimeSeries LAY
timeseries containing the Light-in-Y-arm (LSC-LA_PTRY_NORM)
REAL8 gamma_fudgefactor
UNDOCUMENTED.
REAL4 To
factors integration time
REAL4TimeSeries LAX
timeseries containing the Light-in-X-arm (LSC-LA_PTRX_NORM)
REAL4TimeSeries DARM_ERR
timeseries containing DARM_ERR
REAL4TimeSeries * darmCtrl
void output(int gps_sec, int output_type)