29 #ifndef psdVarMean_hpp
30 #define psdVarMean_hpp
34 #include <gsl/gsl_integration.h>
35 #include <gsl/gsl_errno.h>
37 #include "../math/func/bessel.hpp"
38 #include "../math/constants.hpp"
39 #include "../math/gslInterpolator.hpp"
53 template<
typename _realT>
58 std::vector<realT> *
freq {
nullptr};
59 std::vector<realT> *
psd {
nullptr};
85 if(
freq ==
nullptr ||
psd ==
nullptr)
87 std::cerr <<
"Vectors not set.\n";
92 std::cerr <<
"T not set.\n";
117 if(extrapAlpha == 0)
return 0;
119 return (*
psd)[
psd->size()-1] * pow( f/
maxf, -1*extrapAlpha);
134 template<
typename paramsT>
139 typedef typename paramsT::realT realT;
141 paramsT * pvar = (paramsT *) params;
143 realT J = math::func::bessel_j<realT, realT>(0.5, math::two_pi<realT>()*
k);
145 return J*J/
k*pvar->psdVal(
k);
158 template<
typename paramsT>
161 typedef typename paramsT::realT realT;
166 gsl_integration_workspace *
w {
nullptr};
174 gsl_set_error_handler_off();
196 gsl_integration_workspace_free(
w);
205 std::vector<realT> & freq,
206 std::vector<realT> & psd,
212 w = gsl_integration_workspace_alloc(
wSize);
227 func.function = &psdVarMeanFunc<paramsT>;
232 int ec = gsl_integration_qagiu (&func, 0.0, 1e-14, 1e-8,
wSize,
w, &result, &error);
233 static_cast<void>(ec);
Class to manage interpolation using the GSL interpolation library.
constexpr units::realT k()
Boltzmann Constant.
Declares and defines a class for filtering with PSDs.
paramsT::realT psdVarMeanFunc(typename paramsT::realT k, void *params)
Integration worker function for psdVarMean::operator()
Parameters for calculating the variance of the mean from a numerical PSD.
realT psdVal(realT k)
Get the value of the PSD at k using interpolation.
realT minf
The minimum frequency.
std::vector< realT > * freq
Pointer to the frequency vector.
bool initialized
Flag controlling whether the interpolator is initialized.
math::gslInterpolator< math::gsl_interp_linear< realT > > terp
Interpolator for the PSD.
realT T
The sample length (units appropriate for freq)
math::gslInterpolator< math::gsl_interp_steffen< realT > > terp
Interpolator for the PSD.
realT maxf
The maximum frequency.
std::vector< realT > * psd
Pointer to the psd vector.
Calculate the variance of the mean for a process given its PSD.
~psdVarMean()
d'tor cleans up the workspace memory
gsl_integration_workspace * w
The GSL integration workspace memory.
realT operator()(realT &error, std::vector< realT > &freq, std::vector< realT > &psd, realT T)
Calculate the variance of the mean for a psd over a sample length.
realT extrapAlpha
The extrapolation exponent. No extrapolation if 0.
size_t wSize
The size of the GSL workspace.
psdVarMean()
Default c'tor.
psdVarMean(size_t wm)
Constructor which initializes workspace size.
void init()
Initializes the gsl library.