function pli=pli_hilbert(filtered1,filtered2)

%INPUT:filtered1,2 = 1 x n where n = number of samples
%signals should be filtered 
%OUTPUT: PLI VALUE
%LACHAUX et al.1999

%STAVROS DIMITRIADIS 4/2007
%http://users.auth.gr/stdimitr/

hilbert1=hilbert(filtered1);
hilbert2=hilbert(filtered2);

len=length(hilbert1);

phase1=angle(hilbert1);
phase2=angle(hilbert2);

unwrap1=unwrap(phase1);
unwrap2=unwrap(phase2);

pli=0;
plits=0; 

    for k=1:len
        value=(exp(i*(unwrap1(k)-unwrap2(k))));
        plits=plits + value;
    end
    

    pli=abs(plits)/len;
