clear all;
close all;
clc;
%% Script of the estimation of MSE and FIT
%
%% Description
%
% In that script the suitable model describing measured systems from the sponge
% experiments is chosen. It based on the estimation of MSE and FIT. Model
% with the lowest value of MSE is chosen to represent system from the sponge experiments.
%
%% Loading of the system of the sponge experiment
%
infoorigsignal = h5info('sponge_C1_bip_01_2015.06.15_13.17.11.hdf5');               
origin = h5read('sponge_C1_bip_01_2015.06.15_13.17.11.hdf5', '/RawData/Samples');
%
%% Iddata object os created from the white noise part of that system
%
data = iddata(double(origin(4,2107000:2587000))', double(origin(1,2107000:2587000))', 1/4800);
%
%% Definition of parameters typical for ARX model structure
%
na = 0;
nb = 0;
%
%% Estimation of MSE and FIT values
i = 1;
    for z = 1:5
    na = z;
    nb = i;
    sys = tfest(data,na,nb);
    MSE(i,z) = sys.Report.Fit.MSE;
    FIT(i,z) = sys.Report.Fit.FitPercent;
    end

    