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 BaselineResult 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 BaselineResult result;
36 result.baseline.resize(y.size());
37 result.corrected.resize(y.size());
38 result.baseline = y;
39
40 for(unsigned int i = indices[0]; i < indices.back(); i++) {
41 result.baseline[i] = spline.Interpolate(i / max_index);
42 }
43
44 for(unsigned int i = 0; i < y.size(); i++) {
45 result.corrected[i] = y[i] - result.baseline[i];
46 }
47
48 return result;
49}
50
51}; // 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 BaselineResult 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.
Return value structure for baseline estimation functions.
Definition result_type.h:19
std::vector< double > baseline
Definition result_type.h:20
std::vector< double > corrected
Definition result_type.h:21