# Mscorr

## Contents

### Purpose

Multiplicative scatter/signal correction (MSC).

### Synopsis

[sx,alpha,beta,xref] = mscorr(x,xref)
[sx,alpha,beta,xref] = mscorr(x,options)
[sx,alpha,beta,xref] = mscorr(x,xref,options)
[sx,alpha,beta,xref] = mscorr(x,xref,mc,win,specmode,subind)

### Description

MSCORR performs multiplicative scatter correction (a.k.a. multiplicative signal correction) on an input matrix of spectra x (class "double") regressed against a reference spectra xref (class "double"). If (xref) is empty or omitted, the mean of (x) is used as the reference (or median of (x) if options.algorithm = 'median').

If the optional input mc is 1 {default} then an intercept is used. If mc is set to 0 (zero) then a force fit through zero is used.

Optional input win is a NK element cell array of indices corresponding to windows to perform MSC, i.e. MSC is performed in each window win{i} for i=1:NK. In this case, (alpha and beta are not assigned). Optional input (specmode) defines which mode of the data is the spectral mode (default = 2) and is only used when (x) contains 3 or more modes. Optional input (subind) specifies the indices within the included spectral variables that are used to calculate the MSC correction factors (alpha and beta); default is that ALL included spectral variables are used.

Outputs are the corrected spectra sx, the intercepts/offsets alpha, the multiplicative scatter factor/slope beta, and the reference spectrum xref.

Note: the 'median' method does not work well if there are many negative values in xref or x samples.

#### Inputs

• x = input spectra (class double).

#### Optional Inputs

• xref = 1xN reference or "target" spectrum. If empty, mean or median of (x) is used.
• mc = [{1} | 0] flag indicating if an offset should be removed from the spectra in addition to correcting the multiplicative scaling. 1 = correct for offset {default}, or 0 = do not remove offset.
• win = allows for scatter correction in spectral "windows" that can be of different widths. Input (win) is a cell array with NK elements corresponding to the number of windows desired. Each cell of (win) contains the indices corresponding to each window (i.e. this is not a moving window approach - see STDFIR). MSC is then performed in each of the NK windows. (alpha and beta are not assigned). If (win) is empty, the entire spectrum is treated at once (standard approach),
• specmode = defines which mode of the data is the spectral mode (default = 2) and is only used when (x) contains 3 or more modes.
• subind = specifies the indices within the included spectral variables that are used to calculate the MSC correction; default is that ALL included spectral variables are used. Correction is always applied to the entire spectrum even if subind indicates that only a sub-portion should be used to calculate correction factors.

#### Outputs

• sx = corrected spectra,
• alpha = the intercepts/offsets,
• beta = the multiplicative scatter factor/slope,
• xref = the reference spectrum used.

### Options

options = structure array with the following fields :

• algorithm: [ {'leastsquares'} | 'median' ] Specifies spectrum scale factors are determined. Default by least squares regression between between each spectrum and the reference spectrumj. 'median' uses the median of the ratio between a spectrum and the reference. Thus median is only appropriate if most values are non-negative. If algorithm = 'median' then mc is set = 0,
• robust: [{none'} | 'lsq2top' ] Governs the use of robust least squares. If "lsq2top" is used then "trbflag", "tsqlim", and "stopcrit" are also used (see LSQ2TOP for descriptions of these fields).
• res: [] approximate fit residual [scalar]. Required with "robust" set to "lsq2top". (res) is input (res) to the LSQ2TOP function.
• trbflag: [ 'top' | 'bottom' | {'middle'}] Used only with "lsq2top". (trbflag) is a flag that tells algorithm to fit to the top, bottom, or middle of the data cloud. When 'middle' is used, "lsq2top" can be considered a robust least squares method.
• tsqlim: [ 0.99 ] Used only with "lsq2top." (tsqlim) is T2 limit that governs whether a data point is outside the fit residual defined by input (res).
• mc: [{1} | 0] See description above,
• win: [{[ ]} | cell array] See description above,
• specmode: [{2}] See description above,
• subind: [vector] See description above.

### Algorithm

For input spectra x (1xN) and reference spectra xref (1xN) the model is:

${\displaystyle x^{T}\beta +\alpha =x_{ref}^{T}}$

and the corrected spectra xs (1xN) is given by:

${\displaystyle x_{S}=(x_{ref}-\alpha )/\beta }$