basecorr

Polynomial baseline correction.

Syntax
datacorr = basecorr(data,dim,n)
datacorr = basecorr(data,dim,n,region)
[coddata,baseline] = basecorr(...)
basecorr(...)
Description

This function computes and applies polynomial baseline corrections to the input data array data. It returns the baseline-corrected data in datacorr and the polynomial baseline(s) in baseline. The baseline is computed by least-squares fitting polynomials of required order to the data along specified dimensions.

dim specifies the dimension(s) along which baselines should be fitted. For dim=1, baselines are fitted to each column in the data array. For dim=2, baselines are fitted to each row. For dim=[], a single two-dimensional baseline is fit.

n gives the polynomials order. For 1D fits (dim=1 or 2), provide a single number between 0 (constant offset) and 6 (sixth-order polynomial). For a 2D fit (dim=[]), provide 2 numbers in n, one for each dimension.

The optional input region provides a mask to select the region to include in the fit. Provide a logical array of the same size as data. Data points for which the corresponding element in region is true (false) are included (excluded) in the fit. This works only for 1D fits.

The two outputs are the corrected data in datacorr and the fitted baseline(s) in baseline. If not outputs are requested, the results are plotted.

Examples

To fit cubic baselines separately along each column, use

datac = basecorr(data,1,3);

To fit linear baselines separately along each row, use

datac = basecorr(data,2,1);

To fit linear baselines separately along each row, but limit the fit region, use

region = x<3 | x>6;  % include region with x<3 and x>6 in the fit
datac = basecorr(data,2,1,region);

To fit a single third-order surface to 2D data, use

datac = basecorr(data,[],[3 3]);
Algorithm

1D and 2D polynomial least-square fits are computed by constructing the Vandermonde matrix associated with the problem and using MATLAB's \ operator to solve the resulting system of linear equations.

See also

apowin, exponfit, datasmooth