51 const std::vector<double> & y,
const unsigned int polyorder,
const std::vector<unsigned int> & indices
54 if(y.size() == 0 || indices.size() == 0) {
55 throw std::invalid_argument(
"BaselinePolynomial(): the length of y or indices is zero.");
58 if(y.size() < indices.size()) {
59 throw std::invalid_argument(
"BaselinePolynomial(); the length of indices is larger than y.");
62 if(polyorder >= indices.size()) {
63 throw std::invalid_argument(
"BaselinePolynomial(): Too few indices.");
66 double max_index = y.size() - 1;
67 std::vector<unsigned int> sorted_indices = indices;
68 Eigen::VectorXd xx(indices.size()), yy(indices.size());
70 std::sort(sorted_indices.begin(), sorted_indices.end());
72 for(
unsigned int i = 0; i < indices.size(); i++) {
73 xx(i) = sorted_indices[i] / max_index;
74 yy(i) = y[sorted_indices[i]];
77 Eigen::VectorXd coefficients =
PolyFit(xx, yy, polyorder);
83 for(
unsigned int i = sorted_indices[0]; i < sorted_indices.back(); i++) {
84 double x = i / max_index;
88 for(
int j = 0; j < coefficients.size(); j++) {
89 fx += coefficients(j) * k;
96 for(
unsigned int i = 0; i < y.size(); i++) {
const Derived::PlainObject PolyFit(const Eigen::MatrixX< typename Derived::PlainObject::Scalar > &V, const Eigen::MatrixBase< Derived > &y)
Solves the polynomial least squares fitting problem using a pre-calculated Vandermonde matrix.
const BaselineResult BaselineLinear(const std::vector< double > &y, const unsigned int index1, const unsigned int index2)
Performs baseline estimation with a linear line between two points.
const BaselineResult BaselinePolynomial(const std::vector< double > &y, const unsigned int polyorder, const std::vector< unsigned int > &indices)
Performs baseline estimation by fitting a polynomial to specified points.