%% Serially-correlated data with different lag-1 autocorrelations
%
%% User-specified parameters

N = 30;
rvect = [-0.5 0 0.2 0.7];

for k = 1:length(rvect)
  r = rvect(k);
  x = rednoise(r,N);
  xbar = mean(x);
  sigx = std(x);
  Nstar = N*(1-r)/(1+r);
  subplot(2,2,k)
  plot(1:N,x,'x',...
       [0 N],xbar*[1 1],'r--',...
       [0 N],(xbar+sigx/sqrt(Nstar))*[1 1],'m-.')
    xlabel('j')
  ylabel('x_j')
  ylim([-3 3])
  title(['r = ' num2str(r) ', N = ' num2str(N) ',N* = ' num2str(Nstar)])
  if(k==1)
    legend('Data','xbar','xbar \pm \sigma_m')
  end
  hold on
  plot([0 N],(xbar-sigx/sqrt(Nstar))*[1 1],'m-.',...
       [0 N],[0 0],'k-')
  hold off
end