3 %> @brief Polynomial baseline correction
5 %> <h3>References:</h3>
6 %> [1] Beier BD, Berger AJ. Method
for automated background subtraction from Raman spectra containing known contaminants.
7 %> The Analyst. 2009; 134(6):1198-202. Available at: http:
9 %> @param X [no][nf] matrix
10 %> @param order polynomial order
11 %> @param epsilon tolerance to stop iterations. If zero or no value given, will
default to <code>sqrt(1/30*nf)</code>
12 %> @param Xcont [no_cont][nf] matrix containing contaminants to be eliminated
13 %> @
return Corrected matrix
14 function X =
bc_poly(X, order, epsilon, Xcont)
18 if ~exist(
'epsilon',
'var') || epsilon <= 0
19 % epsilon will be compared to a vector norm. If we assume the error at all elements to have the same importance, it
20 % the norm of the error will be something like sqrt(nf*error_i)
21 % For the tolerance to be 1 when nf = 1500 (empirically found to work) the formula below is set.
22 epsilon = sqrt(1/90*nf);
25 flag_cont = exist(
'Xcont',
'var') && ~isempty(Xcont); % take contaminants into account?
31 x = 1:nf; % x-values to be powered
as columns of a design matrix
34 % If contaminants are present, mounts a design matrix containing powers
35 % of x and the contaminants
as different columns
36 no_cont = size(Xcont, 1);
37 M = zeros(nf, order+1+no_cont);
38 M(:, no_cont) = Xcont
';
43 M(:, no_cont+i) = x'.^(i-1);
49 ipro = progress2_open('Polynomial baseline correction
', [], 0, no);
57 % % I no contaminant is present, uses MATLAB's polyfit rather
58 % % than least-squares solution. I didn
't check which is faster.
59 % p = polyfit(x, y, order);
62 % all-in-one least-squares solution and linear combination of the columns of M
64 % (29/03/2011) Least-Squares solution is faster than polyfit()
66 warning off; %#ok<*WNOFF>
68 yp = (M*(MM\(M'*y
')))';
69 warning on; %#ok<*WNON>
76 % y
for next iteration will be a chopped-peak version of y
80 if norm(y-y_previous) < epsilon
function progress2_change(in prgrss, in title, in perc, in i, in n)
function bc_poly(in X, in order, in epsilon, in Xcont)
function progress2_close(in prgrss)
Analysis Session (AS) base class.