% using t matrix for what comes out of the lri finder

load tenminilandec_190sec
trace=tenminilandec_190sec;

load flat_trace30; flat_trace=flat_trace30;

load LRI_find30
t=LRI_find30;

I=find( t(:,3)>=.8 );
inc=1000;

for cc=1:max(size(I))
    
    clf
    ind=I(cc);
    
    % original trace
    subplot(2,1,1)
    plot( trace(t(ind,1):t(ind,1)+inc) )
    hold on
    plot( trace(t(ind,2):t(ind,2)+inc),'r' )
    % compute its correlation (i.e. on original traces)
    m=trace(t(ind,1):t(ind,1)+inc);
    r=trace(t(ind,2):t(ind,2)+inc);
    cr= ( (m-mean(m))'*(r-mean(r))/inc )/(std(m)*std(r));
    title( sprintf('corr %f',cr) )
        
    % flattened trace
    subplot(2,1,2)    
    plot( flat_trace(t(ind,1):t(ind,1)+inc) )
    hold on
    plot( flat_trace(t(ind,2):t(ind,2)+inc),'r' )
    
    title( sprintf('motif %d repeat %d corr %f',t(ind,1),t(ind,2),t(ind,3) ) )
    
    pause
    
end


