data=readtable('apo_difference.txt');
wavelength=table2array(data(:,1));
Apo6803Diff=table2array(data(:,2));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% fiting the difference spectra with the difference  %%%%%%%%%%%%%%%


reducedWL=wavelength(100:220);
reducedApo6803Diff=Apo6803Diff(100:220);


fo_AbsDiff = fitoptions('gauss3');
fo_AbsDiff.Lower = [ -.02 699 000, -.02 703 000, -.02 701 000];
fo_AbsDiff.Upper = [ 0000 704 50, 0000 705 50, 0000 715 50];

Car_fit = fit(reducedWL, reducedApo6803Diff, 'gauss3',fo_AbsDiff);


CarC1 = Car_fit.a1*exp(-((reducedWL-Car_fit.b1)/Car_fit.c1).^2);
CarC2 = Car_fit.a2*exp(-((reducedWL-Car_fit.b2)/Car_fit.c2).^2);
CarC3 = Car_fit.a3*exp(-((reducedWL-Car_fit.b3)/Car_fit.c3).^2);


Car_totalfit=CarC1+CarC2+CarC3;

plot(reducedWL, reducedApo6803Diff, reducedWL, CarC1, ...
     reducedWL, CarC2, ...
     reducedWL, CarC3, ...
     reducedWL, CarC1+CarC2+CarC3)