% Training session Topic 5 exercise 04
% 
% Fitting time series with polynimials
% 
% 1) Load time series noise
% 2) Fit data with ao/polyfit
% 3) Check results
% 
% 
% L FERRAIOLI 22-02-09
%
% $Id: TrainigSession_T5_Ex04.m,v 1.2 2011/05/13 15:13:12 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% 1) load fsdata

% load test noise AO from file
a = ao(plist('filename', 'topic5/T5_Ex04_TestNoise.xml'));
a.setName;

% looking at data
iplot(a)

%% 2) polyfit

% ao/polyfit is a wrapper of the matlab function polyfit

% set plist for fit
plfit = plist('N', 6); % set the order of the polynomial to be fitted to data

% fit data
p = polyfit(a, plfit);

% evaluating model
b = ao(plist('polyval', p, 't', a));

%% 3) Check results

% plot model and data
iplot(a,b)

% plotting fit residuals
iplot(a-b)





