Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VectorPolar.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Alicia Sintes Olives
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/LALConstants.h>
24#include <lal/VectorOps.h>
25
26/**
27 * \addtogroup VectorPolar_c
28 * \author T. D. Creighton, A. M. Sintes
29 *
30 * \brief Convert complex vector components from rectangular coordinates to polar coordinates.
31 *
32 * Let \c u be an object of type \c COMPLEX8Vector, and let
33 * \c a and \c b be objects of type \c REAL4Vector.
34 *
35 * The \ref LALCVectorAbs "LALCVectorAbs( &status, &a, &u )" function computes
36 * the magnitude of a complex vector \c u:<br>
37 * <tt>a.data[i] = sqrt(u.data[i].re^2 + v.data[i].im^2 )</tt>.
38 *
39 * The \ref LALCVectorAngle "LALCVectorAngle( &status, &a, &u )" function computes
40 * the phase angle of a complex vector \c u
41 * in the interval \f$[-\pi, \pi]\f$ radians:<br>
42 * <tt>a.data[i] = atan2( u.data[i].im, v.data[i].re)</tt>.
43 *
44 * The \ref LALUnwrapREAL4Angle "LALUnwrapREAL4Angle( &status, &a, &b )" function
45 * corrects the radian phase angles of a real vector \c b
46 * by adding multiples of
47 * \f$\pm\pi\f$ when the absolute jumps between consecutive
48 * angle elements are greater than \f$\pi\f$ radians.
49 * This function detects branch cut crossings, but it can be
50 * fooled by sparse, rapidly changing phase values.
51 *
52 * The double-precision functions are similar.
53 *
54 * ### Algorithm ###
55 *
56 * The algorithm for LALUnwrapREAL4Angle() and LALUnwrapREAL8Angle()
57 * (Inspired from the MATLAP function unwrap):
58 * \code
59 *
60 * a = in->data;
61 * b = out->data;
62 * n = out->length;
63 *
64 * cumsum = 0.0;
65 * phaseI = *a;
66 * *b = phaseI;
67 * --n;
68 *
69 * while (n-- > 0)
70 * {
71 * ++a;
72 * ++b;
73 * phaseII = *a;
74 * diffph = phaseII - phaseI;
75 * phaseI = phaseII;
76 *
77 * cumsum += LAL_TWOPI*( (diffph < - LAL_PI) - (diffph > LAL_PI) );
78 *
79 * *b= phaseII + cumsum;
80 * }
81 *
82 * \endcode
83 *
84 * ### Notes ###
85 *
86 * For the LALUnwrapREAL4Angle() and LALUnwrapREAL8Angle() functions, \c a,
87 * and \c b should not point to the same memory location (<tt>a != b</tt>).
88 */
89/** @{ */
90
91/** computes the magnitudes of a vector of complex numbers */
93{
94 UINT4 i;
95 if ( ! out || ! in )
97 if ( ! out->data || ! in->data )
99 if ( out->length != in->length )
101 for ( i = 0; i < in->length; ++i )
102 out->data[i] = cabsf( in->data[i] );
103 return 0;
104}
105
106/** computes the magnitudes of a vector of complex numbers */
108{
109 UINT4 i;
110 if ( ! out || ! in )
112 if ( ! out->data || ! in->data )
114 if ( out->length != in->length )
116 for ( i = 0; i < in->length; ++i )
117 out->data[i] = cabs( in->data[i] );
118 return 0;
119}
120
121
122/** computes the arguments of a vector of complex numbers */
124{
125 UINT4 i;
126 if ( ! out || ! in )
128 if ( ! out->data || ! in->data )
130 if ( out->length != in->length )
132 for ( i = 0; i < in->length; ++i )
133 out->data[i] = cargf( in->data[i] );
134 return 0;
135}
136
137/** computes the arguments of a vector of complex numbers */
139{
140 UINT4 i;
141 if ( ! out || ! in )
143 if ( ! out->data || ! in->data )
145 if ( out->length != in->length )
147 for ( i = 0; i < in->length; ++i )
148 out->data[i] = carg( in->data[i] );
149 return 0;
150}
151
152
153/**
154 * corrects the radian phase angles of a real vector by adding multiples of
155 * pi when the absolute jumps between consecutive angle elements are greater
156 * pi radians
157 */
159{
160 REAL4 prev;
161 REAL4 diff;
162 INT4 wrap;
163 UINT4 i;
164 if ( ! out || ! in )
166 if ( ! out->data || ! in->data || in->length == 0 )
168 if ( out->length != in->length )
170 wrap = 0;
171 prev = out->data[0] = in->data[0];
172 for ( i = 1; i < in->length; ++i ) {
173 diff = in->data[i] - prev;
174 prev = in->data[i];
175 wrap += (diff < -LAL_PI) - (diff > LAL_PI);
176 out->data[i] = in->data[i] + wrap * LAL_TWOPI;
177 }
178 return 0;
179}
180
181/**
182 * corrects the radian phase angles of a real vector by adding multiples of
183 * pi when the absolute jumps between consecutive angle elements are greater
184 * pi radians
185 */
187{
188 REAL8 prev;
189 REAL8 diff;
190 INT4 wrap;
191 UINT4 i;
192 if ( ! out || ! in )
194 if ( ! out->data || ! in->data || in->length == 0 )
196 if ( out->length != in->length )
198 wrap = 0;
199 prev = out->data[0] = in->data[0];
200 for ( i = 1; i < in->length; ++i ) {
201 diff = in->data[i] - prev;
202 prev = in->data[i];
203 wrap += (diff < -LAL_PI) - (diff > LAL_PI);
204 out->data[i] = in->data[i] + wrap * LAL_TWOPI;
205 }
206 return 0;
207}
208
209
210/** UNDOCUMENTED */
211void
214 REAL4Vector *out,
215 const COMPLEX8Vector *in
216 )
217{
219
220 /* Make sure the arguments are not NULL: */
223
224 /* Make sure the data pointers are not NULL: */
227
228 /* Make sure the size is correct (invalid input size): */
230
231 /* Make sure the lengths are the same (size mismatch): */
232 ASSERT (in->length == out->length, status,
234
235 XLALCOMPLEX8VectorAbs( out, in );
236
237 RETURN (status);
238}
239
240
241/** UNDOCUMENTED */
242void
245 REAL8Vector *out,
246 const COMPLEX16Vector *in
247 )
248{
250
251 /* Make sure the arguments are not NULL: */
254
255 /* Make sure the data pointers are not NULL: */
258
259 /* Make sure the size is correct (invalid input size): */
261
262 /* Make sure the lengths are the same (size mismatch): */
263 ASSERT (in->length == out->length, status,
265
266 XLALCOMPLEX16VectorAbs( out, in );
267
268 RETURN (status);
269}
270
271
272/** UNDOCUMENTED */
273void
276 REAL4Vector *out,
277 const COMPLEX8Vector *in
278 )
279{
281
282 /* Make sure the arguments are not NULL: */
285
286 /* Make sure the data pointers are not NULL: */
289
290 /* Make sure the size is correct (invalid input size): */
292
293 /* Make sure the lengths are the same (size mismatch): */
294 ASSERT (in->length == out->length, status,
296
297 XLALCOMPLEX8VectorArg( out, in );
298
299 RETURN (status);
300}
301
302
303/** UNDOCUMENTED */
304void
307 REAL8Vector *out,
308 const COMPLEX16Vector *in
309 )
310{
312
313 /* Make sure the arguments are not NULL: */
316
317 /* Make sure the data pointers are not NULL: */
320
321 /* Make sure the size is correct (invalid input size): */
323
324 /* Make sure the lengths are the same (size mismatch): */
325 ASSERT (in->length == out->length, status,
327
328 XLALCOMPLEX16VectorArg( out, in );
329
330 RETURN (status);
331}
332
333/** UNDOCUMENTED */
334void
337 REAL4Vector *out,
338 const REAL4Vector *in
339 )
340{
342
343 /* Make sure the arguments are not NULL: */
346
347 /* Make sure the data pointers are not NULL: */
350
351 /* Make sure the size is correct (invalid input size): */
353
354 /* Make sure the lengths are the same (size mismatch): */
355 ASSERT (in->length == out->length, status,
357
358 /* Make sure the arguments are not pointing to the same memory location */
360
362
363 RETURN (status);
364}
365
366/** UNDOCUMENTED */
367void
370 REAL8Vector *out,
371 const REAL8Vector *in
372 )
373{
375
376 /* Make sure the arguments are not NULL: */
379
380 /* Make sure the data pointers are not NULL: */
383
384 /* Make sure the size is correct (invalid input size): */
386
387 /* Make sure the lengths are the same (size mismatch): */
388 ASSERT (in->length == out->length, status,
390
391 /* Make sure the arguments are not pointing to the same memory location */
393
395
396 RETURN (status);
397}
398/** @} */
#define ASSERT(assertion, statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define VECTOROPSH_MSGESIZE
Definition: VectorOps.h:59
#define VECTOROPSH_MSGESAME
Definition: VectorOps.h:61
#define VECTOROPSH_MSGESZMM
Definition: VectorOps.h:60
#define VECTOROPSH_MSGENULL
Definition: VectorOps.h:58
#define LAL_PI
Archimedes's constant, pi.
Definition: LALConstants.h:179
#define LAL_TWOPI
2*pi is circumference of a circle divided by its radius
Definition: LALConstants.h:180
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).
#define VECTOROPSH_ESIZE
Invalid input size.
Definition: VectorOps.h:52
#define VECTOROPSH_ENULL
Null pointer.
Definition: VectorOps.h:51
#define VECTOROPSH_ESZMM
Size mismatch.
Definition: VectorOps.h:53
#define VECTOROPSH_ESAME
Input/Output data vectors are the same.
Definition: VectorOps.h:54
int XLALREAL8VectorUnwrapAngle(REAL8Vector *out, const REAL8Vector *in)
corrects the radian phase angles of a real vector by adding multiples of pi when the absolute jumps b...
Definition: VectorPolar.c:186
void LALCVectorAngle(LALStatus *status, REAL4Vector *out, const COMPLEX8Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:274
int XLALCOMPLEX16VectorArg(REAL8Vector *out, const COMPLEX16Vector *in)
computes the arguments of a vector of complex numbers
Definition: VectorPolar.c:138
void LALZVectorAngle(LALStatus *status, REAL8Vector *out, const COMPLEX16Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:305
int XLALCOMPLEX8VectorArg(REAL4Vector *out, const COMPLEX8Vector *in)
computes the arguments of a vector of complex numbers
Definition: VectorPolar.c:123
void LALUnwrapREAL8Angle(LALStatus *status, REAL8Vector *out, const REAL8Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:368
void LALZVectorAbs(LALStatus *status, REAL8Vector *out, const COMPLEX16Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:243
int XLALREAL4VectorUnwrapAngle(REAL4Vector *out, const REAL4Vector *in)
corrects the radian phase angles of a real vector by adding multiples of pi when the absolute jumps b...
Definition: VectorPolar.c:158
int XLALCOMPLEX16VectorAbs(REAL8Vector *out, const COMPLEX16Vector *in)
computes the magnitudes of a vector of complex numbers
Definition: VectorPolar.c:107
int XLALCOMPLEX8VectorAbs(REAL4Vector *out, const COMPLEX8Vector *in)
computes the magnitudes of a vector of complex numbers
Definition: VectorPolar.c:92
void LALCVectorAbs(LALStatus *status, REAL4Vector *out, const COMPLEX8Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:212
void LALUnwrapREAL4Angle(LALStatus *status, REAL4Vector *out, const REAL4Vector *in)
UNDOCUMENTED.
Definition: VectorPolar.c:335
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
Definition: XLALError.h:700
@ XLAL_EBADLEN
Inconsistent or invalid length.
Definition: XLALError.h:419
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:172
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:176
COMPLEX16 * data
Pointer to the data array.
Definition: LALDatatypes.h:177
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:163
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:167
COMPLEX8 * data
Pointer to the data array.
Definition: LALDatatypes.h:168
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158