sablib
Loading...
Searching...
No Matches
baseline.h File Reference

The C interface of sablib baseline estimation functions. More...

#include <stdbool.h>
#include "data.h"

Go to the source code of this file.

Enumerations

enum  Sablib_BackcorFunc {
  Huber = 0 , AHuber , TQuad , ATQuad ,
  Indec , AIndec
}
 Cost function types for the Backcor algorithm. More...
enum  Sablib_SnipPreprocess { None = 0 , LL , LLS }
 Preprocessing types for the SNIP algorithm. More...
enum  Sablib_BeadsPenalty { L1_v1 = 0 , L1_v2 }
 Penalty types for the BEADS algorithm. More...

Functions

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineLinear (const SABLIB_DATA_PTR y, const unsigned int index1, const unsigned int index2)
 Performs baseline estimation with a linear line between two points.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselinePolynomial (const SABLIB_DATA_PTR y, const unsigned int polyorder, const unsigned int *indices_ptr, const size_t ptr_size)
 Performs baseline estimation by fitting a polynomial to specified points.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSpline (const SABLIB_DATA_PTR y, const unsigned int *indices_ptr, const size_t ptr_size)
 Performs baseline estimation using cubic spline interpolation.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSMA (const SABLIB_DATA_PTR y, const unsigned int n, const unsigned int loop)
 Performs background estimation using a simple moving average.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSnip (const SABLIB_DATA_PTR y, const unsigned int m, const bool decreasing, const enum Sablib_SnipPreprocess preprocess, const unsigned int loop)
 Performs baseline estimation using the Statistics-sensitive Non-linear Iterative Peak-clipping (SNIP) algorithm.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineModPoly (const SABLIB_DATA_PTR y, const unsigned int polyorder, const unsigned int loop, const double eps)
 Estimates the baseline using the Modified Polynomial (ModPoly) method.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineIModPoly (const SABLIB_DATA_PTR y, const unsigned int polyorder, const double k, const unsigned int loop, const double eps)
 Estimates the baseline using the Improved Modified Polynomial (IModPoly) method.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineBackcor (const SABLIB_DATA_PTR y, const unsigned int polyorder, const enum Sablib_BackcorFunc func, const double s, const double alpha, const unsigned int loop, const double eps)
 Performs baseline estimation using iterative polynomial fitting with a non-quadratic cost function (Backcor).
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineGoldindec (const SABLIB_DATA_PTR y, const unsigned int polyorder, const double peak_ratio, const double alpha, const unsigned int loop, const double eps, const unsigned int loop_legend, const double eps_legend, const double eps_s)
 Performs baseline estimation using the Goldindec algorithm.
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineAsLS (const SABLIB_DATA_PTR y, const double lambda, const double p, const unsigned int s, const unsigned int loop, const double eps)
 Performs baseline estimation using Asymmetric Least Squares Smoothing (AsLS).
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineAirPLS (const SABLIB_DATA_PTR y, const double lambda, const unsigned int s, const unsigned int loop, const double eps)
 Performs baseline estimation using adaptive iteratively reweighted Penalized Least Squares(airPLS).
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineArPLS (const SABLIB_DATA_PTR y, const double lambda, const unsigned int s, const unsigned int loop, const double eps)
 Performs baseline estimation using asymmetrically reweighted Penalized Least Squares(arPLS).
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselinePsalsa (const SABLIB_DATA_PTR y, const double lambda, const double p, const double k, const unsigned int s, const unsigned int loop, const double eps)
 Performs baseline estimation using Peaked Signal’s Asymmetric Least Squares Algorithm (psalsa).
SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineBeads (const SABLIB_DATA_PTR y, const unsigned int s, const double frequency, const double r, const double lambda0, const double lambda1, const double lambda2, const unsigned int loop, const double eps, const enum Sablib_BeadsPenalty penalty)
 Performs baseline estimation and denoising using Sparsity (BEADS).
SABLIB_EXPORT const SABLIB_DATA_PTR Sablib_BeadsExpandBoundaries (const SABLIB_DATA_PTR y, const unsigned int n)
 Expands the signal boundaries by padding with a tapered sequence.
SABLIB_EXPORT const SABLIB_DATA_PTR Sablib_BeadsTrimBoundaries (const SABLIB_DATA_PTR y, const unsigned int n)
 Trims the expanded signal boundaries.

Detailed Description

The C interface of sablib baseline estimation functions.

Author
Izadori

Definition in file baseline.h.

Enumeration Type Documentation

◆ Sablib_BackcorFunc

Cost function types for the Backcor algorithm.

Enumerator
Huber 

Huber function.

AHuber 

Asymmetric Huber function.

TQuad 

Truncated quadratic function.

ATQuad 

Asymmetric truncated quadratic function.

Indec 

Indec function.

AIndec 

Asymmetric Indec function.

