static int compareFstatResults ( const FstatResults *result1, const FstatResults *result2 ) { XLAL_CHECK ( (result1 != NULL) && (result2 != NULL), XLAL_EINVAL ); XLAL_CHECK ( result1->whatWasComputed == result2->whatWasComputed, XLAL_EINVAL ); XLAL_CHECK ( result1->dFreq == result2->dFreq, XLAL_EINVAL ); XLAL_CHECK ( result1->numFreqBins == result2->numFreqBins, XLAL_EINVAL ); XLAL_CHECK ( result1->numDetectors == result2->numDetectors, XLAL_EINVAL ); // ----- set tolerance levels for comparisons ---------- VectorComparison XLAL_INIT_DECL(tol); tol.relErr_L1 = 2e-2; tol.relErr_L2 = 2e-2; tol.angleV = 0.02; // rad tol.relErr_atMaxAbsx = 2.1e-2; tol.relErr_atMaxAbsy = 2.1e-2; UINT4 numFreqBins = result1->numFreqBins; VectorComparison XLAL_INIT_DECL(cmp); if ( result1->whatWasComputed & FSTATQ_2F ) { // ----- package twoF arrays into REAL4Vectors REAL4Vector XLAL_INIT_DECL(v1); REAL4Vector XLAL_INIT_DECL(v2); v1.length = numFreqBins; v2.length = numFreqBins; v1.data = result1->twoF; v2.data = result2->twoF; XLALPrintInfo ("Comparing 2F values:\n"); XLAL_CHECK ( XLALCompareREAL4Vectors ( &cmp, &v1, &v2, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); } if ( result1->whatWasComputed & FSTATQ_FAFB ) { // ----- package Fa,Fb arrays int COMPLEX8Vectors COMPLEX8Vector XLAL_INIT_DECL(c1); COMPLEX8Vector XLAL_INIT_DECL(c2); c1.length = numFreqBins; c2.length = numFreqBins; // Fa c1.data = result1->Fa; c2.data = result2->Fa; XLALPrintInfo ("Comparing Fa values:\n"); XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, &c1, &c2, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); // FIXME: deactivated test // Fb c1.data = result1->Fb; c2.data = result2->Fb; XLALPrintInfo ("Comparing Fb values:\n"); XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, &c1, &c2, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); // FIXME: deactivated test } return XLAL_SUCCESS; } // compareFstatResults()
// compare two SFTs, return XLAL_SUCCESS if OK, error otherwise int XLALCompareSFTs ( const SFTtype *sft1, const SFTtype *sft2, const VectorComparison *tol ) { // check input sanity XLAL_CHECK ( sft1 != NULL, XLAL_EINVAL ); XLAL_CHECK ( sft2 != NULL, XLAL_EINVAL ); XLAL_CHECK ( tol != NULL, XLAL_EINVAL ); XLAL_CHECK ( XLALGPSCmp ( &(sft1->epoch), &(sft2->epoch) ) == 0, XLAL_ETOL ); REAL8 tolFreq = 10 * LAL_REAL8_EPS; REAL8 err_f0 = sft1->f0 - sft2->f0; XLAL_CHECK ( err_f0 < tolFreq, XLAL_ETOL, "f0_1 = %.16g, f0_2 = %.16g, relErr_f0 = %g (tol = %g)\n", sft1->f0, sft2->f0, err_f0, tolFreq ); REAL8 relErr_df = RELERR ( sft1->deltaF, sft2->deltaF ); XLAL_CHECK ( relErr_df < tolFreq, XLAL_ETOL, "dFreq1 = %g, dFreq2 = %g, relErr_df = %g (tol = %g)", sft1->deltaF, sft2->deltaF, relErr_df, tolFreq ); XLAL_CHECK ( XLALUnitCompare( &(sft1->sampleUnits), &(sft2->sampleUnits) ) == 0, XLAL_ETOL ); XLAL_CHECK ( sft1->data->length == sft2->data->length, XLAL_ETOL, "sft1->length = %d, sft2->length = %d\n", sft1->data->length, sft2->data->length ); VectorComparison XLAL_INIT_DECL(cmp); XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, sft1->data, sft2->data, tol ) == XLAL_SUCCESS, XLAL_EFUNC ); return XLAL_SUCCESS; } // XLALCompareSFTs()
int test_XLALSincInterpolateCOMPLEX8TimeSeries ( void ) { COMPLEX8TimeSeries* tsIn; REAL8 f0 = 100; // heterodyning frequency REAL8 dt = 0.1; // sampling frequency = 10Hz LIGOTimeGPS epoch = { 100, 0 }; REAL8 tStart = XLALGPSGetREAL8 ( &epoch ); UINT4 numSamples = 1000; REAL8 Tspan = numSamples * dt; XLAL_CHECK ( (tsIn = XLALCreateCOMPLEX8TimeSeries ( "test TS_in", &epoch, f0, dt, &emptyLALUnit, numSamples )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamples; j ++ ) { tsIn->data->data[j] = testSignal ( tStart + j * dt, 0 ); } // for j < numSamples // ---------- interpolate this onto new time-samples UINT4 Dterms = 16; REAL8 safety = (Dterms+1.0) * dt; // avoid truncated interpolation to minimize errors, set to 0 for seeing boundary-effects [they're not so bad...] LIGOTimeGPS epochOut = epoch; XLALGPSAdd ( &epochOut, safety ); REAL8 TspanOut = Tspan - 2 * safety; REAL8 dtOut = dt / 10; UINT4 numSamplesOut = lround ( TspanOut / dtOut ); COMPLEX8TimeSeries *tsOut; XLAL_CHECK ( (tsOut = XLALCreateCOMPLEX8TimeSeries ( "test TS_out", &epochOut, f0, dtOut, &emptyLALUnit, numSamplesOut )) != NULL, XLAL_EFUNC ); REAL8 tStartOut = XLALGPSGetREAL8 ( &epochOut ); REAL8Vector *times_out; XLAL_CHECK ( (times_out = XLALCreateREAL8Vector ( numSamplesOut )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamplesOut; j ++ ) { REAL8 t_j = tStartOut + j * dtOut; times_out->data[j] = t_j; } // for j < numSamplesOut XLAL_CHECK ( XLALSincInterpolateCOMPLEX8TimeSeries ( tsOut->data, times_out, tsIn, Dterms ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyREAL8Vector ( times_out ); // ---------- check accuracy of interpolation COMPLEX8TimeSeries *tsFull; XLAL_CHECK ( (tsFull = XLALCreateCOMPLEX8TimeSeries ( "test TS_full", &epochOut, f0, dtOut, &emptyLALUnit, numSamplesOut )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamplesOut; j ++ ) { tsFull->data->data[j] = testSignal ( tStartOut + j * dtOut, 0 ); } // for j < numSamplesOut // ----- out debug info if ( lalDebugLevel & LALINFO ) { XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_in.dat", tsIn ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_out.dat", tsOut ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_full.dat", tsFull ) == XLAL_SUCCESS, XLAL_EFUNC ); } // if LALINFO VectorComparison XLAL_INIT_DECL(tol); tol.relErr_L1 = 2e-2; tol.relErr_L2 = 2e-2; tol.angleV = 2e-2; tol.relErr_atMaxAbsx = 2e-2; tol.relErr_atMaxAbsy = 2e-2; XLALPrintInfo ("Comparing sinc-interpolated timeseries to exact signal timeseries:\n"); VectorComparison XLAL_INIT_DECL(cmp); XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, tsOut->data, tsFull->data, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); // ---------- free memory XLALDestroyCOMPLEX8TimeSeries ( tsIn ); XLALDestroyCOMPLEX8TimeSeries ( tsOut ); XLALDestroyCOMPLEX8TimeSeries ( tsFull ); return XLAL_SUCCESS; } // test_XLALSincInterpolateCOMPLEX8TimeSeries()