LALInspiral 5.0.3.1-eeff03c
LALInspiralWaveOverlap.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 David Churches, Duncan Brown, Jolien Creighton, B.S. Sathyaprakash, Anand Sengupta, Craig Robinson , Thomas Cokelaer
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/**
21 * \author Sathyaprakash, B. S.
22 * \file
23 *
24 * \brief Module to compute the overlap of a given data set with
25 * two orthogonal inspiral signals of specified parameters
26 * with a weight specified in a psd array. The code also returns
27 * in a parameter structure the maximum of the overlap, the bin
28 * where the maximum occured and the phase at the maximum.
29 *
30 * ### Prototypes ###
31 *
32 * <tt>LALInspiralWaveOverlap()</tt>
33 *
34 * ### Description ###
35 *
36 *
37 * ### Algorithm ###
38 *
39 *
40 * ### Uses ###
41 *
42 * \code
43 * LALInspiralWave()
44 * LALREAL4VectorFFT()
45 * LALInspiralWaveNormaliseLSO()
46 * LALInspiralWaveCorrelate()
47 * \endcode
48 *
49 * ### Notes ###
50 *
51 */
52#include <lal/LALNoiseModelsInspiral.h>
53#include <lal/LALNoiseModels.h>
54
55/* Routine to compute a vector that is orthogonal to the input vector
56 * without changing its norm by multiplying with e^(i pi/2); Assumes
57 * that the input vector is the Fourier transform with the positive
58 * and negative frequencies pairs arranged as in fftw: f[i] <->f[ n-i].
59 */
60
62{
63 int i,n,nby2;
64
65 n = filter1->length;
66 nby2 = n/2;
67 filter2->data[0] = filter1->data[0];
68 filter2->data[nby2] = filter1->data[nby2];
69 for (i=1; i<nby2; i++)
70 {
71 filter2->data[i] = -filter1->data[n-i];
72 filter2->data[n-i] = filter1->data[i];
73 }
74}
75
76
77void
79 (
81 REAL4Vector *output,
82 InspiralWaveOverlapOut *overlapout,
83 InspiralWaveOverlapIn *overlapin
84 )
85{
86 REAL4Vector filter1, filter2, output1, output2;
88 REAL8 norm, x, y, z, phase;
89 INT4 i, nBegin, nEnd;
91
94
95 ASSERT (output->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
96 ASSERT (overlapin->psd.data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
97 ASSERT (overlapin->signal.data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
98 ASSERT (overlapin->ifExtOutput <= 1, status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
99
100 output1.length = output2.length = overlapin->signal.length;
101 filter1.length = filter2.length = overlapin->signal.length;
102
103 /* Allocate memory to all temporary arrays */
104 if (!(output1.data = (REAL4*) LALMalloc(sizeof(REAL4)*output1.length))) {
105 ABORT (status, LALNOISEMODELSH_EMEM, LALNOISEMODELSH_MSGEMEM);
106 }
107 if (!(output2.data = (REAL4*) LALMalloc(sizeof(REAL4)*output2.length))) {
108 LALFree(output1.data);
109 output1.data = NULL;
110 ABORT (status, LALNOISEMODELSH_EMEM, LALNOISEMODELSH_MSGEMEM);
111 }
112 if (!(filter1.data = (REAL4*) LALMalloc(sizeof(REAL4)*filter1.length))) {
113 LALFree(output1.data);
114 LALFree(output2.data);
115 output1.data = NULL;
116 output2.data = NULL;
117 ABORT (status, LALNOISEMODELSH_EMEM, LALNOISEMODELSH_MSGEMEM);
118 }
119 if (!(filter2.data = (REAL4*) LALMalloc(sizeof(REAL4)*filter2.length))) {
120 LALFree(output1.data);
121 LALFree(output2.data);
122 LALFree(filter1.data);
123 output1.data = NULL;
124 output2.data = NULL;
125 filter1.data = NULL;
126 ABORT (status, LALNOISEMODELSH_EMEM, LALNOISEMODELSH_MSGEMEM);
127 }
128
129 /*
130 * Generate the required template
131 */
132 overlapin->param.nStartPad = 0;
133 switch (overlapin->param.approximant)
134 {
135 case AmpCorPPN:
136 case TaylorT1:
137 case TaylorT2:
138 case TaylorT3:
139 case PadeT1:
140 case EOB:
141 case EOBNR:
142 case TaylorEt:
143 case TaylorT4:
144 case TaylorN:
145 case SpinTaylorT3:
146 case SpinTaylor:
147 /*
148 * Generate only 0-phase template, pi/2-template can be generated by
149 * multiplying the 0-phase template with i=e^(i pi/2).
150 */
151 overlapin->param.startPhase = 0.;
152 LALInspiralWave(status->statusPtr, &output1, &overlapin->param);
154
155 /*
156 * When the approximant is AmpCorPPN, TaylorT1, TaylorT2, TaylorT3, PadeT1 or EOB
157 * (time domain waveform) generate the template and take its FT
158 */
159 if (XLALREAL4VectorFFT(&filter1, &output1, overlapin->fwdp)!= 0)
161
162 break;
163 case Eccentricity:
164 /* we do not want to impose the startPhase to be zero so as
165 * to be able to test the overlap for different values of
166 * starting phase*/
167 LALInspiralWave(status->statusPtr, &output1, &overlapin->param);
169 if (XLALREAL4VectorFFT(&filter1, &output1, overlapin->fwdp) != 0)
171 break;
172 /* commented section to inject a particular waveform containing a combinaison
173 * of F+, Fx, h+ and hx, not just F+h+
174 * */
175 #if 0
176 {
177 REAL8 t, p, s, a1, a2, phi, phi0, shift;
178 REAL8 fp, fc, hp, hc;
179 INT4 kk;
180 t = cos(overlapin->param.sourceTheta);
181 p = 2. * overlapin->param.sourcePhi;
182 s = 2. * overlapin->param.polarisationAngle;
183 fp = 0.5*(1 + t*t)*cos(p)*cos(s) - t*sin(p)*sin(s);
184 fc = 0.5*(1 + t*t)*cos(p)*sin(s) + t*sin(p)*cos(s);
185 for (kk=0; kk < output1.length; kk++)
186 {
187 output1.data[kk] = output1.data[kk]*fp + output2.data[kk]*fc;
188 }
189 }
190 if (XLALREAL4VectorFFT(&filter1, &output1, overlapin->fwdp) != 0)
192
193 break;
194 #endif
195
196 case TaylorF1:
197 case TaylorF2:
198 case BCV:
199 case BCVSpin:
200
201 overlapin->param.startPhase = 0.;
202 LALInspiralWave(status->statusPtr, &filter1, &overlapin->param);
204
205
206
207 /*
208 * When the approximant is BCV, BCVSpin, TaylorF1 or TaylorF2
209 * no FT is needed as the approximant generates signal in the Fourier domain.
210 */
211
212 /* print out for debugging
213 for (i=0; i<output1.length; i++) printf("%d %e %e\n", i, output1.data[i], output2.data[i]);
214 if (XLALREAL4VectorFFT(&filter1, &output1, overlapin->fwdp) != 0)
215 ABORTXLAL(status);
216 if (XLALREAL4VectorFFT(&filter2, &output2, overlapin->fwdp) != 0)
217 ABORTXLAL(status);
218 */
219 break;
220 default:
222 {
223 LALInfo(status, "Invalid choice of approximant\n");
224 LALPrintError("\tInvalid choice of approximant\n");
225 }
226 break;
227
228 }
229 /* Normalise the template just created */
230 normin.psd = &(overlapin->psd);
231 normin.df = overlapin->param.tSampling / (REAL8) overlapin->signal.length;
232 normin.fCutoff = overlapin->param.fFinal;
233 normin.samplingRate = overlapin->param.tSampling;
234 LALInspiralWaveNormaliseLSO(status->statusPtr, &filter1, &norm, &normin);
236
237 /* Get the template orthogonal to the normalized template just created */
238 LALInspiralGetOrthoNormalFilter(&filter2, &filter1);
240 /* Compute the overlap of the two orthonormal templates with the signal in corrin */
241 corrin.fCutoff = overlapin->param.fFinal;
242 corrin.samplingRate = overlapin->param.tSampling;
243 corrin.df = overlapin->param.tSampling / (REAL8) overlapin->signal.length;
244 corrin.psd = overlapin->psd;
245 corrin.signal1 = overlapin->signal;
246 corrin.signal2 = filter1;
247 corrin.revp = overlapin->revp;
248 LALInspiralWaveCorrelate(status->statusPtr, &output1, corrin);
250 corrin.signal2 = filter2;
251 LALInspiralWaveCorrelate(status->statusPtr, &output2, corrin);
253
254 /* Compute the maximum of the overlap by adding the two correlations in quadrature */
255 nBegin = overlapin->nBegin;
256 nEnd = output1.length - overlapin->nEnd;
257 x = output1.data[nBegin];
258 y = output2.data[nBegin];
259 overlapout->max = x*x + y*y;
260 overlapout->bin = nBegin;
261 overlapout->phase = atan2(y,x);
262 for (i=nBegin; i<nEnd; i++) {
263 x = output1.data[i];
264 y = output2.data[i];
265 z = x*x + y*y;
266 if (z>overlapout->max) {
267 overlapout->max = z;
268 overlapout->bin = i;
269 overlapout->phase = atan2(y,x);
270 }
271 }
272
273 phase = overlapout->phase;
274
275
276
277
278 /* If an extended output is not requested - then just fill out the output
279 * (as before). This can be indicated by setting overlapin->ifExtOutput to zero
280 * */
281
282 if ( !(overlapin->ifExtOutput) )
283 {
284 /* No xcorrelation or filters requested on output - so just fill out
285 * output vector and exit
286 * */
287 if ( overlapin->ifCorrelationOutput )
288 {
289 for (i=0; i<(int)output->length; i++)
290 {
291 output->data[i] = sqrt( output1.data[i] * output1.data[i] +
292 output2.data[i] * output2.data[i]);
293 }
294 }
295 else
296 {
297 for (i=0; i<(int)output->length; i++)
298 {
299 output->data[i] =
300 cos(phase) * output1.data[i] + sin(phase) * output2.data[i];
301 }
302 }
303 }
304 else {
305
306 /* Else we assume that all of them are requested to be output. Eventually we
307 * would want the freedom to output any one of the 4 vectors but right now we
308 * output all the four together
309 * */
310
311 /* Check that the space has been allocated to recv the xcorr and filters */
312 ASSERT (overlapout->xcorr1->length == overlapin->signal.length,
313 status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
314 ASSERT (overlapout->xcorr1->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
315
316 ASSERT (overlapout->xcorr2->length == overlapin->signal.length,
317 status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
318 ASSERT (overlapout->xcorr2->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
319
320 ASSERT (overlapout->filter1->length == overlapin->signal.length,
321 status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
322 ASSERT (overlapout->filter1->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
323
324 ASSERT (overlapout->filter2->length == overlapin->signal.length,
325 status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
326 ASSERT (overlapout->filter2->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
327
328 /* Now fill everything in the extended output */
329 for (i=0; i<(int)output->length; i++) {
330 output->data[i] = cos(phase) * output1.data[i]
331 + sin(phase) * output2.data[i];
332
333 overlapout->xcorr1->data[i] = output1.data[i];
334 overlapout->xcorr2->data[i] = output2.data[i];
335 overlapout->filter1->data[i] = filter1.data[i];
336 overlapout->filter2->data[i] = filter2.data[i];
337 }
338 }
339
340 overlapout->max = sqrt(overlapout->max);
341
342
343 if (filter1.data!=NULL) LALFree(filter1.data);
344 if (filter2.data!=NULL) LALFree(filter2.data);
345 if (output1.data!=NULL) LALFree(output1.data);
346 if (output2.data!=NULL) LALFree(output2.data);
347
349 RETURN(status);
350}
void LALInspiralWave(LALStatus *status, REAL4Vector *signalvec, InspiralTemplate *params)
void LALInspiralWaveCorrelate(LALStatus *status, REAL4Vector *output, InspiralWaveCorrelateIn corrin)
void LALInspiralWaveNormaliseLSO(LALStatus *status, REAL4Vector *filter, REAL8 *norm, InspiralWaveNormaliseIn *in)
void LALInspiralWaveOverlap(LALStatus *status, REAL4Vector *output, InspiralWaveOverlapOut *overlapout, InspiralWaveOverlapIn *overlapin)
static void LALInspiralGetOrthoNormalFilter(REAL4Vector *filter2, REAL4Vector *filter1)
#define LALMalloc(n)
#define LALFree(p)
#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)
#define ABORTXLAL(sp)
int s
double i
const double a2
double REAL8
int32_t INT4
float REAL4
#define lalDebugLevel
LALINFO
int LALInfo(LALStatus *status, const char *info)
int LALPrintError(const char *fmt,...)
#define LALNOISEMODELSH_ENULL
#define LALNOISEMODELSH_EMEM
#define LALNOISEMODELSH_ESIZE
EOB
PadeT1
TaylorEt
BCVSpin
TaylorN
Eccentricity
EOBNR
AmpCorPPN
TaylorF1
TaylorT3
TaylorT4
TaylorF2
BCV
TaylorT1
SpinTaylor
SpinTaylorT3
TaylorT2
int XLALREAL4VectorFFT(REAL4Vector *_LAL_RESTRICT_ output, const REAL4Vector *_LAL_RESTRICT_ input, const REAL4FFTPlan *plan)
list y
int n
p
x
Approximant approximant
Post-Newtonain approximant to be used in generating the wave (input)
Definition: LALInspiral.h:208
INT4 nStartPad
Number of leading elements in the signal generation to be set to zero (input) If template is requeste...
Definition: LALInspiral.h:307
REAL8 startPhase
starting phase of the waveform in radians (input)
Definition: LALInspiral.h:221
REAL8 sourcePhi
Azimuth angle in the direction to the source.
Definition: LALInspiral.h:268
REAL8 polarisationAngle
Definition: LALInspiral.h:269
REAL8 fFinal
final frequency reached, in units of Hz (output)
Definition: LALInspiral.h:293
REAL8 tSampling
Sampling rate in Hz (input)
Definition: LALInspiral.h:218
REAL8 sourceTheta
Co-latitute in the direction to the source.
Definition: LALInspiral.h:267
REAL4 * data
REAL8 * data
FILE * fp
char output[FILENAME_MAX]