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