Rescale data, including least-squares baseline fits.
y_ = rescaledata(y,yref,mode) y_ = rescaledata(y,mode) [y_,scalefactors] = rescaledata(...)
This function rescales the data in the vector y and returns it in y_. The type of rescaling depends on the setting mode and on the presence or absence of a reference data vector yref.
If a second data set is given in yref, the data in y
are rescaled and shifted in a way depending on the value of mode:
'minmax': shifts and scales y such that its minimum and maximum will match those of yref
'maxabs': scales y such that its maximum absolute will match that of yref (no shift)
'lsq': least-squares fits y to yref using a*y (scale only)
'lsq0': least-squares fits y to yref using a*y+b (scale and shift)
'lsq1': least-squares fits y to yref using a*y+b+c*x (scale plus linear baseline)
'lsq2': least-squares fits y to yref using a*y+b+c*x+ d*x^2 (scale plus quadratic baseline)
'lsq3': least-squares fits y to yref using a*y+b+c*x+ d*x^2+ e*x^3 (scale plus cubic baseline)
In all cases, positive rescaling is enforced, i.e. the rescaled data is not inverted.
Without a reference data vector, the rescale options (given in mode) are more limited:
'minmax':
shifts and scales y such that its minimum is 0 and its maximum is 1
'maxabs':
scales y such that its maximum absolute is 1 (no shift)
scalefactors is an optional ouput that includes the scale, shift and polynomial coefficients (against an abscissa running from 0 to 1).
Generate a Gaussian signal and a noisy version of it with a linear baseline drift
n = 200; x = linspace(-1,1,n); yn = gaussian(x,0,0.5); y1 = yn + 0.5*randn(1,n) + 2*x; plot(x,yn,x,y1)
The noisy signal can be rescaled in various ways to fit the noise-free one:
y2 = rescaledata(yn,y1,'minmax');
y3 = rescaledata(yn,y1,'lsq0');
y4 = rescaledata(yn,y1,'lsq1');
plot(x,y1,x,y2,x,y3,x,y4);
legend('input','minmax','lsq0','lsq1');
In this case, 'lsq1' is needed to remove the linear background.