function varargout = vliv_krok(varargin)
% VLIV_KROK MATLAB code for vliv_krok.fig
%      VLIV_KROK, by itself, creates a new VLIV_KROK or raises the existing
%      singleton*.
%
%      H = VLIV_KROK returns the handle to a new VLIV_KROK or the handle to
%      the existing singleton*.
%
%      VLIV_KROK('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in VLIV_KROK.M with the given input arguments.
%
%      VLIV_KROK('Property','Value',...) creates a new VLIV_KROK or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before vliv_krok_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to vliv_krok_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help vliv_krok

% Last Modified by GUIDE v2.5 29-May-2015 07:44:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @vliv_krok_OpeningFcn, ...
                   'gui_OutputFcn',  @vliv_krok_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before vliv_krok is made visible.
function vliv_krok_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to vliv_krok (see VARARGIN)

% Choose default command line output for vliv_krok
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes vliv_krok wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = vliv_krok_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global gFWHM D F
FDD = str2double(get(handles.edit1,'String'));
FID = str2double(get(handles.edit2,'String'));
D = str2double(get(handles.edit6,'String'));
F = str2double(get(handles.edit3,'String'));
T=str2double(get(handles.edit4,'String'));
t=str2double(get(handles.edit5,'String'));
uroven=str2num(get(handles.edit10,'String'));
barvy=['r' 'b' 'g' 'm' 'k'];

a(1)=get(handles.radiobutton1,'Value');
a(2)=get(handles.radiobutton2,'Value');
a(3)=get(handles.radiobutton5,'Value');
a(4)=get(handles.radiobutton4,'Value');

krok=5

for i=1:krok
if a(1)==1;
    if i==1
    FDD=str2double(get(handles.edit8,'String'));
    mFDD=str2double(get(handles.edit9,'String'));
    dFDD=(mFDD-FDD)/krok;
    else
    FDD=FDD+dFDD;
    end
elseif a(2)==1
    if i==1
    FID=str2double(get(handles.edit8,'String'));
    mFID=str2double(get(handles.edit9,'String'));
    dFID=(mFID-FID)/krok;
    else
    FID=FID+dFID;
    end
elseif a(3)==1
    if i==1
    F=str2double(get(handles.edit8,'String'));
    mF=str2double(get(handles.edit9,'String'));
    dF=(mF-F)/krok;
    else
    F=F+dF;
    end
elseif a(4)==1
    if i==1
    D=str2double(get(handles.edit8,'String'));
    mD=str2double(get(handles.edit9,'String'));
    dD=(mD-D)/krok;
    else
    D=D+dD;
    end
end
DID=FDD-FID;
DIR = (FID/FDD)*D;
FIR = (DID/FDD)*F;
Ep=2*pi*((T/t)/T);
FWHM=sqrt((FIR*FIR)+(DIR*DIR)+(Ep*Ep));


gFWHM(i)=FWHM;

[x y]=vyp_PSF(FWHM,D,F);

[Mx MTF]=vyp_MTF(y,FWHM);

mMx(i)={Mx};
mMTF(i)={MTF};

krivkax(i)={x};
krivkay(i)={y};
aa(i)={num2str(FWHM)}
% lPSF(i)={['FWHM=' aa]}


if a(1)==1
        zav(i,1)=FDD;
        zav(i,2)=FWHM;
        tmp=abs(MTF-uroven);
        [idc,tmp2] =min(tmp);
        zav(i,3)=Mx(tmp2);
        men_par='Vzdálenost ohnisko-detektory [mm]'
     elseif a(2)==1
        zav(i,1)=FID;
        zav(i,2)=FWHM;
        tmp=abs(MTF-uroven);
        [idc,tmp2] =min(tmp);
        zav(i,3)=Mx(tmp2);
        men_par='Vzdálenost ohnisko-izocentrum [mm]'        
elseif a(3)==1
    zav(i,1)=F;
        zav(i,2)=FWHM;
        tmp=abs(MTF-uroven);
        [idc,tmp2] =min(tmp);
        zav(i,3)=Mx(tmp2);
        men_par='Velikost optického ohniska [mm]'
elseif a(4)==1
        zav(i,1)=D;
        zav(i,2)=FWHM;
        tmp=abs(MTF-uroven);
        [idc,tmp2] =min(tmp);
        zav(i,3)=Mx(tmp2);
        men_par='Apertura detektoru [mm]'
     end

end

for j=1:krok
    axes(handles.axes2)
    plot(cell2mat(krivkax(j)),cell2mat(krivkay(j)),'color',barvy(j));
    tmp=cell2mat(aa(j))
    lPSF(j)={['FWHM = ' tmp]};
%     lPSF(j)=['FWHM = ' 'lPSF(j)'];
    if j==1
    legend(cell2mat(lPSF(1)));
    elseif j==2
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)));
        elseif j==3
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)));
        elseif j==4
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)));
        elseif j==5
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)),cell2mat(lPSF(5)));
    end
   
    hold on
     pause(0.2)
     axes(handles.axes4)
     
     plot(zav(j,1),zav(j,2),'*')
     xlim([zav(1,1)*0.9 zav(end,1)*1.1])
     ylim([min(zav(:,2))*0.9 max(zav(:,2))*1.1])
     hold on
     
     
