%Einlesen der .csv-Datei

%TE

fid_TE=fopen('Datei_TE')
M=textscan(fid_TE,'%s','headerlines',2,'delimiter',';');
M=reshape(M{1},76,[]);
fclose(fid_TE)
M(5:end,:)=strrep(M(5:end,:),',','.');
numeric_TE_V1=cellfun(@str2num,M(5:end,:));

%TK

fid_TK=fopen('Datei_TK')
M2=textscan(fid_TK,'%s','headerlines',4,'delimiter',';');
M2=reshape(M2{1},19,[]);
fclose(fid_TK)
M2(5:end,:)=strrep(M2(5:end,:),',','.');
numeric_TK=cellfun(@str2num,M2(5:end,:));


%Deklarieren der Datei

%TE
y_TE_1=(numeric_TE_V1)'
y_TE=y_TE_1(875,:)			%Anpassen der Dimensionen

%TK
y_TK_K=(numeric_TK)'
y_TK_C=y_TK_K(:,:)-273,15                   %Umrechnung in C

% Erstellung des Zeitvektors

%TE
y_size_TE = size (y_TE,1)
time=0:0.5:((y_size_TE-1)/2)               %Vektor ungerade
%time = 0:0.5:(y_size_TE/2)                  %Vektor gerade

%TK
y_size_TK = size (y_TK_C,1)
time_TK=0:0.5:((y_size_TK-1)/2)   %Vektor ungerade
% time_TK = 0:0.5:(y_size_TK/2)           %Vektor gerade


%Plotten

hold on

%TE
% plot(time, y_TE(:,1),'k')                %Sollwert Temperatur
% plot(time, y_TE(:,2))                    %Sollwert Druck

% plot(time, y_TE(:,4),'g')                %T1
% plot(time, y_TE(:,5),'c')                %T2
% plot(time, y_TE(:,6),'m')                %T3
% plot(time, y_TE(:,7),'k')                %T4
% plot(time, y_TE(:,14))                   %T11
plot(time, y_TE(:,15),'k')               %T12
% plot(time, y_TE(:,16))                   %T13

%TK
% plot(time_TK, y_TK_C(:,1))      %POIO = T4
% plot(time_TK, y_TK_C(:,3))      %POI1 = T13
% plot(time_TK, y_TK_C(:,5))      %POI2 = T11
% plot(time_TK, y_TK_C(:,7))      %POI3 = T1
plot(time_TK, y_TK_C(:,9),'b')  %POI4 = T12
% plot(time_TK, y_TK_C(:,11))     %AOI0


%Nherungsfunktion

%Polynom

%TE
polytime=(time)'
p1_TE=polyfit(polytime(:,1),y_TE(:,15),10)
p1plot_TE=polyval(p1_TE,time)
plot(time, p1plot_TE,'k-.')       

%TK
polytime_TK=(time_TK)'
p1_TK=polyfit(polytime_TK(:,1),y_TK_C(:,9),10)
p1plot_TK=polyval(p1_TK,time_TK)
plot(time_TK, p1plot_TK,'b-.')       


%Spline

%TE
pp_TE=spline(time, y_TE(:,15));
spline1_TE=ppval(pp_TE,time);
plot(time,spline1_TE,'k:');
[breaks,coefs,l,k,d]=unmkpp(pp_TE);


%TK
pp_TK=spline(time_TK, y_TK_C(:,9));
spline1_TK=ppval(pp_TK,time_TK);
plot(time_TK,spline1_TK,'b:');
[breaks,coefs,l,k,d]=unmkpp(pp_TK);

hold off


%Offset

delta_y=spline1_TK-spline1_TE