tic

clear all
close all

% Load of experimental data. d00, d05, ... , d20, d25 denotes the measurement
% positions which are extended with 5cm from the original position of d00.
load e02_Run01_d00.lvm
load e02_Run02_d00.lvm
load e02_Run03_d00.lvm

% Compact names.
A=e02_Run01_d00;
B=e02_Run02_d00;
C=e02_Run03_d00;


% Discrete time steps t from first data column.
t=A(:,1);

% Interpolation method and thresholds
interpolation_method = 'cubic';
innerTreshold=0.50;
lowerThreshold=-4.00;
upperThreshold=4.00;


for j=2:17
    % Interpolation and filter at d00.
    A=e02_Run01_d00;
    for i = 1:length(A)-1
        % Criteria for drop-outs.
        if abs(A(i+1,j) - A(i,j))>innerTreshold || A(i,j)<lowerThreshold || A(i,j)>upperThreshold; 
            % Drop out data points are set to not a number (NaN).
            A(i,j) = NaN;        
        end
    end
    % Interpolation.
    A(any(isnan(A),2),:) = [];
    etaA(:,j)= interp1(A(:,1),A(:,j), t, interpolation_method);
    
    
    % Interpolation and filter at d05.
    B=e02_Run02_d00;
    for i = 1:length(B)-1
        if abs(B(i+1,j) - B(i,j))>innerTreshold || B(i,j)<lowerThreshold || B(i,j)>upperThreshold; 
            B(i,j) = NaN;        
        end
    end
    B(any(isnan(B),2),:) = [];
    etaB(:,j)= interp1(B(:,1),B(:,j), t, interpolation_method);
    
    
    % Interpolation and filter at d10.
    C=e02_Run03_d00;
    for i = 1:length(C)-1
        if abs(C(i+1,j) - C(i,j))>innerTreshold || C(i,j)<lowerThreshold || C(i,j)>upperThreshold; 
            C(i,j) = NaN;        
        end
    end
    C(any(isnan(C),2),:) = [];
    etaC(:,j)=interp1(C(:,1),C(:,j), t, interpolation_method);
      
end

% Delete first coulumn of zeros
etaA(:,1)=[]; etaB(:,1)=[]; etaC(:,1)=[];
    
    
    
    
toc








