% obtain  mean return flow and infragravity velocities flow velocity for the LIP-experiment
%
%
%
%
clear all

ij(1,:) = [1 2  3 4  7 8  10  12 15 16 17];
ij(2,:) = [2 13 4 5  7 8  10  13  4  5  6];
id      = [2  3 4 5  7 8  10  3  4  5  6];  % position of pressure sensor 
ib      = [1  2 3 4  7 8  12  12 12 18  18];  % corresponding bottom profile
xc      = [65 102 115 130 145 152 170 102 115 130 138]; % position of carriage
ziemf   = [0.1 0.2 0.4 0.7 1.1]; % height above the bed
zidro   = 4.1-[3 3 3.2 3.3 3.55 3.5 3.7 3.6 3.44 3.4];


Tp   = 5; 
nij = length(ij);
for j = 1:nij
   test = '#1b0000'; 
   testb = '%1b003c';
   inst1 = 'DRO00'; 
   inst2 = 'EMF00';
 
   %for j = 2:2
   if ij(1,j) < 10
      test(5:5) = num2str(ij(1,j))
   else
      test(4:5) = num2str(ij(1,j))
   end
   if ij(2,j) < 10
      test(7:7) = num2str(ij(2,j))
   else
      test(6:7) = num2str(ij(2,j))
   end
   
    
   % get velocity time series
   
   for ist=1:5
      inst2(4:5) = num2str(10+2*ist-1)
      [t,g] = get_series(test,inst2,0);
      Um(ist) = mean(g);
      
      % obtain low frequency velocities
      ng = length(g);
      ng1 = floor(ng/10);
      ng2 = ng-ng1;
      dt = t(2)-t(1);
      U = detrend(g(ng1:ng2));
      [u_lo,u_hi] = f_flt(U,1/Tp/2,dt);
      Urms_lo(ist,j) = std(u_lo);
      
      % obtain asymmtry
      us(ist,j) = mean(u_hi.^3);
%       guls(ist,j) = mean(3*u_lo.*u_hi.^2)+mean(u_lo.^3);
       guls(ist,j) = mean(3*u_lo.*u_hi.^2);
    figure(1)
    subplot(311),plot(u_hi)
    if ist == 1
        hold
    end
    subplot(312),plot(u_lo)
    if ist == 1
        hold
    end
    subplot(313),plot(3*u_lo.*u_hi.^2+u_lo.^3)
    if ist == 1
        hold
    end
    
    pause(.1)
    j
    ist
   end
   
end
   
  