end


%%%%%%%%%% %pro vysledky
% 
% for j=1:krok
%     figure(20)
% subplot(1,2,1)
%     plot(cell2mat(krivkax(j)),cell2mat(krivkay(j)),'color',barvy(j));
%     tmp=cell2mat(aa(j))
%     lPSF(j)={['FWHM = ' tmp]};
% %     lPSF(j)=['FWHM = ' 'lPSF(j)'];
%     if j==1
%     legend(cell2mat(lPSF(1)));
%     elseif j==2
%         legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)));
%         elseif j==3
%         legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)));
%         elseif j==4
%         legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)));
%         elseif j==5
%         legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)),cell2mat(lPSF(5)));
%     end
%    
%     hold on
%      pause(0.2)
%      figure(21)
%      subplot(1,2,1)
%      
%      plot(zav(j,1),zav(j,2),'*')
%      xlim([zav(1,1)*0.9 zav(end,1)*1.1])
%     ylim([min(zav(:,2))*0.9 max(zav(:,2))*1.1])
%      hold on
%      
%      
% end
% 
% figure(20)
% subplot(1,2,1)
% ylabel('PSF')
% xlabel('Šířka [mm]')
% hold off;
% % prolx=linspace(zav(1,1),zav(end,1),200);
% % proly=linspace(zav(1,2),zav(end,2),200);
% % mproly=linspace(zav(1,3),zav(end,3),200);
% figure(21)
%      subplot(1,2,1)
% hold on
% plot(zav(:,1),zav(:,2))
% hold off
% xlabel(men_par)
% ylabel('FWHM [mm]')

%%%%%%%%%% %konec vysledku





axes(handles.axes2)
ylabel('PSF')
xlabel('Šířka [mm]')
hold off;
% prolx=linspace(zav(1,1),zav(end,1),200);
% proly=linspace(zav(1,2),zav(end,2),200);
% mproly=linspace(zav(1,3),zav(end,3),200);
axes(handles.axes4)
hold on
plot(zav(:,1),zav(:,2))
hold off
xlabel(men_par)
ylabel('FWHM [mm]')




for j=1:krok
    if j==1
    lim=cell2mat(mMx(j));
    end
    if length(lim)<length(cell2mat(mMx(j)))
        lim=cell2mat(mMx(j));
    end
    
axes(handles.axes3)
% plot(cell2mat(Mx(j)),cell2mat(MTFF(j)),'color',barvy(j))
plot(cell2mat(mMx(j)),cell2mat(mMTF(j)),'color',barvy(j))
hold on
pause(0.2)

xlim([0 lim(end-floor(length(lim)/8))])

tmp=zav(j,3);
tmp=num2str(tmp);
    lMTF(j)={['Mezní prostorová frekvence = ' tmp]};

    if j==1
    legend(cell2mat(lMTF(1)));
    elseif j==2
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)));
        elseif j==3
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)));
        elseif j==4
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)));
        elseif j==5
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)),cell2mat(lMTF(5)));
    end

axes(handles.axes5)
     plot(zav(j,1),zav(j,3),'*')
     xlim([zav(1,1)*0.9 zav(end,1)*1.1])
     ylim([min(zav(:,3))*0.9 max(zav(:,3))*1.1])
     hold on

end
axes(handles.axes3)
hold off
xlabel ('Prostorová frekvence [lp/mm]')
ylabel ('MTF')
axes(handles.axes5)
hold on
xlabel(men_par)
ylabel('Mezní prostorová frekvence [lp/mm]')
plot(zav(:,1),zav(:,3))
hold off


%%%%%%% pro vysledky
% for j=1:krok
% figure(20)
% subplot(1,2,2)
% % plot(cell2mat(Mx(j)),cell2mat(MTFF(j)),'color',barvy(j))
% plot(cell2mat(mMx(j)),cell2mat(mMTF(j)),'color',barvy(j))
% hold on
% pause(0.2)
% 
% xlim([0 lim(end-floor(length(lim)/8))])
% 
% tmp=zav(j,3);
% tmp=num2str(tmp);
%     lMTF(j)={['Mezní prostorová frekvence = ' tmp]};
% 
%     if j==1
%     legend(cell2mat(lMTF(1)));
%     elseif j==2
%         legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)));
%         elseif j==3
%         legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)));
%         elseif j==4
%         legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)));
%         elseif j==5
%         legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)),cell2mat(lMTF(5)));
%     end
% 
% figure(21)
% subplot(1,2,2)
%      plot(zav(j,1),zav(j,3),'*')
%      xlim([zav(1,1)*0.9 zav(end,1)*1.1])
%      ylim([min(zav(:,3))*0.9 max(zav(:,3))*1.1])
%      hold on
% 
% end
% figure(20)
% subplot(1,2,2)
% hold off
% xlabel ('Prostorová frekvence [lp/mm]')
% ylabel ('MTF')
% figure(21)
% subplot(1,2,2)
% hold on
% xlabel(men_par)
% ylabel('Mezní prostorová frekvence [lp/mm]')
% plot(zav(:,1),zav(:,3))
% hold off

