LAL  7.5.0.1-08ee4f4
ComputeCalibrationFactors.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Xavier Siemens
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 <complex.h>
21 #include <math.h>
22 #include <lal/LALStdlib.h>
23 #include <lal/LALStdio.h>
24 #include <lal/LALConstants.h>
25 #include <lal/Calibration.h>
26 
27 /* Independently computes the calibration factors \alpha(t)*\beta(t) and \alpha (t) from */
28 
29 
33  UpdateFactorsParams *params
34  )
35 {
36  const REAL8 tiny = LAL_REAL8_MIN;
37  COMPLEX16 alpha;
38  COMPLEX16 alphabeta;
39  COMPLEX16 beta;
40  COMPLEX16 DARM_CTRL;
41  COMPLEX16 AS_Q;
42  COMPLEX16 EXC;
43  COMPLEX16 G0,D0,W0;
44  REAL8 f0;
45  REAL8 a;
46  REAL8 b;
47  REAL8 c;
48  REAL8 s;
49  UINT4 i;
50 
52 
53  ASSERT( output, status, CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
54  ASSERT( params, status, CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
55 
56  /* sanity check on params */
57  ASSERT( params->darmCtrl, status, CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
58  ASSERT( params->asQ, status, CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
59  ASSERT( params->exc, status, CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
60  ASSERT( params->darmCtrl->data, status,
61  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
62  ASSERT( params->asQ->data, status,
63  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
64  ASSERT( params->exc->data, status,
65  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
66  ASSERT( (int)params->darmCtrl->data->length > 0, status,
67  CALIBRATIONH_ESIZE, CALIBRATIONH_MSGESIZE );
68  ASSERT( (int)params->asQ->data->length > 0, status,
69  CALIBRATIONH_ESIZE, CALIBRATIONH_MSGESIZE );
70  ASSERT( (int)params->exc->data->length > 0, status,
71  CALIBRATIONH_ESIZE, CALIBRATIONH_MSGESIZE );
72  ASSERT( params->darmCtrl->data->data, status,
73  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
74  ASSERT( params->asQ->data->data, status,
75  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
76  ASSERT( params->exc->data->data, status,
77  CALIBRATIONH_ENULL, CALIBRATIONH_MSGENULL );
78 
79  f0 = params->lineFrequency;
80 
81  G0 = params->openloop;
82  D0 = params->digital;
83  W0 = params->whitener;
84 
85 
86  /* ------------------------------------- match filtering ----------------------------------- */
87 
88  /* filter DARM_CTRL against sinusoids at f0 */
89  DARM_CTRL = 0;
90  a = cos( 2.0 * LAL_PI * f0 * params->darmCtrl->deltaT );
91  b = sin( 2.0 * LAL_PI * f0 * params->darmCtrl->deltaT );
92  c = 1;
93  s = 0;
94  for ( i = 0; i < params->darmCtrl->data->length; ++i )
95  {
96  REAL8 tmp = a * c - b * s;
97  DARM_CTRL += c * params->darmCtrl->data->data[i];
98  DARM_CTRL += I * s * params->darmCtrl->data->data[i];
99  s = b * c + a * s;
100  c = tmp;
101  }
102 
103  DARM_CTRL = -conj(DARM_CTRL) * params->darmCtrl->deltaT; /* The conjugation is needed for correct FT convention */
104 
105  /* De-whiten DARM_CTRL */
106  if(W0 != 0.0)
107  {
108  DARM_CTRL *= W0;
109  }
110 
111  output->darm=DARM_CTRL;
112 
113  /* filter AS_Q against sinusoids at f0 */
114  AS_Q = 0;
115  a = cos( 2.0 * LAL_PI * f0 * params->asQ->deltaT );
116  b = sin( 2.0 * LAL_PI * f0 * params->asQ->deltaT );
117  c = 1;
118  s = 0;
119  for ( i = 0; i < params->asQ->data->length; ++i )
120  {
121  REAL8 tmp = a * c - b * s;
122  AS_Q += c * params->asQ->data->data[i];
123  AS_Q += I * s * params->asQ->data->data[i];
124  s = b * c + a * s;
125  c = tmp;
126  }
127 
128  AS_Q = conj(AS_Q) * params->asQ->deltaT;
129 
130  output->asq=AS_Q;
131 
132  /* filter EXC against sinusoids at f0 */
133  EXC = 0;
134  a = cos( 2.0 * LAL_PI * f0 * params->exc->deltaT );
135  b = sin( 2.0 * LAL_PI * f0 * params->exc->deltaT );
136  c = 1;
137  s = 0;
138  for ( i = 0; i < params->exc->data->length; ++i )
139  {
140  REAL8 tmp = a * c - b * s;
141  EXC += c * params->exc->data->data[i];
142  EXC += I * s * params->exc->data->data[i];
143  s = b * c + a * s;
144  c = tmp;
145  }
146 
147  EXC = conj(EXC) * params->exc->deltaT;
148 
149  output->exc=EXC;
150 
151  if (( fabs( creal(EXC) ) < tiny && fabs( cimag(EXC) ) < tiny )) /* check on DARM_CTRL too?? */
152  {
153  output->alphabeta=0.0;
154  output->alpha=0.0;
155  RETURN(status);
156  }
157 
158 
159  /* ------------------------------ compute alpha*beta ------------------------------------- */
160 
161  {
162  COMPLEX16 RD;
163 
164  RD = EXC / DARM_CTRL;
165  alphabeta = (RD - 1.0) / G0;
166  }
167 
168  /* ------------------------------- compute alpha ----------------------------------------- */
169  {
170  COMPLEX16 RQ;
171 
172  RQ = AS_Q / DARM_CTRL;
173  alpha = -RQ * D0 / G0;
174  }
175  /* ------------------------------- compute beta ----------------------------------------- */
176 
177  {
178  COMPLEX16 DmLoQ;
179 
180  DmLoQ = (DARM_CTRL - EXC) / AS_Q;
181  beta = DmLoQ / D0;
182  }
183  /* ------------------ Done, now put alpha, beta and alpha*beta in the output structure --------- */
184 
185  output->alphabeta=alphabeta;
186  output->alpha=alpha;
187  output->beta=beta;
188 
189  RETURN( status );
190 }
void LALComputeCalibrationFactors(LALStatus *status, CalFactors *output, UpdateFactorsParams *params)
#define ASSERT(assertion, statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define CALIBRATIONH_ENULL
Null pointer.
Definition: Calibration.h:49
#define CALIBRATIONH_ESIZE
Invalid size.
Definition: Calibration.h:50
#define LAL_PI
Archimedes's constant, pi.
Definition: LALConstants.h:179
#define LAL_REAL8_MIN
Smallest normalized REAL8 number 2^-1022.
Definition: LALConstants.h:60
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.
static const INT4 a
Definition: Random.c:79
UNDOCUMENTED.
Definition: Calibration.h:82
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
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
UNDOCUMENTED.
Definition: Calibration.h:96
REAL4TimeSeries * darmCtrl
Definition: Calibration.h:101
REAL4TimeSeries * exc
Definition: Calibration.h:103
COMPLEX16 openloop
Definition: Calibration.h:98
REAL4TimeSeries * asQ
Definition: Calibration.h:102
void output(int gps_sec, int output_type)
Definition: tconvert.c:440