Datafit engine
Purpose
Asymmetric least squares with smoothing, baselining & robust fitting.
Synopsis
- [yb,z,options] = datafit_engine(y,options);
- options = datafit_engine('options');
Description
DATAFIT_ENGINE is used to A) provide a smoothed estimate (z) of the rows of input (y) or B) a baselined estimate the rows of input (y). In each case the objective function to be minimized is given by:
- O(z) = (y-z)'*W0*(y-z) + lambdas*z'*Ds'*Ws*Ds*z + lambdae*(y-ye-z)'*We*(y-ye-z) + lambdab*(Pa-z)'*Wb*(Pa-z) (1).
The weights W are diagonal matrices with entries 0<w<1 allowing individual points in the optimization to be weighted differently. The penalty magnitude is given by the scalar lambda factors.
E.g., the first term in (1) includes W0 that has zeros where data are missing and ones elsewhere. The second term uses a smoothing operator Ds and penalty factor lambdas to penalize roughness (by default Ds is the second difference operator). The third term is used to include equality constriants with penalty factor lambdae (if included) and the fourth term allows for basis functions (P) to be used (if included).
- A) Smoothing is obtained using options.trbflag = 'none' or 'middle'. In this case the output (z), the smoothed estimate of (y) is likey desired. Output yb = y - z would then correspond to fit residuals. if options.trbflag = 'middle' a robust fitting strategy is used.
- B) Baselining is obtained using options.trbflag = 'top' or 'bottom' via an asymmetric least squares fitting strategy. In this case the output (yb) is the baselined estimate of (y) and output (z) corresponds to the baseline.
See additional information on (options.trbflag) below.
Inputs
- spec = M by N matrix of data to be baslined (class "double" or "dataset").
Options
options = a structure array with the following fields:
- plots : [ {'none'} | 'final' ] governs plotting.
- algorithm : [ {'wlsbaseline'} | 'baseline' | 'whittaker' | 'datafit']
- wlsbaseline - Baseline subtraction using iterative asymmetric least squares algorithm.
- baseline - Subtracts a polynomial baseline offset from spectra.
- whittaker - Baseline subtraction using Whittaker filter.
- datafit - Asymmetric least squares baselining.
- order : positive integer for polynomial order {default =1}.
- wlsbaseline_options : see wlsbaseline.m.
- whittaker_options : see wlsbaseline.m.
- baseline_freqs : wavenumber or frequency axis vector, see baseline.m.
- baseline_range : baseline regions, see baseline.m.
- baseline_options : see baseline.m.
- datafit_options : see datafit_engine.m. NOTE: 'lambdas' and 'trbflag' options have defaults updated for baselining.
Outputs
- baselined_data = data with baseline removed.
- baselines = baselines removed from data.