clear all;
close all;
clc;
%% Script of the estimation of the correlation coefficients of Jansen's signals, 
% in that script the function jansen_superposition_partI.m is called
%
%% Description
%
% This script is created for the estimation of the correlation coefficients
% of Jansen's signal to confirm or not the superposition principle.
%
%% Call the function jansen_superposition_partI
%
[matrix_signal,data] = jansen_superposition_partI;
%
%% Loading of the estimated model from Ident toolbox
%
load model_jansen1_S1_out1_1.mat
%
%% Estimation of the impulse response of the estimated model
%
h = impulse(arxqs_trial1);
%
%% Estimation of the output of Jansen's signal based on the impulse estimation of the estimated model,
% convolution estimation between the real inputs and their impulse responses,
% multiplication of these convolutions
%
y1 = conv(h(:,1,1),matrix_signal(1,:)) + conv(h(:,1,2),matrix_signal(2,:));
%
%% Normalization of the estimated output and of the real output
%
y1_norm = normr(y1);
matrix_signal_norm = normr(matrix_signal);
%
% Estimation of the correlation coefficients between the real output and
% the estimated output
[r,p] = corrcoef(matrix_signal_norm(3,600:end-600),y1_norm(600:length(matrix_signal(1,:))-600));
%
% Plotting of impulse response  of the estimated model
%
figure
plot(impulse(arxqs_trial1(1,1)), 'b')
hold on
plot(impulse(arxqs_trial1(1,2)), 'r')
title('Impulse response of ARX model')
xlabel('Number of samples')
ylabel('Amplitude')
hold off
%
%% Plotting of the best or the worst results of the analysis of 
% linear relationship between inputs and outputs (only for illustration)
figure
plot(y1_norm,'b')
hold on
plot(matrix_signal_norm(3,:),'r')
xlabel('Number of samples')
ylabel('Normalized amplitude')
hold off

