diff --git a/lib/Core/Math.cpp b/lib/Core/Math.cpp index 5278412..16ab66d 100644 --- a/lib/Core/Math.cpp +++ b/lib/Core/Math.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -48,16 +49,42 @@ DMat MATH_NAMESPACE::corrToVar(const DMat &corr, const DVec &varDiag) return res; } -double MATH_NAMESPACE::svdDynamicRange(const DMat &mat) +double MATH_NAMESPACE::conditionNumber(const DMat &mat) { DVec s = mat.singularValues(); return s.maxCoeff()/s.minCoeff(); } -double MATH_NAMESPACE::svdDynamicRangeDb(const DMat &mat) +double MATH_NAMESPACE::cdr(const DMat &mat) { - return 10.*log10(svdDynamicRange(mat)); + return 10.*log10(conditionNumber(mat)); +} + +template +double nsdr(const DMat &m) +{ + Index n = m.rows(); + FFT fft(n); + CMat buf(n, 1); + + FOR_VEC(buf, i) + { + buf(i) = 0.; + for (Index j = 0; j < n; ++j) + { + buf(i) += m(j, (i+j) % n); + } + buf(i) /= n; + } + fft(buf, FFT::Forward); + + return 10.*log10(buf.real().maxCoeff()/buf.real().minCoeff()); +} + +double MATH_NAMESPACE::nsdr(const DMat &mat) +{ + return ::nsdr(mat); } /****************************************************************************** diff --git a/lib/Core/Math.hpp b/lib/Core/Math.hpp index 0ece91a..7ad4ad1 100644 --- a/lib/Core/Math.hpp +++ b/lib/Core/Math.hpp @@ -73,8 +73,9 @@ namespace MATH_NAMESPACE DMat corrToVar(const DMat &corr, const DVec &varDiag); // matrix SVD dynamic range - double svdDynamicRange(const DMat &mat); - double svdDynamicRangeDb(const DMat &mat); + double conditionNumber(const DMat &mat); + double cdr(const DMat &mat); + double nsdr(const DMat &mat); // Constants constexpr double pi = 3.1415926535897932384626433832795028841970; diff --git a/lib/Statistics/XYSampleData.cpp b/lib/Statistics/XYSampleData.cpp index 0676564..8b5e0d9 100644 --- a/lib/Statistics/XYSampleData.cpp +++ b/lib/Statistics/XYSampleData.cpp @@ -343,7 +343,7 @@ SampleFitResult XYSampleData::fit(std::vector &minimizer, result.nPar_ = sampleResult.getNPar(); result.nDof_ = sampleResult.nDof_; result.parName_ = sampleResult.parName_; - result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat()); + result.corrRangeDb_ = Math::cdr(getFitCorrMat()); return result; } diff --git a/lib/Statistics/XYStatData.cpp b/lib/Statistics/XYStatData.cpp index 690a3a6..b83397f 100644 --- a/lib/Statistics/XYStatData.cpp +++ b/lib/Statistics/XYStatData.cpp @@ -358,7 +358,7 @@ FitResult XYStatData::fit(vector &minimizer, const DVec &init, result = (*m)(chi2); totalInit = result; } - result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat()); + result.corrRangeDb_ = Math::cdr(getFitCorrMat()); result.chi2_ = chi2(result); result.nPar_ = nPar; result.nDof_ = layout.totalYSize - nPar; diff --git a/utils/sample-plot-corr.cpp b/utils/sample-plot-corr.cpp index c900dc0..34e4d98 100644 --- a/utils/sample-plot-corr.cpp +++ b/utils/sample-plot-corr.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) var = sample.varianceMatrix(); corr = sample.correlationMatrix(); - cout << "dynamic range " << Math::svdDynamicRangeDb(corr) << " dB" << endl; + cout << "dynamic range " << Math::cdr(corr) << " dB" << endl; p << PlotCorrMatrix(corr); p.display(); if (!outVarName.empty())