clear xx,yy;

%%%%%%incarcarea vectorului yy cu date din fisier
if (u==1)
   h1=figure;h2=figure;h3=figure;
end
yy=(eval(nume))';xx=1:length(yy);

figure(h1);

%%%%%%stabilire translatie in domeniul lamda_m - lamda_mm
lungime_vector=length(yy);
translatie=(lamda_mm-lamda_m)/lungime_vector;
plot(xx*translatie+lamda_m,yy);
xlabel('Lungimea de unda (nm)')
ylabel('Transmisia (u. a.)')
title('Spectrul de transmisie')

%%%%%%prima filtrare a datelor cu ajutorul functiei spline
%%%%%%the firs filtration with the spline function
figure(h2);
yi=spline(xx(1:5:lungime_vector)*translatie+lamda_m,yy(1:5:lungime_vector),xx(1:3:lungime_vector)*translatie+lamda_m);
yii=spline(xx(mouse_x(1):5:mouse_x(2))*translatie+lamda_m,yy(mouse_x(1):5:mouse_x(2)),xx(mouse_x(1):3:mouse_x(2))*translatie+lamda_m);

%%%%%%afisarea graficului dupa prima filtrare a datelor
%%%%%%the graph display after the first data's filtration
plot(xx(1:3:lungime_vector)*translatie+lamda_m,yi,xx(mouse_x(1):3:mouse_x(2))*translatie+lamda_m,yii);
xlabel('Lungimea de unda (nm)')
ylabel('Transmisia (u. a.)')
%title('Aproximarea spline cubica a curbei de transmitanta')
title('Aproximarea spectrului de transmisie cu functii de tip spline')

%%%%%%a doua filtrare a datelor cu prin fit-are cu polinoane de diferite garde
%%%%%%the second data filtration by fit with varied degres polynomial
x=xx(mouse_x(1):mouse_x(2));
y=yy(mouse_x(1):mouse_x(2));
c3=polyfit(x,y,3);    
c4=polyfit(x,y,4);  
c5=polyfit(x,y,5);
c15=polyfit(x,y,15);
yc3=polyval(c3,x);
yc4=polyval(c4,x);
yc5=polyval(c5,x);
yc15=polyval(c15,x);
%%%%%%calculul erorilor aproximarilor fata da datele de intrare
eroarea3=sum((y-yc3).*(y-yc3))/100;
eroarea4=sum((y-yc4).*(y-yc4))/100;
eroarea5=sum((y-yc5).*(y-yc5))/100;
eroarea15=sum((y-yc15).*(y-yc15))/100;
yid=spline(x*translatie+lamda_m,y,x*translatie+lamda_m);
%%%%%%afisarea graficului cu  toate reazultatele prelucrarilor
figure(h3);
plot(x*translatie+lamda_m,yid,x*translatie+lamda_m,yc3,x*translatie+lamda_m,yc4,x*translatie+lamda_m,yc5,x*translatie+lamda_m,yc15);
xlabel('Lungimea de unda (nm)')
ylabel('Transmisia (u. a.)')
%title(['Aproximarea spline cubica a curbei de transmitanta' ' ' num2str(mouse_x_g(1)) '-' num2str(mouse_x_g(2))]);
title(['Aproximarea spectrului de transmisie cu functii de tip spline' ' ' num2str(mouse_x_g(1)) '-' num2str(mouse_x_g(2))]);
movgrad3=['mov->grad3 err = ' num2str(eroarea3)];
albastrugrad4=['albastru->grad4 err = ' num2str(eroarea4)];
rosugrad5=['rosu->grad5 err = ' num2str(eroarea5)];
verdegrad15=['verde->grad15 err = ' num2str(eroarea15)];

%%%%%%pastreaza ca data de iesire vectorul ce coresspunde cel mai bine cerintelor
%%%%%%the keeping of the most suitable vector as output date
i2=yc4;
