%HISTO Summary of this function goes here
%   Detailed explanation goes here
clc

% Lese Datei A ein und Interpoliere
a = load('test_3x3.asc');
disp(['Länge: ' num2str(length(a))]);
xa = a(:,1);
ya = a(:,2);
za = a(:,3);
[Xa,Ya,Za] = meshgrid(xa,ya,za)
[Xia,Yia] = meshgrid(-3:0.01:3,-3:0.01:3);   
za2 = interp2(Xa, Ya, Za, Xia, Yia,'cubic');


% Lese Datei B ein und Interpoliere
b = load('test_10x10.asc');
disp(['Länge: ' num2str(length(b))]);
xb = b(:,1);
yb = b(:,2);
zb = b(:,3);
[Xb,Yb,Zb] = meshgrid(xb,yb,zb)
[Xib,Yib] = meshgrid(-3:0.01:3,-3:0.01:3); 
zb2 = interp2(Xb, Yb, Zb, Xib, Yib,'cubic');

length(za);
length(zb2);
% Differenzprofil
zdiff = za2-zb2;

% Plotte Histogramme der Rauheitsprofile für A und B und Diff
subplot(3,1,1); hist(za2,400); title('3x3')
subplot(3,1,2); hist(zb2,400); title('10x10')
subplot(3,1,3); hist(zdiff,400); title('diff')


% Plotte Rauheitsprofile von A und B unnd Diff
figure
subplot(3,1,1); plot(za2); title('3x3')
subplot(3,1,2); plot(zb2); title('10x10')
subplot(3,1,3); plot(zdiff); title('diff')

% Plotte Profil B und interpolierte Näherung
figure
subplot(2,1,1); plot(zb); title('zb - 10x10 - normal')
subplot(2,1,2); plot(zb2); title('zb2 - 10x10 - interp2')

%Strukturfunktion und Autokorrelation
% S = sort(2*(var(zb) - xcorr(zb))); 
% figure
% loglog(S)
% figure
% plot(S)

