function [e,A,B]=cross_sampen(x,y,M,r,sflag); %function [e,A,B]=cross_sampen(x,y,M,r); % % The Cross-sample Entropy (Cross-SampEn) quantified the degree of synchronization between AP and ML, AP and V, and ML and V accelerations. % Cross-SampEn is the negative natural logarithm of the conditional probability that epochs with length m that match point-wise % in the two related signals, repeat itself for m+1 points, within a tolerance of r (in the present study m = 5 and r = 0.3) %Input % %x,y input data %M maximum template length %r matching tolerance %sflag flag to standardize signals(default yes/sflag=1) % %Output % %e sample entropy estimates for m=0,1,...,M-1 %A number of matches for m=1,...,M %B number of matches for m=0,...,M-1 excluding last point if ~exist('sflag')|isempty(sflag),sflag=1;end y=y(:); x=x(:); ny=length(y); nx=length(x); N=nx; if sflag>0 y=y-mean(y); sy=sqrt(mean(y.^2)); y=y/sy; x=x-mean(x); sx=sqrt(mean(x.^2)); x=x/sx; end lastrun=zeros(nx,1); run=zeros(nx,1); A=zeros(M,1); B=zeros(M,1); p=zeros(M,1); e=zeros(M,1); for i=1:ny for j=1:nx if abs(x(j)-y(i))