Fitting time series with polynomials exploits the function ao/polyfit. Details on the agorithm can be found in the appropriate help page.

Fitting time series with polynomials

During this exercise we will:

  1. Load time series noise
  2. Fit data with ao/polyfit
  3. Check results

Let's open a new editor window and load test data.

    a = ao(plist('filename', 'topic5/T5_Ex04_TestNoise.xml'));
    a.setName;

Try to fit data with ao/polyfit. We decide to fit with a 6th order polynomial.

    plfit = plist('N', 6);
    p     = polyfit(a, plfit);

The output of the polifit method is a parameter estimation object (pest-object). This object contains the coefficients of the fitted polynomial.

---- pest 1 ----
       name: polyfit(a)
param names: {'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7'}
          y: [9.17e-15;-1.01e-11;1.15e-08;-2.84e-06;-0.00444;0.138;47.5]
         dy: []
     yunits: [s^(-6)][s^(-5)][s^(-4)][s^(-3)][s^(-2)][s^(-1)][]
        pdf: []
        cov: []
       corr: []
      chain: []
       chi2: []
        dof: 993
     models: smodel(P1*X.^6 + P2*X.^5 + P3*X.^4 + P4*X.^3 + P5*X.^2 + P6*X.^1 + P7*X.^0)
description:
       UUID: 58a56ecf-24e8-40ed-a42c-ef6832c747c3
----------------

Once we have the pest object with the coefficients, we can evaluate the pest-object. The inside model of the pest-object stores the t vector of the input AO so that time base of the objects will be the same.

    b = p.eval(plist('type', 'tsdata'))
    b.setName;

Now, check fit result with some plotting. Compare data with fitted model and look at the fit residuals.

    iplot(a,b)
    iplot(a-b)

You could also try using ao/detrend on the input time-series to yield a very similar result as that shown in the last plot.