close all
clear all
% ***** read u
load u_v_time_4nodes_re1000.dat
fil=u_v_time_4nodes_re1000;
u1=fil(:,1);
v1=fil(:,2);
u2=fil(:,3);
v2=fil(:,4);
u3=fil(:,5);
v3=fil(:,6);
u4=fil(:,7);
v4=fil(:,8);

% time step
dt=8.177E-04;
n=length(u1);
% compute time array
t=dt:dt:n*dt;

%%%%%%%%%%%%%%%% plotting section %%%%%%%%%%%%%%%%%%%%%%%%%%
% plot u
figure(1)
plot(t,u2)
hold
plot(t,u3,'r--')
xlabel('t','fontsize',[20])
ylabel('u','fontsize',[20])
handle=gca
set(handle,'fontsize',[20])
%print u_time.ps -deps

% autocorrelation
figure(2)

u_fluct=u2-mean(u2);
nstep=length(u2);

imax=100;
two_uu_t=zeros(imax,1);
for tt=1:imax
tau=tt-1; %time separation
for it=1:nstep-imax-2
i0=it+tau;
two_uu_t(tt)=two_uu_t(tt)+u_fluct(it)*u_fluct(i0);
end
end
two_uu_t=two_uu_t/two_uu_t(1); %normalize _uu_t so that two_uu_t(1)=1

% use xcorr
two=xcorr(u_fluct,imax,'coeff'); 
% two=1 at i=imax+1; two(1:imax)=correlations for negartive separation

plot(t(1:imax),two_uu_t,'linewidth',2)
hold
plot(t(1:imax+1),two(imax+1:end),'r--','linewidth',2)

handle=gca
set(handle,'fontsize',[20])
%