Definition at line 23 of file baseline.h.

◆ Sablib_BeadsPenalty

Penalty types for the BEADS algorithm.

Enumerator
L1_v1 

Penalty type 1.

L1_v2 

Penalty type 2.

Definition at line 46 of file baseline.h.

◆ Sablib_SnipPreprocess

Preprocessing types for the SNIP algorithm.

Enumerator
None 

No preprocessing (linear scale).

LL 

Log-log transformation.

LLS 

Log-log-sqrt transformation.

Definition at line 36 of file baseline.h.

Function Documentation

◆ Sablib_BaselineAirPLS()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineAirPLS ( const SABLIB_DATA_PTR y,
const double lambda,
const unsigned int s,
const unsigned int loop,
const double eps )

Performs baseline estimation using adaptive iteratively reweighted Penalized Least Squares(airPLS).

Parameters
yThe input data for baseline estimation.
lambdaSmoothing parameter.
sThe order of the difference (usually s = 1, 2, or 3).
loopMaximum number of iterations.
epsConvergence threshold.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 265 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineArPLS()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineArPLS ( const SABLIB_DATA_PTR y,
const double lambda,
const unsigned int s,
const unsigned int loop,
const double eps )

Performs baseline estimation using asymmetrically reweighted Penalized Least Squares(arPLS).

Parameters
yThe input data for baseline estimation.
lambdaSmoothing parameter.
sThe order of the difference (usually s = 1, 2, or 3).
loopMaximum number of iterations.
epsConvergence threshold.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 285 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineAsLS()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineAsLS ( const SABLIB_DATA_PTR y,
const double lambda,
const double p,
const unsigned int s,
const unsigned int loop,
const double eps )

Performs baseline estimation using Asymmetric Least Squares Smoothing (AsLS).

Parameters
yThe input data for baseline estimation.
lambdaSmoothing parameter.
pWeight (asymmetry parameter, typically 0.001 to 0.1).
sThe order of the difference (usually s = 1, 2, or 3).
loopMaximum number of iterations.
epsConvergence threshold.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 245 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineBackcor()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineBackcor ( const SABLIB_DATA_PTR y,
const unsigned int polyorder,
const enum Sablib_BackcorFunc func,
const double s,
const double alpha,
const unsigned int loop,
const double eps )

Performs baseline estimation using iterative polynomial fitting with a non-quadratic cost function (Backcor).

Parameters
yThe input data vector (signal to be processed).
polyorderThe order of the polynomial to be fitted.
funcThe type of cost function to use.
sThreshold parameter for the cost function.
alphaControl parameter for the iterative update. Should be in range [0, 1].
loopThe maximum number of iterations.
epsConvergence threshold for the relative change in the estimated baseline.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 179 of file baseline.cpp.

References AHuber, AIndec, AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, Huber, Indec, _stSablibData::size, and TQuad.

◆ Sablib_BaselineBeads()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineBeads ( const SABLIB_DATA_PTR y,
const unsigned int s,
const double frequency,
const double r,
const double lambda0,
const double lambda1,
const double lambda2,
const unsigned int loop,
const double eps,
const enum Sablib_BeadsPenalty penalty )

Performs baseline estimation and denoising using Sparsity (BEADS).

Parameters
yThe input data.
sOrder of the derivative for baseline sparsity (typically 1 or 2).
frequencySampling frequency of the signal.
rHigh-pass filter parameter (cut-off frequency relative to sampling frequency).
lambda0Sparsity parameter for the baseline.
lambda1Sparsity parameter for the first-order derivative of the signal.
lambda2Sparsity parameter for the second-order derivative of the signal.
loopMaximum number of iterations.
epsConvergence threshold.
penaltyPenalty type.
Returns
The estimated baseline and denoised baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 325 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, L1_v1, and _stSablibData::size.

◆ Sablib_BaselineGoldindec()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineGoldindec ( const SABLIB_DATA_PTR y,
const unsigned int polyorder,
const double peak_ratio,
const double alpha,
const unsigned int loop,
const double eps,
const unsigned int loop_legend,
const double eps_legend,
const double eps_s )

Performs baseline estimation using the Goldindec algorithm.

Parameters
yThe input data vector (signal to be processed).
polyorderThe order of the polynomial to be fitted.
peak_ratioEstimated ratio related to the peak content.
alphaA weighting parameter for the iterative process.
loopMaximum number of iterations for the main loop.
epsConvergence threshold for the main loop.
loop_legendMaximum number of iterations for internal LEGEND algorithm.
eps_legendConvergence threshold for internal LEGEND algorithm.
eps_sConvergence threshold for the internal parameter s.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 222 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineIModPoly()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineIModPoly ( const SABLIB_DATA_PTR y,
const unsigned int polyorder,
const double k,
const unsigned int loop,
const double eps )

