8#ifndef clAOLinearPredictor_hpp
9#define clAOLinearPredictor_hpp
35#define CLAOLP_BREADCRUMB
45template <
typename _realT>
119 std::vector<realT> &PSDn,
130 for(
size_t i = 0; i < PSDt.size(); ++i )
132 m_PSDtn[i] = PSDt[i] + PSDn[i] + PSDreg;
165 template <
bool telem>
172 std::vector<realT> &PSDt,
173 std::vector<realT> &PSDn,
188 min_var = std::numeric_limits<realT>::max();
198 realT psdReg = PSDt[0];
203 for(
realT sc = max_sc; sc >= sc0; sc -= precision )
233 rv = go_lp.
optGainOpenLoop( gopt_lp, var_lp, PSDt, PSDn, gmax_lp,
false );
242 m_regResults.push_back( { sc, gopt_lp, gmax_lp, var_lp } );
246 if( var_lp < min_var )
253 if( var_lp > 10 * min_var )
274 template <
bool telem = false>
281 std::vector<realT> &PSDt,
282 std::vector<realT> &PSDn,
298 "invalid linear-predictor regularization search controls" );
316 const bool firstIteration = its == 0;
326 if( min_sc == max_sc )
341 max_sc = min_sc + precision;
351 "linear-predictor regularization reached its iteration limit" );
380 rv = go_lp.
optGainOpenLoop( gopt_lp, var_lp, PSDt, PSDn, gmax_lp,
false );
399 template <
bool pr
intout = false>
405 std::vector<realT> &PSDt,
406 std::vector<realT> &PSDn,
410 realT minVar = std::numeric_limits<realT>::max();
412 for(
int n = minNc; n <= maxNc; ++n )
424 if( _var_lp < minVar )
Tools for working with autocorrelations.
Provides a class to manage closed loop gain optimization.
Floating-point classification utilities that remain reliable under fast-math optimization.
Utilities for working with angles.
error_t
The mxlib error codes.
@ noerror
No error has occurred.
@ timeout
A timeout occurred.
@ invalidconfig
A config setting was invalid.
@ liberr
An error was returned by a library.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
bool isFinite(realT value)
Test whether a floating-point value is finite, including under finite-math-only optimization.
void augment1SidedPSD(vectorTout &psdTwoSided, vectorTin &psdOneSided, bool addZeroFreq=false, typename vectorTin::value_type scale=0.5)
Augment a 1-sided PSD to standard 2-sided FFT form.
Working with linear prediction.
Declarations of some libarary wide utilities.
Tools for working with PSDs.
Result from one evaluated regularization scale.
realT gopt
Optimum gain at this scale.
realT sc
Regularization scale in dB.
realT var
Closed-loop variance at the optimum gain.
realT gmax
Maximum stable gain at this scale.
Diagnostic summary of the most recent regularization search.
std::size_t evaluations
Regularization scales evaluated.
int iterations
Refinement iterations attempted.
regularizationStatus status
Search termination state.
realT m_max_sc0
Initial maximum regularization scale in dB.
realT m_minPrecision
Minimum requested regularization spacing in dB.
mx::error_t _regularizeCoefficients(realT &min_var, realT &min_sc, realT precision, realT max_sc, clGainOpt< realT > &go_lp, std::vector< realT > &PSDt, std::vector< realT > &PSDn, int Nc)
Worker function for regularizing the PSD for coefficient calculation.
realT m_gmax_lp
The maximum allowable gain for LP.
realT m_precision0
Initial regularization scale spacing in dB.
std::vector< realT > m_psd2s
Working memory for the 2-sided regularized PSD.
sigproc::linearPredictor< realT > m_lp
Linear predictor used to calculate coefficients.
mx::error_t regularizeCoefficients(realT &gmax_lp, realT &gopt_lp, realT &var_lp, realT &min_sc, clGainOpt< realT > &go_lp, std::vector< realT > &PSDt, std::vector< realT > &PSDn, int Nc)
Regularize the PSD and calculate the associated LP coefficients.
regularizationStatus
Termination state of the most recent regularization search.
@ boundaryLimited
The optimum remained on the expanded search boundary.
@ notRun
No regularization search has been attempted.
@ converged
The requested precision was reached.
@ iterationLimit
The search exhausted its iteration limit.
@ invalidControls
The configured search controls were invalid.
@ calculationFailure
Coefficient or gain calculation failed.
regularizationReport m_regularizationReport
Diagnostic summary of the latest search.
std::vector< realT > m_PSDtn
Working memory for the regularized PSD.
std::vector< realT > m_ac
Working memory to hold the autocorrelation.
mx::error_t optimizeNc(realT &gmax_lp, realT &gopt_lp, int &Nc, realT &var_lp, clGainOpt< realT > &go_lp, std::vector< realT > &PSDt, std::vector< realT > &PSDn, int minNc, int maxNc)
Regularize the PSD and calculate the associated LP coefficients.
int m_maxIts
Maximum number of search refinement iterations.
realT m_dPrecision
Divisor applied to the spacing during refinement.
_realT realT
Floating-point type used for predictor calculations.
clAOLinearPredictor()=default
Construct a closed-loop linear-predictor calculator with default search controls.
mx::error_t calcCoefficients(std::vector< realT > &PSDt, std::vector< realT > &PSDn, realT PSDreg, int Nc, realT condition=0)
Calculate the LP coefficients for a turbulence PSD and a noise PSD.
realT m_min_sc0
Initial minimum regularization scale in dB.
sigproc::autocorrelationFromPSD< realT > m_acpsd
Converts the working PSD to an autocorrelation.
std::vector< regResult > m_regResults
Per-scale telemetry collected when requested.
realT m_min_var0
Initial minimum variance, with zero requesting initialization.
int m_extrap
The LP extrapolation length in loop steps. Normally it is 1 step.
A class to manage optimizing closed-loop gains.
void a(const std::vector< realT > &newA)
Set the vector of IIR coefficients.
void b(const std::vector< realT > &newB)
Set the vector of FIR coefficients.
mx::error_t maxStableGain(realT &gain, maxStableGainReport *report=nullptr)
Find the maximum stable gain for the loop parameters.
mx::error_t optGainOpenLoop(realT &gain, realT &var, const std::vector< realT > &PSDerr, const std::vector< realT > &PSDnoise, bool gridSearch, optGainReport *report=nullptr)
Return the optimum closed loop gain given an open loop PSD.
Functor for calculating the autocorrelation given a PSD.
A class to support linear prediction.