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 e10_Run01_d00.lvm
load e10_Run01_d05.lvm
load e10_Run01_d10.lvm
load e10_Run01_d15.lvm
load e10_Run01_d20.lvm
load e10_Run01_d25.lvm

% Compact names.
A=e10_Run01_d00;
B=e10_Run01_d05;
C=e10_Run01_d10;
D=e10_Run01_d15;
E=e10_Run01_d20;
F=e10_Run01_d25;


% 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=e10_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=e10_Run01_d05;
    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=e10_Run01_d10;
    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);
    

    % Interpolation and filter at d15.
    D=e10_Run01_d15;
    for i = 1:length(D)-1
        if abs(D(i+1,j) - D(i,j))>innerTreshold || D(i,j)<lowerThreshold || D(i,j)>upperThreshold; 
            D(i,j) = NaN;        
        end
    end
    D(any(isnan(D),2),:) = [];
    etaD(:,j)=interp1(D(:,1),D(:,j), t, interpolation_method);
    

    % Interpolation and filter at d20.
    E=e10_Run01_d20;
    for i = 1:length(E)-1
        if abs(E(i+1,j) - E(i,j))>innerTreshold || E(i,j)<lowerThreshold || E(i,j)>upperThreshold; 
            E(i,j) = NaN;        
        end
    end
    E(any(isnan(E),2),:) = [];
    etaE(:,j)= interp1(E(:,1),E(:,j), t, interpolation_method);
    
    
    % Interpolation and filter at d25.
    F=e10_Run01_d25;
    for i = 1:length(F)-1
        if abs(F(i+1,j) - F(i,j))>innerTreshold || F(i,j)<lowerThreshold || F(i,j)>upperThreshold; 
            F(i,j) = NaN;        
        end
    end
    F(any(isnan(F),2),:) = [];
    etaF(:,j)= interp1(F(:,1),F(:,j), t, interpolation_method);
      
end

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


% Collect probe data in an MxN matrix
ETA=[   etaA(:,1)  etaB(:,1)  etaC(:,1)  etaD(:,1)  etaE(:,1)  etaF(:,1)... 
        etaA(:,2)  etaB(:,2)  etaC(:,2)  etaD(:,2)  etaE(:,2)  etaF(:,2)...
        etaA(:,3)  etaB(:,3)  etaC(:,3)  etaD(:,3)  etaE(:,3)  etaF(:,3)...
        etaA(:,4)  etaB(:,4)  etaC(:,4)  etaD(:,4)  etaE(:,4)  etaF(:,4)... 
        etaA(:,5)  etaB(:,5)  etaC(:,5)  etaD(:,5)  etaE(:,5)  etaF(:,5)... 
        etaA(:,6)  etaB(:,6)  etaC(:,6)  etaD(:,6)  etaE(:,6)  etaF(:,6)...
        etaA(:,7)  etaB(:,7)  etaC(:,7)  etaD(:,7)  etaE(:,7)  etaF(:,7)... 
        etaA(:,8)  etaB(:,8)  etaC(:,8)  etaD(:,8)  etaE(:,8)  etaF(:,8)... 
        etaA(:,9)  etaB(:,9)  etaC(:,9)  etaD(:,9)  etaE(:,9)  etaF(:,9)...
        etaA(:,10) etaB(:,10) etaC(:,10) etaD(:,10) etaE(:,10) etaF(:,10)... 
        etaA(:,11) etaB(:,11) etaC(:,11) etaD(:,11) etaE(:,11) etaF(:,11)... 
        etaA(:,12) etaB(:,12) etaC(:,12) etaD(:,12) etaE(:,12) etaF(:,12)...
        etaA(:,13) etaB(:,13) etaC(:,13) etaD(:,13) etaE(:,13) etaF(:,13)...
        etaA(:,14) etaB(:,14) etaC(:,14) etaD(:,14) etaE(:,14) etaF(:,14)... 
        etaA(:,15) etaB(:,15) etaC(:,15) etaD(:,15) etaE(:,15) etaF(:,15)...
        etaA(:,16) etaB(:,16) etaC(:,16) etaD(:,16) etaE(:,16) etaF(:,16) ];

    
    
    
    
toc








