clear all;

%Dioden Laser Kennlinie
%daten einlesen
[titel_d_k,b]=mhdrload('d_laser_kennlinie.dat');

Id=b(:,1);
A=b(:,2);
div=b(:,3);
gain=b(:,4);
d_A=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;

%Fit
	lin=[1:11];
	%Kurvenfit Pld = a + b * Id
	X=[ones(size(Id(lin))),Id(lin)];
	k=X\Pld(lin);
	a=k(1);
	b=k(2);
	%Fehler
	alpha11=sum(d_Pld(lin));
	alpha12=sum(d_Pld(lin).*Id(lin));
	alpha22=sum(d_Pld(lin).*(Id(lin).^2));
	D=alpha11*alpha22-alpha12^2;
	sigma_b=alpha11/D;
	sigma_a=alpha22/D;
	

figure(1);clf;
hold on;
p1=errorbar(Id,Pld,d_Pld,'.r');
i=[0:max(Id)];
p2=plot(i,a+b.*i,' b-');

ax1=gca;
set(ax1,'XLim',[0,max(Pld)+200])
set(ax1,'YLim',[0,max(Id)*1.1])

le1=legend([p1(1),p2],'P_{LD}',['linearer Fit I_{LD}=a+b \cdot I_D b=',num2str(b),'\pm ',num2str(sigma_b)],4);
xl1=xlabel('Strom der Laserdiode I_D / mA');
yl1=ylabel('Strom der Photodiode I_{LD} / mA');

hold off;




%Absorptionsspektrum
[titel_abs,b]=mhdrload('absorptionsspektrum.dat');
Id=440;
T=b(:,1);
A=b(:,2);
div=b(:,3);
gain=b(:,4);
d_A=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;
figure(2);clf;
errorbar(T,Pld,d_Pld);


%Messung bei Konstantem Lambda des diodenlasers: Temperaturabhängigkeit
[titel_konst_l,b]=mhdrload('konstantes_lambda.dat');
Id=b(:,1);
T=b(:,2);
A=b(:,3);
div=b(:,4);
gain=b(:,5);
d_A=0.1;
d_T=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;
figure(3);clf;
plot(Id,T);


%Messung der Spontanen Emission
[titel_spontan,b]=mhdrload('spontane_emission.dat');
t=b(:,1);
A=b(:,2);
div=b(:,3);
gain=b(:,4);
d_A=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;
figure(4);clf;
errorbar(t,Pld,d_Pld);


%Messung Nd YAG Laserkennlinie
[titel_kennlinie,b]=mhdrload('laserkennlinie.dat');
Id=b(:,1);
T=b(:,2);
A=b(:,3);
div=b(:,4);
gain=b(:,5);
d_A=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;
figure(5);clf;
errorbar(Id,Pld,d_Pld);



%Messung Nd YAG bei verschiedenen Pumpfrequenzen
[titel_scan,b]=mhdrload('frequenzscan.dat');
T=b(:,1);
A=b(:,2);
div=b(:,3);
gain=b(:,4);
d_A=0.1;

Pld = A.*div./gain;
d_Pld=d_A.*div./gain;
figure(6);clf;
errorbar(T,Pld,d_Pld);


%Messung Nd YAG mit Frequenzverdoppler Kristal
[titel_scan,b]=mhdrload('doppel1.dat');
Id=b(:,1);
T=b(:,2);
A_yag=b(:,3);
div_yag=b(:,4);
gain_yag=b(:,5);
A_kts=b(:,6);
div_kts=b(:,7);
gain_kts=b(:,8);
d_A=0.1;

Pld_yag = A_yag.*div_yag./gain_yag;
d_Pld_yag=d_A.*div_yag./gain_yag;

Pld_kts = A_kts.*div_kts./gain_kts;
d_Pld_kts=d_A.*div_kts./gain_kts;

figure(7);clf;
errorbar(Pld_yag,Pld_kts,d_Pld_kts);






%Messung Nd YAG mit Frequenzverdoppler Kristal
[titel_scan,b]=mhdrload('doppel2.dat');
Id=b(:,1);
T=b(:,2);
A_yag=b(:,3);
div_yag=b(:,4);
gain_yag=b(:,5);
A_kts=b(:,6);
div_kts=b(:,7);
gain_kts=b(:,8);
d_A=0.1;

Pld_yag = A_yag.*div_yag./gain_yag;
d_Pld_yag=d_A.*div_yag./gain_yag;

Pld_kts = A_kts.*div_kts./gain_kts;
d_Pld_kts=d_A.*div_kts./gain_kts;

figure(8);clf;
errorbar(Pld_yag,Pld_kts,d_Pld_kts);
