Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
PeakSelect.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2005 Badri Krishnan, Alicia Sintes
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 * \file PeakSelect.c
22 * \ingroup lalpulsar_bin_Hough
23 * \author Sintes, A.M. and Krishnan, B.
24 * \brief Functions for selecting peaks from SFTs.
25 *
26 * History: Created by Sintes May 21, 2003
27 * Modified by Krishnan Oct, 2005
28 *
29 * ### PeakSelect.c ###
30 *
31 * Routines for reading SFT binary files
32 *
33 * ### Prototypes ###
34 *
35 * <tt>PeakSelectHeader1()</tt>
36 *
37 * ### Description ###
38 *
39 * the output of the periodogram should be properly normalized !!!
40 *
41 * ### Uses ###
42 *
43 * \code
44 * LALHO()
45 * \endcode
46 */
47
48#include "PeakSelect.h"
49
50/*
51 * The functions that make up the guts of this module
52 */
53
54/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
55
57 REAL8 *mean,
58 REAL8Periodogram1 *peri )
59{
60
61 INT4 length;
62 REAL8 sum;
63
64 /* --------------------------------------------- */
67
68 /* Make sure the arguments are not NULL: */
71
72 length = peri->length;
73 sum = 0.0;
74
75 if ( length > 0 ) {
76 REAL8 *in1;
77 INT4 n;
79 in1 = peri->data;
80 n = length;
81 while ( n-- > 0 ) {
82 sum += *in1;
83 ++in1;
84 }
85 sum = sum / length;
86 }
87
88 *mean = sum;
89
91 /* normal exit */
92 RETURN( status );
93}
94
95/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
96
98 UCHARPeakGram *pg,
99 REAL8 *thr,
100 REAL8Periodogram1 *peri )
101{
102
103
104 INT4 length;
105 INT4 nPeaks;
106
107 /* --------------------------------------------- */
110
111 /* Make sure the arguments are not NULL: */
115
116 pg->epoch.gpsSeconds = peri->epoch.gpsSeconds;
118 pg->timeBase = peri->timeBase;
119 pg->fminBinIndex = peri->fminBinIndex;
120
121 length = peri->length;
122 nPeaks = 0;
123
125
126 if ( length > 0 ) {
127 UCHAR *out;
128 REAL8 *in1;
129 REAL8 threshold;
130 INT4 n;
131
134 out = pg->data;
135 in1 = peri->data;
136 threshold = *thr;
137 n = length;
138
139 while ( n-- > 0 ) {
140 if ( *in1 > threshold ) {
141 *out = 1 ;
142 nPeaks++ ;
143 } else {
144 *out = 0;
145 }
146 ++out;
147 ++in1;
148 }
149 }
150
151 pg->nPeaks = nPeaks;
152
154 /* normal exit */
155 RETURN( status );
156}
157
158/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
159
161 HOUGHPeakGram *pgOut,
162 UCHARPeakGram *pgIn )
163{
164
165 INT4 length;
166 UINT4 nPeaks;
167
168 /* --------------------------------------------- */
171
172 /* Make sure the arguments are not NULL: */
175
176 length = pgIn->length;
177 pgOut->deltaF = 1. / pgIn->timeBase;
178 pgOut->fBinIni = pgIn->fminBinIndex;
179 pgOut->fBinFin = pgOut->fBinIni + length - 1;
180
181 nPeaks = pgIn->nPeaks;
183
184 if ( nPeaks > 0 ) {
185 INT4 *peak;
186 UCHAR *in1;
187 INT4 i;
188
191 peak = pgOut->peak;
192 in1 = pgIn->data;
193
194 for ( i = 0; i < length; i++ ) {
195 if ( *in1 ) {
196 *peak = i;
197 ++peak;
198 }
199 ++in1;
200 }
201 }
202
204 /* normal exit */
205 RETURN( status );
206}
207/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
208
209
210/******************************************************************/
211/* estimate psd from periodogram using runing-median */
212/* this is just a wrapper to Mohanty's rngmed */
213/******************************************************************/
214
217 REAL8Periodogram1 *peri,
218 INT4 *blocksRNG )
219{
220
221 INT4 length, j;
222 UINT2 blockSize, nblocks2;
223 REAL8 *medians;
224 LALRunningMedianPar rngmedPar;
225 REAL8Sequence mediansV;
226 REAL8Sequence inputV;
227
228
229 /* --------------------------------------------- */
232
233 /* Make sure the arguments are not NULL: */
237
238 psd->epoch.gpsSeconds = peri->epoch.gpsSeconds;
239 psd->epoch.gpsNanoSeconds = peri->epoch.gpsNanoSeconds;
240 psd->timeBase = peri->timeBase;
241 psd->fminBinIndex = peri->fminBinIndex;
242
243 length = peri->length;
244 blockSize = *blocksRNG;
245
246 ASSERT( length == psd->length, status, PEAKSELECTH_EVAL, PEAKSELECTH_MSGEVAL );
248 ASSERT( blockSize <= length, status, PEAKSELECTH_EVAL, PEAKSELECTH_MSGEVAL );
249
250 if ( length > 0 ) {
253
254 nblocks2 = floor( blockSize / 2.0 );
255
256 medians = psd->data + nblocks2;
257
258 rngmedPar.blocksize = ( UINT4 )blockSize;
259 inputV.length = length;
260 inputV.data = peri->data;
261 mediansV.length = length - blockSize + 1;
262 mediansV.data = psd->data + nblocks2;
263
264 /* calling Mohanty's function. It is not LAL compliant */
265 /*rngmed(data, length, blockSize, medians); */
266 /* this now calls Bernd's functions since other one is buggy */
267 TRY( LALDRunningMedian2( status->statusPtr,
268 &mediansV, &inputV, rngmedPar ), status );
269
270
271 for ( j = 0; j < nblocks2 ; ++j ) {
272 psd->data[j] = medians[0];
273 }
274 for ( j = nblocks2 + length - blockSize + 1; j < length ; ++j ) {
275 psd->data[j] = medians[length - blockSize];
276 }
277 }
278
280 /* normal exit */
281 RETURN( status );
282}
283
284/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
285
287 UCHARPeakGram *pg,
288 REAL8 *thr,
289 REAL8PeriodoPSD *in )
290{
291
292 INT4 length;
293 INT4 nPeaks;
294
295 /* --------------------------------------------- */
298
299 /* Make sure the arguments are not NULL: */
303
304 /* check that the psd and periodogram are consistent */
310
311
314 pg->timeBase = in->psd.timeBase;
315 pg->fminBinIndex = in->psd.fminBinIndex;
316
317 length = in->psd.length;
318
319 /* make sure that the length of the peakgram is consistent */
321
322 nPeaks = 0;
323
324 if ( length > 0 ) {
325 UCHAR *out;
326 REAL8 *psd;
327 REAL8 *peri;
328 REAL8 threshold;
329 INT4 n;
330
334
335 out = pg->data;
336 peri = in->periodogram.data;
337 psd = in->psd.data;
338
339 threshold = *thr;
340 n = length;
341
342 while ( n-- > 0 ) {
343 if ( *peri > threshold * ( *psd ) ) {
344 *out = 1 ;
345 nPeaks++ ;
346 } else {
347 *out = 0;
348 }
349 ++out;
350 ++psd;
351 ++peri;
352 }
353
354 }
355
356 pg->nPeaks = nPeaks;
357
359 /* normal exit */
360 RETURN( status );
361}
362/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
363
364
365
366/**
367 * Convert a normalized sft into a peakgram by selecting bins in
368 * which power exceeds a threshold.
369 */
370
372 UCHARPeakGram *pg,
373 const SFTtype *sft,
374 REAL8 thr )
375{
376
377 INT4 length;
378 INT4 nPeaks;
379 REAL8 f0, deltaF;
380 REAL8FrequencySeries periodo;
381
382 /* --------------------------------------------- */
385
386 /* Make sure the arguments are not NULL: */
389
390
391 pg->epoch.gpsSeconds = sft->epoch.gpsSeconds;
393 deltaF = sft->deltaF;
394 f0 = sft->f0;
395 pg->timeBase = 1.0 / deltaF;
396 pg->fminBinIndex = floor( f0 / deltaF + 0.5 );
397 length = sft->data->length;
398
399 /* make sure that the length of the peakgram is consistent */
401
402 /* allocate memory for normalized periodogram */
403 periodo.data = NULL;
404 periodo.data = ( REAL8Sequence * )LALMalloc( sizeof( REAL8Sequence ) );
405 periodo.data->length = length;
406 periodo.data->data = ( REAL8 * )LALMalloc( length * sizeof( REAL8 ) );
407
409
410 nPeaks = 0;
411 if ( length > 0 ) {
412 UCHAR *out;
413 REAL8 *peri;
414 INT4 n;
415
417
418 out = pg->data;
419 peri = periodo.data->data;
420
421 n = length;
422
423 while ( n-- > 0 ) {
424 if ( *peri > thr ) {
425 *out = 1 ;
426 nPeaks++ ;
427 } else {
428 *out = 0;
429 }
430 ++out;
431 ++peri;
432 } /* end loop over n */
433 }/* end if statement */
434
435 pg->nPeaks = nPeaks;
436
437 LALFree( periodo.data->data );
438 LALFree( periodo.data );
439
441 /* normal exit */
442 RETURN( status );
443}
int j
#define LALMalloc(n)
#define LALFree(p)
#define XLAL_CHECK_LAL(sp, assertion,...)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
void LALSelectPeakColorNoise(LALStatus *status, UCHARPeakGram *pg, REAL8 *thr, REAL8PeriodoPSD *in)
Function for selecting peaks in colored noise – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:286
void LALPeriodo2PSDrng(LALStatus *status, REAL8Periodogram1 *psd, REAL8Periodogram1 *peri, INT4 *blocksRNG)
Wrapper for LALRunningMedian code – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:215
void LALUCHAR2HOUGHPeak(LALStatus *status, HOUGHPeakGram *pgOut, UCHARPeakGram *pgIn)
Compress explicit peak gram.
Definition: PeakSelect.c:160
void SFTtoUCHARPeakGram(LALStatus *status, UCHARPeakGram *pg, const SFTtype *sft, REAL8 thr)
Convert a normalized sft into a peakgram by selecting bins in which power exceeds a threshold.
Definition: PeakSelect.c:371
void LALComputeMeanPower(LALStatus *status, REAL8 *mean, REAL8Periodogram1 *peri)
to compute mean power from a periodogram – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:56
void LALSelectPeakWhiteNoise(LALStatus *status, UCHARPeakGram *pg, REAL8 *thr, REAL8Periodogram1 *peri)
select peakgram in white noise – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:97
Header file for PeakSelect.c.
#define PEAKSELECTH_MSGENULL
Definition: PeakSelect.h:91
#define PEAKSELECTH_ENULL
Definition: PeakSelect.h:88
#define PEAKSELECTH_EVAL
Definition: PeakSelect.h:89
#define PEAKSELECTH_MSGEVAL
Definition: PeakSelect.h:92
unsigned char UCHAR
double REAL8
uint16_t UINT2
uint32_t UINT4
int32_t INT4
void LALDRunningMedian2(LALStatus *status, REAL8Sequence *medians, const REAL8Sequence *input, LALRunningMedianPar param)
int XLALSFTtoPeriodogram(REAL8FrequencySeries *periodo, const COMPLEX8FrequencySeries *SFT)
Calculate the "periodogram" of an SFT, ie the modulus-squares of the SFT-data.
XLAL_SUCCESS
XLAL_EFUNC
n
out
psd
int deltaF
COMPLEX8Sequence * data
This structure stores the `‘peak-gram’'.
Definition: PHMD.h:129
REAL8 deltaF
Frequency resolution: df=1/TCOH
Definition: PHMD.h:131
UINT4 length
Number of peaks present in the peak-gram.
Definition: PHMD.h:134
UINT8 fBinFin
Frequency index of the last element of the spectrum covered by this peak-gram.
Definition: PHMD.h:133
UINT8 fBinIni
Frequency index of the first element of the spectrum covered by this peak-gram; it can be seen as an ...
Definition: PHMD.h:132
INT4 * peak
The peak indices relative to fBinIni, i.e., the zero peak corresponds to fBinIni.
Definition: PHMD.h:135
INT4 gpsNanoSeconds
REAL8Sequence * data
structure containing psd and periodogram of a sft – obsolete – use LAL functions
Definition: PeakSelect.h:124
REAL8Periodogram1 periodogram
Definition: PeakSelect.h:126
REAL8Periodogram1 psd
Definition: PeakSelect.h:125
REAL8 timeBase
Definition: SFTbin.h:160
LIGOTimeGPS epoch
Definition: SFTbin.h:159
INT4 fminBinIndex
Definition: SFTbin.h:161
REAL8 * data
Definition: SFTbin.h:163
REAL8 * data
Explicit peakgram structure – 1 if power in bin is above threshold and 0 if below.
Definition: PeakSelect.h:114
UCHAR * data
pointer to the data {0,1}
Definition: PeakSelect.h:120
LIGOTimeGPS epoch
epoch of first series sample
Definition: PeakSelect.h:115
REAL8 timeBase
coherent time baseline used to construct peakgram
Definition: PeakSelect.h:116
INT4 nPeaks
number of peaks selected in data
Definition: PeakSelect.h:119
INT4 length
number of elements in data
Definition: PeakSelect.h:118
INT4 fminBinIndex
first frequency bin of peakgram
Definition: PeakSelect.h:117