25#include <lal/LALStdlib.h>
26#include <lal/LALStdio.h>
28#include <lal/AVFactories.h>
29#include <lal/TimeFreqFFT.h>
30#include <lal/RealFFT.h>
31#include <lal/Window.h>
32#include <lal/LIGOMetadataRingdownUtils.h>
38#define UNUSED __attribute__ ((unused))
47 REAL8 segmentDuration,
49 REAL4FFTPlan *fwdPlan,
59 segmentLength = floor( segmentDuration/
series->deltaT + 0.5 );
60 segmentStride = floor( strideDuration/
series->deltaT + 0.5 );
62 spectrum =
LALCalloc( 1,
sizeof( *spectrum ) );
71 spec = 2.0 *
series->deltaT;
72 verbose(
"creating white spectrum with constant value %g\n", spec );
76 spectrum->
data->
data[0] = 2.0 * spec;
79 spectrum->
deltaF = 1.0/segmentDuration;
83 switch ( spectrumAlgthm )
86 verbose(
"estimating average spectrum using median method\n" );
88 segmentStride, window, fwdPlan );
91 verbose(
"estimating average spectrum using median-mean method\n" );
93 segmentStride, window, fwdPlan );
96 error(
"unrecognized injection signal type\n" );
108 REAL8 segmentDuration
113 REAL8 origDeltaF,rsmplDeltaF;
114 REAL8 currF,belowF,aboveF,belowWeight,aboveWeight,currPower;
118 segmentLength = floor( segmentDuration*
sampleRate + 0.5 );
119 rsmplspectrum =
LALCalloc( 1,
sizeof( *rsmplspectrum ) );
122 origDeltaF = origspectrum->
deltaF;
123 rsmplDeltaF = 1.0/segmentDuration;
125 rsmplspectrum->
f0 = origspectrum->
f0;
126 rsmplspectrum->
deltaF = rsmplDeltaF;
128 if((
int)
sizeof(rsmplspectrum->
name) <= snprintf( rsmplspectrum->
name,
sizeof( rsmplspectrum->
name ),
129 "%s_RSMPL", origspectrum->
name))
132 for (
k=0;
k < segmentLength/2 + 1;
k++)
134 currF =
k * rsmplDeltaF;
135 belowK = floor( currF / origDeltaF);
136 aboveK = ceil( currF / origDeltaF);
137 belowF = belowK * origDeltaF;
138 aboveF = aboveK * origDeltaF;
151 if (aboveK - belowK == 0)
158 belowWeight = (currF - belowF) / (aboveF - belowF);
159 aboveWeight = (aboveF - currF) / (aboveF - belowF);
163 currPower = origspectrum->
data->
data[belowK] * belowWeight;
164 currPower += origspectrum->
data->
data[aboveK] * aboveWeight;
165 rsmplspectrum->
data->
data[
k] = currPower;
171 return rsmplspectrum;
176 REAL8 segmentDuration,
177 UINT4 spectrumNumber,
184 segmentLength = floor( segmentDuration/
deltaT + 0.5 );
186 spectrum =
LALCalloc( 1,
sizeof( *spectrum ) );
189 spectrum->
deltaF = 1.0/segmentDuration;
196 verbose(
"creating white PSD with constant value %g\n", spec * simScale * simScale );
198 spectrum->
data->
data[
k] = spec * simScale * simScale;
202 snprintf( spectrum->
name,
sizeof( spectrum->
name ),
207 verbose(
"Creating initial LIGO PSD. PSD only generated from 30Hz \n" );
211 snprintf( spectrum->
name,
sizeof( spectrum->
name ),
216 verbose(
"Creating advanced LIGO high-power broad-band signal recycling "
217 "PSD. PSD only generated from 10Hz \n ");
220 snprintf( spectrum->
name,
sizeof( spectrum->
name ),
225 fprintf(stderr,
"Spectrum number not valid. This message should not be seen."
226 " Have you broken the code?? \n");
239 REAL8 dataSampleRate,
240 REAL8 UNUSED strideDuration,
241 REAL8 truncateDuration,
242 REAL8 lowCutoffFrequency,
243 REAL4FFTPlan *fwdPlan,
244 REAL4FFTPlan *revPlan
247 REAL8 segmentDuration;
249 UINT4 UNUSED segmentStride;
250 UINT4 truncateLength;
252 segmentDuration = 1.0/spectrum->
deltaF;
253 segmentLength = floor( segmentDuration * dataSampleRate + 0.5 );
254 segmentStride = floor( strideDuration * dataSampleRate + 0.5 );
255 if ( truncateDuration > 0.0 )
256 truncateLength = floor( truncateDuration * dataSampleRate + 0.5 );
260 verbose(
"computing inverse spectrum with truncation length %d\n",
264 segmentLength, truncateLength, fwdPlan, revPlan );
274 REAL8 lowCutoffFrequency,
285 if ( lowCutoffFrequency > 0.0 )
286 cut = lowCutoffFrequency / spectrum->
deltaF;
297 spectrum->
data->
data[
k] /= (re*re + im*im );
308 spectrum->
data->
data[
k] *= (re*re + im*im );
#define sanity_check(condition)
int error(const char *fmt,...)
double XLALSimNoisePSDaLIGOZeroDetHighPower(double f)
int XLALSimNoisePSD(REAL8FrequencySeries *psd, double flow, double(*psdfunc)(double))
double XLALSimNoisePSDiLIGOSRD(double f)
int XLALStringPrint(char *s, size_t n, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(3
int XLALREAL4AverageSpectrumMedian(REAL4FrequencySeries *spectrum, const REAL4TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL4Window *window, const REAL4FFTPlan *plan)
int XLALREAL4AverageSpectrumMedianMean(REAL4FrequencySeries *spectrum, const REAL4TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL4Window *window, const REAL4FFTPlan *plan)
int XLALREAL4SpectrumInvertTruncate(REAL4FrequencySeries *spectrum, REAL4 lowfreq, UINT4 seglen, UINT4 trunclen, REAL4FFTPlan *fwdplan, REAL4FFTPlan *revplan)
LALUnit * XLALUnitDivide(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
LALUnit * XLALUnitMultiply(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL4Window(REAL4Window *window)
REAL4Window * XLALCreateWelchREAL4Window(UINT4 length)
#define XLAL_ERROR_NULL(...)
char name[LIGOMETA_SOURCE_MAX]
int calibrate_spectrum(REAL4FrequencySeries *spectrum, COMPLEX8FrequencySeries *response, REAL8 lowCutoffFrequency, int inverse)
REAL4FrequencySeries * resample_psd(REAL4FrequencySeries *origspectrum, REAL8 sampleRate, REAL8 segmentDuration)
REAL8FrequencySeries * generate_theoretical_psd(REAL4 deltaT, REAL8 segmentDuration, UINT4 spectrumNumber, REAL8 simScale)
int invert_spectrum(REAL4FrequencySeries *spectrum, REAL8 dataSampleRate, REAL8 UNUSED strideDuration, REAL8 truncateDuration, REAL8 lowCutoffFrequency, REAL4FFTPlan *fwdPlan, REAL4FFTPlan *revPlan)
REAL4FrequencySeries * compute_average_spectrum(REAL4TimeSeries *series, int spectrumAlgthm, REAL8 segmentDuration, REAL8 strideDuration, REAL4FFTPlan *fwdPlan, int whiteSpectrum)