function [rr_pos,rr_neg]=recurr_intervals(varargin);

if (length(varargin)<2)
    global Y;
    Y=varargin{1};
    figure;
    
    
end
n=length(y);
times_pos=[];
times_neg=[];
for i=1:n
    if y(i)>thr
        times_pos=[times_pos,i];
    end
    if y(i)<-thr
        times_neg=[times_neg,i];
    end
end
n_pos=length(times_pos);
if (n_pos)>1
    rr_pos=times_pos(2:n_pos)-times_pos(1:n_pos-1);
else
    rr_pos=[];
end
n_neg=length(times_neg);
if (n_neg)>1
    rr_neg=times_neg(2:n_pos)-times_neg(1:n_pos-1);
else
    rr_neg=[];
end