Rescale data using various criteria.
y_ = rescaledata(y,mode) y_ = rescaledata(y,yref,mode) y_ = rescaledata(...,region) [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 array is given in yref
, the data in y
are rescaled in a way depending on the value of mode
:
'maxabs'
: scales y
such that its maximum absolute will match that of yref
'lsq'
: least-squares fits y
to yref
using a*y
(scale only)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:
'maxabs'
:
scales y
such that its maximum absolute value equals 1.
'int'
:
scales y
such that the integral (calculated as the sum of the datapoints) equals 1.
'dint'
:
scales y
such that the double integral (calculated as the sum of the cumulative sum o the datapoints) equals 1.
scalefactors
is an optional output that provides the calculated scale factor.
Generate a Gaussian signal and a noisy version of it
n = 200; x = linspace(-1,1,n); yn = gaussian(x,0,0.5); y1 = addnoise(yn,20,'n'); plot(x,yn,x,y1)
The noisy signal can be rescaled in various ways to fit the noise-free one:
y2 = rescaledata(yn,y1,'maxabs'); y3 = rescaledata(yn,y1,'lsq'); plot(x,y1,x,y2,x,y3); legend('input','maxabs','lsq');
basecorr, deriv, rcfilt, datasmooth