sablib
Loading...
Searching...
No Matches
smoothing.cpp File Reference

The C interface of sablib smoothing functions.(implementation). More...

#include <algorithm>
#include <vector>
#include "smoothing.h"
#include "../smoothing/moving_average.h"
#include "../smoothing/moving_median.h"
#include "../smoothing/pspline.h"
#include "../smoothing/savitzky_golay.h"
#include "../smoothing/whittaker.h"

Go to the source code of this file.

Functions

const SABLIB_DATA_PTR Sablib_MovingAverage (const SABLIB_DATA_PTR y, const unsigned int n)
 Calculates the simple moving average of the input signal.
const SABLIB_DATA_PTR Sablib_WeightedMovingAverage (const SABLIB_DATA_PTR y, const SABLIB_DATA_PTR w)
 Calculates the weighted moving average of the input signal.
const SABLIB_DATA_PTR Sablib_GaussianKernel (const unsigned int n, const double sigma)
 Generates a Gaussian kernel.
const SABLIB_DATA_PTR Sablib_GaussianFilter (const SABLIB_DATA_PTR y, const unsigned int n, const double sigma)
 Performs Gaussian smoothing on the input signal.
const SABLIB_DATA_PTR Sablib_MovingMedian (const SABLIB_DATA_PTR y, const unsigned int n)
 Performs moving median smoothing.
const SABLIB_DATA_PTR Sablib_PSpline (const SABLIB_DATA_PTR y, const unsigned int knots_num, const unsigned int degree, const unsigned int s, const double lambda)
 Smoothes the input data using P-Splines (Penalized B-Splines).
const SABLIB_DATA_PTR Sablib_SavitzkyGolayCoefficients (const unsigned int n, const unsigned int polyorder, const unsigned derive, const double delta)
 Calculates the coefficients for a Savitzky-Golay filter.
const SABLIB_DATA_PTR Sablib_SavitzkyGolay (const SABLIB_DATA_PTR y, const unsigned int n, const unsigned int polyorder, const unsigned derive, const double delta)
 Performs smoothing (and differentiation) using a Savitzky-Golay filter.
const SABLIB_DATA_PTR Sablib_WeightedWhittaker (const SABLIB_DATA_PTR y, const SABLIB_DATA_PTR w, const double lambda, const unsigned int s)
 Performs Whittaker smoothing (with weights).
const SABLIB_DATA_PTR Sablib_Whittaker (const SABLIB_DATA_PTR y, const double lambda, const unsigned int s)
 Performs Whittaker smoothing (without weights).

Detailed Description

The C interface of sablib smoothing functions.(implementation).

Author
Izadori

Definition in file smoothing.cpp.

Function Documentation

◆ Sablib_GaussianFilter()

const SABLIB_DATA_PTR Sablib_GaussianFilter ( const SABLIB_DATA_PTR y,
const unsigned int n,
const double sigma )

Performs Gaussian smoothing on the input signal.

This is a convenience function that generates a Gaussian kernel and then applies it using Sablib_WeightedMovingAverage.

Parameters
yThe data to be smoothed.
nHalf-width of the Gaussian window (total size is 2 * n + 1).
sigmaThe standard deviation of the Gaussian distribution.
Returns
The data after applying the Gaussian filter.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 67 of file smoothing.cpp.

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

◆ Sablib_GaussianKernel()

const SABLIB_DATA_PTR Sablib_GaussianKernel ( const unsigned int n,
const double sigma )

Generates a Gaussian kernel.

Parameters
nHalf-width of the Gaussian window (total size is 2 * n + 1).
sigmaThe standard deviation of the Gaussian distribution.
Returns
A vector containing the Gaussian kernel coefficients.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 54 of file smoothing.cpp.

References AllocSablibData(), and _stSablibData::data.

◆ Sablib_MovingAverage()

const SABLIB_DATA_PTR Sablib_MovingAverage ( const SABLIB_DATA_PTR y,
const unsigned int n )

Calculates the simple moving average of the input signal.

Parameters
yThe data to be averaged.
nHalf-width of the moving average window (calculated using 2 * n + 1 points).
Returns
The data after applying the moving average.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 21 of file smoothing.cpp.

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

