function co_example3
% DAMOCO Toolbox, function CO_EXAMPLE3, version 16.01.11
%
% This function illustrates the bivariate analysis.
% It reads input data from the file co_vdp2uni.mat,
% reconstructs the phase model and quantifies the coupling.
% The data are from simulation of two unidirectionally coupled 
% van der Pol oscillators, see manual for parameters.
%
disp(' ');disp(' ');disp(' ');disp(' ');
disp('--------  Starting co_example3  -----------');
pi2=pi+pi;
load co_vdp2uni.mat;
% The previous line loads to wokspace three variables:
%    signals x1 and x2, 
%    sampling frequency fsamp. 
%%%%%%%%%%%%%%   step 1: computation of protophases  %%%%%%%%%%%%%%%%%%%%%
%
% In simple cases like this one, the protophases can be computed via
% the Hilbert transform
theta1= co_hilbproto(x1); % First protophase, no plot of the embedding, 
%                           default parameter values
theta2= co_hilbproto(x2); % Second protophase: also without plot.
% Note that the program automatically checks the minimal amplitude,
% even if the corresponding output parameter is skipped in the call, 
% and issues a warning, if the data are not good enough for 
% the Hilbert transform.
%
%%%%%%%%%%%%% step 2: bivariate transformation %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%   by means of the high-level function  %%%%%%%%%%%%%%%%%
Forder=10;
[phi1,phi2,omeg1,omeg2,q1,q2,norm1,norm2,dirin]...
              = co_ittransf2(theta1, theta2, Forder, fsamp);
% Plot of coupling functions in the window number 3
co_plot2cplf(omeg1+q1,omeg2+q2,0,1,'\phi_1','\phi_2',...
    '\omega_1+Q_1(\phi_1,\phi_2)','\omega_2+Q_2(\phi_2,\phi_1)',...
    'True coupling function after bivariate transformation');
%
%%%%%%%%%%    step 3: quantification of coupling  %%%%%%%%%%%%%%%%%%%%
%
siphase=co_sync(phi1,phi2,1,1);
disp(['Synchronization index from phases ' num2str(siphase)]); 
disp(['Directionality index ' num2str(dirin)]); 
%
disp('--------  End of co_example3  --------');
end