close all
clear all

pkg load signal % comment out for matlab

rate=0.2
N=1e4

sup=1
sdown=0

% simulate telegraph noise
r= (rand(N,1)< rate);
s=zeros(N,1);
s(1)=sup;
for i=2:N
    if r(i)
        if s(i-1)==sup
            s(i)=sdown;
        else
            s(i)=sup;
        end    
    else
       s(i)=s(i-1) ;
    end    
end

% these plots looks weird....
maxlag=ceil(5/rate)
c=xcov(s,s, maxlag,'unbiased');
plot(c)
hold on

cr=xcorr(s,s, maxlag,'unbiased');
plot(cr)