◆ Sablib_MovingMedian()

const SABLIB_DATA_PTR Sablib_MovingMedian ( const SABLIB_DATA_PTR y,
const unsigned int n )

Performs moving median smoothing.

Parameters
yThe input data vector (signal to be smoothed).
nHalf-width of the moving median window (calculated using 2 * n + 1 points).
Returns
The data after applying the moving median.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 83 of file smoothing.cpp.

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

◆ Sablib_PSpline()

const SABLIB_DATA_PTR Sablib_PSpline ( const SABLIB_DATA_PTR y,
const unsigned int knots_num,
const unsigned int degree,
const unsigned int s,
const double lambda )

Smoothes the input data using P-Splines (Penalized B-Splines).

This function applies a B-Spline basis with a difference penalty on the coefficients to achieve smoothing of the input data.

Parameters
yThe input data points to be smoothed.
knots_numThe number of internal knots for the B-Spline basis.
degreeThe degree of the B-Spline basis (default is 3, cubic spline).
sThe order of the difference penalty (default is 2).
lambdaThe smoothing parameter (default is 1.0). Larger values result in smoother curves.
Returns
A vector containing the smoothed data points.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 99 of file smoothing.cpp.

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

◆ Sablib_SavitzkyGolay()

const SABLIB_DATA_PTR Sablib_SavitzkyGolay ( const SABLIB_DATA_PTR y,
const unsigned int n,
const unsigned int polyorder,
const unsigned derive,
const double delta )

Performs smoothing (and differentiation) using a Savitzky-Golay filter.

Parameters
yThe input data to be filtered.
nThe half-width of the filter window (total window size is 2 * n + 1).
polyorderThe order of the polynomial used for fitting.
deriveThe order of the derivative to compute (0 for smoothing only).
deltaThe spacing of the samples.
Returns
The filtered (smoothed or differentiated) data.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 133 of file smoothing.cpp.

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

◆ Sablib_SavitzkyGolayCoefficients()

const SABLIB_DATA_PTR Sablib_SavitzkyGolayCoefficients ( const unsigned int n,
const unsigned int polyorder,
const unsigned derive,
const double delta )

Calculates the coefficients for a Savitzky-Golay filter.

Parameters
nThe half-width of the filter window (total window size is 2 * n + 1).
polyorderThe order of the polynomial used for fitting.
deriveThe order of the derivative to compute (0 for smoothing only).
deltaThe spacing of the samples.
Returns
The calculated filter coefficients.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 118 of file smoothing.cpp.

References AllocSablibData(), and _stSablibData::data.

◆ Sablib_WeightedMovingAverage()

const SABLIB_DATA_PTR Sablib_WeightedMovingAverage ( const SABLIB_DATA_PTR y,
const SABLIB_DATA_PTR w )

Calculates the weighted moving average of the input signal.

Parameters
yThe data to be averaged.
wWeights.
Returns
The data after applying the moving average.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 37 of file smoothing.cpp.

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

◆ Sablib_WeightedWhittaker()

const SABLIB_DATA_PTR Sablib_WeightedWhittaker ( const SABLIB_DATA_PTR y,
const SABLIB_DATA_PTR w,
const double lambda,
const unsigned int s )

Performs Whittaker smoothing (with weights).

Parameters
yThe input data to be smoothed.
wWeights for each data point.
lambdaSmoothing parameter (larger values lead to more smoothing, but may flatten peaks).
sThe order of the difference (usually s = 1, 2, or 3).
Returns
The smoothed data.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 152 of file smoothing.cpp.

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

◆ Sablib_Whittaker()

const SABLIB_DATA_PTR Sablib_Whittaker ( const SABLIB_DATA_PTR y,
const double lambda,
const unsigned int s )

Performs Whittaker smoothing (without weights).

Parameters
yThe input data to be smoothed.
lambdaSmoothing parameter (larger values lead to more smoothing, but may flatten peaks).
sThe order of the difference (usually s = 1, 2, or 3).
Returns
The smoothed data.
Note
The returned pointer must be freed with FreeSablibData() to avoid memory leaks.

Definition at line 172 of file smoothing.cpp.

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