sablib
Loading...
Searching...
No Matches
spline.cpp
Go to the documentation of this file.
1
6
8
9#include "spline.h"
10
11namespace sablib {
12
13//
14// Implementation of BaselineSpline() function
15//
16const std::vector<double> BaselineSpline(const std::vector<double> & y, const std::vector<unsigned int> & indices)
17{
18 if(y.size() == 0 || indices.size() == 0) {
19 throw std::invalid_argument("BaselineSpline(): the length of y or indices is zero.");
20 }
21
22 if(y.size() < indices.size()) {
23 throw std::invalid_argument("BaselineSpline(): the length of indices is larger than y.");
24 }
25
26 double max_index = y.size() - 1;
27 Eigen::VectorXd xx(indices.size()), yy(indices.size());
28
29 for(unsigned int i = 0; i < indices.size(); i++) {
30 xx(i) = indices[i] / max_index;
31 yy(i) = y[indices[i]];
32 }
33
34 CubicSpline spline(xx, yy);
35 std::vector<double> result = y;
36
37 for(unsigned int i = indices[0]; i < indices.back(); i++) {
38 result[i] = spline.Interpolate(i / max_index);
39 }
40
41 return result;
42}
43
44}; // namespace sablib
A class for cubic spline interpolation.
Scalar Interpolate(const double x) const
Interpolates the value at a given x-coordinate.
Performs cubic spline parameter calculation and interpolation.
const std::vector< double > BaselineSpline(const std::vector< double > &y, const std::vector< unsigned int > &indices)
Performs baseline estimation using cubic spline interpolation.
Definition spline.cpp:16
Baseline estimation from cubic spline.