LAL  7.5.0.1-8083555
LALColoredNoise.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 David Churches, Duncan Brown, Jolien Creighton, B.S. Sathyaprakash
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 <lal/LALNoiseModels.h>
21 
22 /**
23  * \author Sathyaprakash, B. S.
24  * \ingroup LALNoiseModels_h
25  * \brief This function colors a given white noise input into a colored noise
26  * of power spectral density \c psd.
27  *
28  * ### Description ###
29  *
30  * Given the Fourier transform \f$N(f)\f$ of white noise, the
31  * Fourier transform of noise of power spectral density \f$S(f)\f$ is
32  * given by \f${\cal N}(f) = N(f) \times \sqrt{S(f)}.\f$
33  * In the discrete version there is an additional normalisation:
34  * \f[{\cal N}_k = N_k \times \sqrt{\frac{2 S_k}{n}},\ \
35  * {\cal N}_{n-k} = N_{n-k} \times \sqrt{\frac{2 S_k}{n}},\ \
36  * k=1, \ldots, \frac{n}{2}.\f]
37  *
38  */
39 void
41  (
43  REAL4Vector *noisy,
44  REAL8Vector psd
45  )
46 {
47 
48  INT4 i, j, n, nby2;
49  REAL8 x, length;
50 
51 
54 
55  ASSERT (noisy, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
56  ASSERT (noisy->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
57  ASSERT (psd.data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
58  ASSERT (psd.length == noisy->length/2+1, status, LALNOISEMODELSH_ESIZE, LALNOISEMODELSH_MSGESIZE);
59 
60  n = length = noisy->length;
61  nby2 = n/2;
62 
63  for (i=1; i<nby2; i++)
64  {
65  j = n-i;
66  /* Since fftw requires n and NOT n/2, I presume we
67  don't need the factor 2 in the normalisation
68  x = sqrt(2. * psd.data[i] / length);
69  */
70  x = sqrt(2.*psd.data[i]);
71  noisy->data[i] *= x;
72  noisy->data[j] *= x;
73  }
74  x = sqrt(2.*psd.data[0]);
75  noisy->data[0] *= x;
76  x = sqrt(2.*psd.data[nby2]);
77  noisy->data[nby2] *= x;
78 
80  RETURN (status);
81 }
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
void LALColoredNoise(LALStatus *status, REAL4Vector *noisy, REAL8Vector psd)
This function colors a given white noise input into a colored noise of power spectral density psd.
#define LALNOISEMODELSH_ENULL
Arguments contained an unexpected null pointer.
#define LALNOISEMODELSH_ESIZE
Invalid input size.
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