Fitting time series with polynimials exploits the function ao/polyfit. Details on the agorithm can be found in the appropriate help page.
During this exercise we will:
Let's open a new editor window and load test data. Run...
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 variable p is a cdata analysis object containing the coefficients of the fitted polynimial.
----------- ao 01: polyfit(a) ----------- name: polyfit(a) description: data: -3.36766610680378e-014 1.00459257400442e-010 -9.19003973844817e-008 3.98578358994058e-005 -0.0123010606401583 1.02090831777042 -87.6426134396757 -------- cdata 01 ------------ y: [1x7], double yunits: [] ------------------------------ hist: ao / polyfit / $Id: polyfit.m,v 1.23 2009/02/19 16:57:47 anneke Exp mfilename: mdlfilename: -----------------------------------------
Once we have the model coefficients we can evaluate the model. We simply need to construct an analysis object with the parameters polyval and t. We pass as polyval the AO containing the fit coefficients and as t the AO with original data so that the time base will be the same.
b = ao(plist('polyval', p, 't', a)); b.setYunits(a.yunits); 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.