Method ao/polyfit


  POLYFIT overloads polyfit() function of MATLAB for Analysis Objects.
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  DESCRIPTION: POLYFIT overloads polyfit() function of MATLAB for Analysis
               Objects. It finds the coefficients of a polynomial P(X) of
               degree N that fits the data Y best in a least-squares sense:
               P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1)
 
  CALL:        bs = polyfit(a1, a2, a3, ..., pl)
               bs = polyfit(as,pl)
               bs = as.polyfit(pl)
 
  INPUTS:      aN   - input analysis objects with data to be fitted.
                    X will be a.x
                    Y will be a.y
               as   - input analysis objects array
               pl   - input parameter list
 
  OUTPUTs:     bs  - An array of pest objects, each with the N+1 fitting coefficients P(j)
 
  NOTE: the data are assumed to be random, so to use the information from polyfit to estimate
        the covariance matrix of the data, under the assumption chi^2 equals 1.
 
  Parameters Description
 
  EXAMPLES:
  
    %% Make fake AO from polyval
    nsecs = 100;
    fs    = 10;
    
    u = unit('fm s^-2');
    
    pl = plist('nsecs', nsecs, 'fs', fs, ...
      'tsfcn', 'polyval([3 2 1 ], t) + 1000*randn(size(t))', ...
      'xunits', 's', 'yunits', u);
  
    a1 = ao(pl);
    
    %% Fit a polynomial
    N = 3;
    p1 = polyfit(a1, plist('N', N));
    p2 = polyfit(a1, plist('N', N, 'rescale', true));
 
    %% Compute fit: evaluating pest
    %% Here we need to specify that we want to use the 'x' field of 
    %% the AO a to build the output AO
    
    b1 = p1.eval(plist('type', 'tsdata', 'XData', a1, 'Xfield', 'x'));
    b2 = p2.eval(a1, plist('type', 'tsdata', 'Xfield', 'x'));
    
    %% Plot fit
    iplot(a1, b1, plist('LineStyles', {'', '--'}));
 
    %% Remove polynomial
    c = a1-b1;
    iplot(c)
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Method Details
Access public
Defining Class ao
Sealed 0
Static 0

Parameter Description

Default

no description
Key Default Value Options Description
polyfit
N, ORDER 1
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
Degree of polynomial to fit.
RESCALE 0
  • 0
  • 1
set to 'true' or 'false' to center and rescale the data before fitting.
See "help polyfit" for further details.

Example

plist('N', [1], 'RESCALE', [false])

back to top back to top

Some information of the method ao/polyfit are listed below:
Class name ao
Method name polyfit
Category Signal Processing
Package name ltpda
VCS Version 967b0eec0dece803a81af8ef54ad2f8c784b20b2
Min input args 1
Max input args -1
Min output args 1
Max output args -1
Can be used as modifier 0
Supported numeric types {'double'}




©LTP Team