00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <math.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <lal/LALStdlib.h>
00024 #include <lal/AVFactories.h>
00025 #include <lal/TimeFreqFFT.h>
00026 #include <lal/RealFFT.h>
00027 #include <lal/Window.h>
00028 #include <lal/Random.h>
00029
00030 #include <lal/LALRCSID.h>
00031 NRCSID (AVERAGESPECTRUMTESTC,"$Id: AverageSpectrumTest.c,v 1.6 2008/07/08 22:13:24 kipp Exp $");
00032
00033 #define TESTSTATUS( s ) \
00034 if ( (s)->statusCode ) { REPORTSTATUS( s ); exit( 1 ); } else \
00035 ((void)0)
00036
00037 int main( void )
00038 {
00039 const UINT4 n = 65536;
00040 const UINT4 m = 8;
00041 static AverageSpectrumParams specpar;
00042 static REAL4FrequencySeries fseries;
00043 static REAL4TimeSeries tseries;
00044 static LALStatus status;
00045 static RandomParams *randpar;
00046 REAL8 ave;
00047 UINT4 i;
00048
00049 lalDebugLevel = 3;
00050
00051
00052 tseries.deltaT = 1;
00053 LALCreateVector( &status, &tseries.data, n * m );
00054 TESTSTATUS( &status );
00055 LALCreateVector( &status, &fseries.data, n / 2 + 1 );
00056 TESTSTATUS( &status );
00057
00058
00059
00060
00061
00062
00063
00064 LALCreateRandomParams( &status, &randpar, 1 );
00065 TESTSTATUS( &status );
00066 LALNormalDeviates( &status, tseries.data, randpar );
00067 TESTSTATUS( &status );
00068 LALDestroyRandomParams( &status, &randpar );
00069 TESTSTATUS( &status );
00070
00071
00072 specpar.method = useMedian;
00073 specpar.overlap = n / 2;
00074
00075 LALCreateForwardRealFFTPlan( &status, &specpar.plan, n, 0 );
00076 TESTSTATUS( &status );
00077 specpar.window = XLALCreateWelchREAL4Window(n);
00078
00079
00080 LALREAL4AverageSpectrum( &status, &fseries, &tseries, &specpar );
00081 TESTSTATUS( &status );
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 ave = 0;
00092 for ( i = 1; i < fseries.data->length - 1; ++i )
00093 ave += fseries.data->data[i];
00094 ave /= fseries.data->length - 2;
00095 fprintf( stdout, "median:\t%e\terror:\t%f%%\n", ave, fabs( ave - 2.0 ) / 0.02 );
00096
00097
00098 specpar.method = useMean;
00099 LALREAL4AverageSpectrum( &status, &fseries, &tseries, &specpar );
00100 TESTSTATUS( &status );
00101
00102 ave = 0;
00103 for ( i = 1; i < fseries.data->length - 1; ++i )
00104 ave += fseries.data->data[i];
00105 ave /= fseries.data->length - 2;
00106 fprintf( stdout, "mean:\t%e\terror:\t%f%%\n", ave, fabs( ave - 2.0 ) / 0.02 );
00107
00108
00109
00110 XLALDestroyREAL4Window( specpar.window );
00111 LALDestroyRealFFTPlan( &status, &specpar.plan );
00112 TESTSTATUS( &status );
00113 LALDestroyVector( &status, &fseries.data );
00114 TESTSTATUS( &status );
00115 LALDestroyVector( &status, &tseries.data );
00116 TESTSTATUS( &status );
00117
00118
00119 LALCheckMemoryLeaks();
00120 return 0;
00121 }