Estimates the baseline using the Improved Modified Polynomial (IModPoly) method.

Parameters
yThe input data points to be processed.
polyorderThe order of the polynomial to fit.
kScaling factor for the standard deviation threshold.
loopThe maximum number of iterations.
epsThe convergence tolerance based on the standard deviation change.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 159 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineLinear()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineLinear ( const SABLIB_DATA_PTR y,
const unsigned int index1,
const unsigned int index2 )

Performs baseline estimation with a linear line between two points.

Parameters
yThe input data for baseline estimation.
index1The index of the first point.
index2The index of the second point.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 26 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineModPoly()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineModPoly ( const SABLIB_DATA_PTR y,
const unsigned int polyorder,
const unsigned int loop,
const double eps )

Estimates the baseline using the Modified Polynomial (ModPoly) method.

Parameters
yThe input data points to be processed.
polyorderThe order of the polynomial to fit.
loopThe maximum number of iterations.
epsThe convergence tolerance.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 140 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselinePolynomial()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselinePolynomial ( const SABLIB_DATA_PTR y,
const unsigned int polyorder,
const unsigned int * indices_ptr,
const size_t ptr_size )

Performs baseline estimation by fitting a polynomial to specified points.

Parameters
yThe input data for baseline estimation.
polyorderThe order of the polynomial to fit.
indices_ptrThe indices of the points used for polynomial fitting.
ptr_sizeThe number of indices.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 45 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselinePsalsa()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselinePsalsa ( const SABLIB_DATA_PTR y,
const double lambda,
const double p,
const double k,
const unsigned int s,
const unsigned int loop,
const double eps )

Performs baseline estimation using Peaked Signal’s Asymmetric Least Squares Algorithm (psalsa).

Parameters
yThe input data for baseline estimation.
lambdaSmoothing parameter.
pWeight (asymmetry parameter, typically 0.001 to 0.1).
kExponential decay of the weights.
sThe order of the difference (usually s = 1, 2, or 3).
loopMaximum number of iterations.
epsConvergence threshold.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 305 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineSMA()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSMA ( const SABLIB_DATA_PTR y,
const unsigned int n,
const unsigned int loop )

Performs background estimation using a simple moving average.

Parameters
yThe input data for baseline estimation.
nHalf-width of the moving average window (calculated using 2 * n + 1 points).
loopNumber of iterations.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 87 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BaselineSnip()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSnip ( const SABLIB_DATA_PTR y,
const unsigned int m,
const bool decreasing,
const enum Sablib_SnipPreprocess preprocess,
const unsigned int loop )

Performs baseline estimation using the Statistics-sensitive Non-linear Iterative Peak-clipping (SNIP) algorithm.

Parameters
yThe input data vector (signal to be processed).
mThe maximum half-window size (maximum clipping distance).
decreasingIf true, iterates from m down to 1 (recommended). If false, iterates from 1 up to m.
preprocessThe preprocessing transformation to apply before clipping.
loopThe number of times to repeat the entire SNIP process.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 106 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, LL, LLS, and _stSablibData::size.

◆ Sablib_BaselineSpline()

SABLIB_EXPORT const SABLIB_BASELINE_DATA_PTR Sablib_BaselineSpline ( const SABLIB_DATA_PTR y,
const unsigned int * indices_ptr,
const size_t ptr_size )

Performs baseline estimation using cubic spline interpolation.

Parameters
yThe input data for baseline estimation.
indices_ptrThe indices of the points to be used as knots for the cubic spline.
ptr_sizeThe number of indices.
Returns
The estimated baseline and baseline-corrected data.
Note
The returned pointer must be freed with FreeSablibBaselineData() to avoid memory leaks.

Definition at line 66 of file baseline.cpp.

References AllocSablibBaselineData(), _stSablibBaselineData::baseline, _stSablibBaselineData::corrected, _stSablibData::data, and _stSablibData::size.

◆ Sablib_BeadsExpandBoundaries()

SABLIB_EXPORT const SABLIB_DATA_PTR Sablib_BeadsExpandBoundaries ( const SABLIB_DATA_PTR y,
const unsigned int n )

Expands the signal boundaries by padding with a tapered sequence.

Parameters
yThe input data vector.
nThe number of elements to add at each end.
Returns
A expanded vector.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 357 of file baseline.cpp.

References AllocSablibData(), _stSablibData::data, and _stSablibData::size.

◆ Sablib_BeadsTrimBoundaries()

SABLIB_EXPORT const SABLIB_DATA_PTR Sablib_BeadsTrimBoundaries ( const SABLIB_DATA_PTR y,
const unsigned int n )

Trims the expanded signal boundaries.

Parameters
yThe input data vector (expanded signal).
nThe number of elements to trim from each end.
Returns
A trimmed vector.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 373 of file baseline.cpp.

References AllocSablibData(), _stSablibData::data, and _stSablibData::size.