%%%%%konec vysledky





function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
run main
close vliv_krok


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global gFWHM barvy D F

barvy=['r' 'b' 'g' 'm' 'k'];

krok=5;

for i=1:krok

FWHM=gFWHM(i);

[x y]=vyp_PSF(FWHM,D,F);

krivkax(i)={x};
krivkay(i)={y};
aa(i)={num2str(FWHM)}

end
figure
for j=1:krok
   
    plot(cell2mat(krivkax(j)),cell2mat(krivkay(j)),'color',barvy(j));
    tmp=cell2mat(aa(j));
    lPSF(j)={['FWHM = ' tmp]};
    if j==1
    legend(cell2mat(lPSF(1)));
    elseif j==2
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)));
        elseif j==3
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)));
        elseif j==4
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)));
        elseif j==5
        legend(cell2mat(lPSF(1)),cell2mat(lPSF(2)),cell2mat(lPSF(3)),cell2mat(lPSF(4)),cell2mat(lPSF(5)));
    end
   
    hold on
end
ylabel('PSF')
hold off;



% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
FDD = str2double(get(handles.edit1,'String'));
FID = str2double(get(handles.edit2,'String'));
D = str2double(get(handles.edit6,'String'));
F = str2double(get(handles.edit3,'String'));
T=str2double(get(handles.edit4,'String'));
t=str2double(get(handles.edit5,'String'));
barvy=['r' 'b' 'g' 'm' 'k'];

a(1)=get(handles.radiobutton1,'Value');
a(2)=get(handles.radiobutton2,'Value');
a(3)=get(handles.radiobutton5,'Value');
a(4)=get(handles.radiobutton4,'Value');

krok=5

for i=1:krok
if a(1)==1;
    if i==1
    FDD=str2double(get(handles.edit8,'String'));
    mFDD=str2double(get(handles.edit9,'String'));
    dFDD=(mFDD-FDD)/krok;
    else
    FDD=FDD+dFDD;
    end
elseif a(2)==1
    if i==1
    FIDD=str2double(get(handles.edit8,'String'));
    mFID=str2double(get(handles.edit9,'String'));
    dFID=(mFID-FID)/krok;
    else
    FID=FID+dFID;
    end
elseif a(3)==1
    if i==1
    F=str2double(get(handles.edit8,'String'));
    mF=str2double(get(handles.edit9,'String'));
    dF=(mF-F)/krok;
    else
    F=F+dF;
    end
elseif a(4)==1
    if i==1
    D=str2double(get(handles.edit8,'String'));
    mD=str2double(get(handles.edit9,'String'));
    dD=(mD-D)/krok;
    else
    D=D+dD;
    end
end
DID=FDD-FID;
DIR = (FID/FDD)*D;
FIR = (DID/FDD)*F;
Ep=2*pi*((T/t)/T);
FWHM=sqrt((FIR*FIR)+(DIR*DIR)+(Ep*Ep));
c=FWHM/(2*sqrt(2*log(2)));
lim=1;
if D>lim
    lim=D;
elseif F>lim
    lim=F;
end
x=-lim:0.001:lim;
y=gaussmf(x,[c 0]);
% uy=abs(y-0.5);
% [f1 ff1]=min(uy(1:1000*lim));
% [f2 ff2]=min(uy(lim*1001:end));
% ff2=ff2+1001*lim;
% f3(1:abs(ff2-ff1)+1)=0.5;



pMTF=abs(fft(y,100000));
for ii=1:500
     if pMTF(ii)<=0.1
         break;
     end
     MTF(ii)=pMTF(ii);
end
MTFF(i,:)=MTF/max(MTF);
Mx(i,:)=linspace(0,1/FWHM,length(MTF));



% plot(x(ff1:ff2),f3,'r');

krivkax(i)={x};
krivkay(i)={y};
aa(i)={num2str(FWHM)}
% lPSF(i)={['FWHM=' aa]}

end


lim=Mx(1,:);
figure
for j=1:krok

% plot(cell2mat(Mx(j)),cell2mat(MTFF(j)),'color',barvy(j))
plot(Mx(j,:),MTFF(j,:),'color',barvy(j))
hold on

xlim([0 lim(end-floor(length(lim)/8))])
tmp=MTFF(j,:)-0.1;
[idc tmp]=min(MTFF(j,:));
tmp=Mx(j,tmp)
tmp=num2str(tmp);
    lMTF(j)={['Mezní prostorová frekvence = ' tmp]};

    if j==1
    legend(cell2mat(lMTF(1)));
    elseif j==2
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)));
        elseif j==3
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)));
        elseif j==4
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)));
        elseif j==5
        legend(cell2mat(lMTF(1)),cell2mat(lMTF(2)),cell2mat(lMTF(3)),cell2mat(lMTF(4)),cell2mat(lMTF(5)));
    end

end
hold off
xlabel ('Prostorová frekvence [lp/mm]')
ylabel ('MTF')



function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
