function varargout = gui_1(varargin)
% GUI_1 M-file for gui_1.fig
%      GUI_1, by itself, creates a new GUI_1 or raises the existing
%      singleton*.
%
%      H = GUI_1 returns the handle to a new GUI_1 or the handle to
%      the existing singleton*.
%
%      GUI_1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_1.M with the given input arguments.
%
%      GUI_1('Property','Value',...) creates a new GUI_1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_1_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 gui_1

% Last Modified by GUIDE v2.5 13-May-2011 18:41:43

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_1_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);

               %global ir;
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 gui_1 is made visible.
function gui_1_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 gui_1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = gui_1_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;

%--------------------------------------------------------------------------
% tlacitko Spustit
% nacte odezvu místnosti ulozenou jako zvuk1.wav
% 

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)


global ir;
global Fs;
global mls;
global row;
global col;
global energia;


set(handles.checkbox2,'Value',0);               
Sel_lb3 = get(handles.listbox3,'Value');        % nacteni vzorkovaci frekvence
                 for i = 1:length(Sel_lb3)      % potrebna pro oba typy signalu
                    switch Sel_lb3(i)
                        case 1
                            Fs = 1000; 
                        case 2
                            Fs = 8000;
                        case 3
                            Fs = 44100;
                        case 4
                            Fs = 48000;
                    end
                 end
            
        
        if Fs>= 100 & Fs <=50000
            if get(handles.radiobutton1,'Value') == 1   % vybran signal MLS
   
                   n = str2double(get(handles.edit1,'String'));  % delka MLS
                                          
                if n>=2 & n<=32
                    
                      n == 2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32;

                 % [ir,mls,row,col] = mls_gen(n);        % volani fce, kt. generuje MLS a vypocita impulsni odezvu 
                 % -----------------------------------------------------
                 vekt=wavread('zvuk1.wav');      % nacteni zmerene odezvy mistnosti
                vekt=(vekt(:,1));

                delka_signalu=length(vekt)*2;
                signal=zeros(delka_signalu,1);      
                signal(1:length(vekt))=vekt;        


                signal(length(vekt)+1:2*length(vekt))=vekt;


                % ------------------------ hledání začátku impulsní odezvy (bod ponto) (podle ISO 3382)

                maximo = find(abs(signal) == max(abs(signal)));
                energia = (signal/signal(maximo(1))).^2;


                ponto = maximo(1)-length(row); % puvodne jen maximo(1)


                aux = signal(ponto:length(signal)/2,1);



                 ir=fwht(aux);          % vypocet impulsni odezvy

                ir = ir(1:1000);
                 
                % -----------------------------------------------------
                
                 axes(handles.axes1);
                 plot(ir)
                 grid on 
                 assignin('base','ir',ir);
                 xlabel ('t [ms]'), ylabel('p [Pa]');
                 
                else helpdlg('Hodnota n musi byt mezi 2 a 32.');
                end
                 
%                 y=mls ; 
%                 wavwrite(y,Fs,32,'mls1_wav.wav')          %jen kontrola


            else get(handles.radiobutton2,'Value') == 1     % vybran signal ESS
                 global A;
                 global B;
                 global tempo;
                 
                 
                 f0 = str2double(get(handles.edit10,'String')); % okrajove kmitočty
                 f1 = str2double(get(handles.edit11,'String')); 
                 
                                 
                 if f0 >=0 & f0 <= Fs/2 & f1 >=0 & f1 <=Fs/2
                 
                     [c,B,A] = sweep_gen(Fs,tempo,f0,f1);      % volani fce, kt. generuje ESS


                     sweep_vekt=wavread('zvuk1.wav');           % načtení odezvy mistnosti
                     sweep_vekt=(sweep_vekt(:,1));
                     m = 2*length(c);

                     sweep_vekt = sweep_vekt(1:m/2);
                     c = c(1:m/2);
                     c = rot90(c);

                     ir = real(ifft(fft(sweep_vekt,m)./fft(c,m)));  % výpočet impulsní odezvy
                     ir = filter(B,A,ir);

                     axes(handles.axes1);
                     plot(ir)
                     grid on 
                     assignin('base','ir',ir);
                     xlabel ('t [ms]'), ylabel('p [Pa]');

                 else helpdlg('Mezní frekvence musejí být v rozmezí od 0 do Fs/2!');
                 end    
            end
        
        else
            helpdlg('Zadej N a Fs!');
        end
 set(handles.checkbox2,'Value',1);  
   

% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3


% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton4


% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton5


% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton6


% --- Executes on button press in radiobutton7.
function radiobutton7_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton7


% --- Executes on button press in radiobutton8.
function radiobutton8_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton8


% --- Executes on button press in radiobutton9.
function radiobutton9_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton9


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% --------------- volani jednotlivych funkci počítajících parametry
%-------------------tlačítko Spočítat parametry
global ir;
global n;
global Fs;
global energia;


if get(handles.checkbox2,'Value') == 1;
     n = str2double(get(handles.edit1,'String'));
    
   if get(handles.radiobutton3,'Value') == 1
        [EDT,x,E] = reverberb_EDT(ir,Fs); 
        set(handles.edit5, 'String',num2str(EDT));
        
        obrEDT
         
   else set(handles.edit5, 'String','-');
   end
   
   if get(handles.radiobutton4,'Value') == 1
       [T20] = reverberb_T20(ir,Fs);        % parametr x textu označený jako T10
                                            % zde kvůli shodě s dalsimi
                                            % zdrojovymi kody jako T20    
       if T20 == 100 
            helpdlg('Hodnoty nevhodne pro graficke zobrazeni.');
            set(handles.edit6, 'String','Mimo rozsah.');
       else    
       set(handles.edit6, 'String',num2str(T20));
       obr_T20
       end

   else set(handles.edit6, 'String','-');
   end
   if get(handles.radiobutton5,'Value') == 1
       [T30] = reverberb_T30(ir,Fs);        % parametr x textu označený jako T20
                                            % zde kvůli shodě s dalsimi
                                            % zdrojovymi kody jako T30              
      if T30 == 100 
            helpdlg('Hodnoty nevhodne pro graficke zobrazeni.');
            set(handles.edit7, 'String','Mimo rozsah.');
       else    
       set(handles.edit7, 'String',num2str(T30));
       obr_T30
       end
       
   else set(handles.edit7, 'String','-');
   end
   
   if get(handles.radiobutton6,'Value') == 1
       [T40] = reverberb_T40(ir,Fs);        % parametr x textu označený jako T30
                                            % zde kvůli shodě s dalsimi
                                            % zdrojovymi kody jako T40               
      if T40 == 100 
            helpdlg('Hodnoty nevhodne pro graficke zobrazeni.');
            set(handles.edit8, 'String','Mimo rozsah.');
       else    
       set(handles.edit8, 'String',num2str(T40));
       obr_T40
       end
       
   else set(handles.edit8, 'String','-');
   end
   
   if get(handles.radiobutton7,'Value') == 1
       [C50]=energ_C50(energia,Fs);         % parametr C50
       set(handles.edit2, 'String',num2str(C50));
             
   else set(handles.edit2, 'String','-');
   end
   
   if get(handles.radiobutton9,'Value') == 1
       [C80]=energ_C80(energia,Fs);         % parametr C80
       set(handles.edit3, 'String',num2str(C80)); 
              
   else set(handles.edit3, 'String','-');
   end
   
   if get(handles.radiobutton8,'Value') == 1
       [CT]=energ_CT(energia,Fs);           % parametr Center Time
       set(handles.edit4, 'String',num2str(CT));
              
   else set(handles.edit4, 'String','-');
   end;
else 
    helpdlg('Nebyla spustena simulace!'); 
end;

% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


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

% Hint: listbox 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 selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject    handle to listbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox2


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

% Hint: listbox 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 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


% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1



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

 % ---------------------------------------------------- zavřít všechna okna
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
%close all global;
%close ();
close all hidden;

% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox2



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



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 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

% --------------------------------------------------
% pokročilé vyhodnocení

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global a;
global b;
global c;
global d;

Sel_lb1 = get(handles.listbox1,'Value');
Sel_lb2 = get(handles.listbox2,'Value');
 a =str2double(get(handles.edit5,'String'));    %EDT
 b =str2double(get(handles.edit2,'String'));    %C50
 c =str2double(get(handles.edit3,'String'));    %C80
 d =str2double(get(handles.edit4,'String'));    %CT

if get(handles.radiobutton3,'Value') == 1 & get(handles.radiobutton7,'Value') == 1 & get(handles.radiobutton8,'Value') == 1 & get(handles.radiobutton9,'Value') == 1;
    
 for q = 1:length(Sel_lb2)
    switch Sel_lb2(q)
        case 1 %mluvene slovo
            for p = 1:length(Sel_lb1)
               switch Sel_lb1(p) %jednotlive objemy
                  case 1
                     vargout = vyhodnoceni_11(a, b, c, d);
                      helpdlg('Kontrola'); 
                  case 2
                     vargout = vyhodnoceni_12(a, b, c, d);
                  case 3
                     vargout = vyhodnoceni_13(a, b, c, d);
                  case 4
                     vargout = vyhodnoceni_14(a, b, c, d);
                  case 5
                     vargout = vyhodnoceni_15(a, b, c, d);
                  case 6
                    vargout = vyhodnoceni_16(a, b, c, d);
                 
               end
            end
        case 2  %komorni a solova
           for p = 1:length(Sel_lb1)
               switch Sel_lb1(p)    %jednotlive objemy
                  case 1
                     vargout = vyhodnoceni_21(a, b, c, d);
                  case 2
                     vargout = vyhodnoceni_22(a, b, c, d);
                  case 3
                     vargout = vyhodnoceni_23(a, b, c, d);
                  case 4
                     vargout = vyhodnoceni_24(a, b, c, d);
                  case 5
                     vargout = vyhodnoceni_25(a, b, c, d);
                  case 6
                     vargout = vyhodnoceni_26(a, b, c, d);
                   
               end
           end   
        case 3  %orchestralni
           for p = 1:length(Sel_lb1)
               switch Sel_lb1(p) %jednotlive objemy
                  case 1
                    vargout = vyhodnoceni_31(a, b, c, d);
                  case 2
                     vargout = vyhodnoceni_32(a, b, c, d);
                  case 3
                     vargout = vyhodnoceni_33(a, b, c, d);
                  case 4
                     vargout = vyhodnoceni_34(a, b, c, d);
                  case 5
                     vargout = vyhodnoceni_35(a, b, c, d);
                  case 6
                     vargout = vyhodnoceni_36(a, b, c, d);
                 
               end
           end   
        case 4  %opera
           for p = 1:length(Sel_lb1)
               switch Sel_lb1(p)    %jednotlive objemy
                  case 1
                     vargout = vyhodnoceni_41(a, b, c, d);
                  case 2
                     vargout = vyhodnoceni_42(a, b, c, d);
                  case 3
                     vargout = vyhodnoceni_43(a, b, c, d);
                  case 4
                     vargout = vyhodnoceni_44(a, b, c, d);
                  case 5
                     vargout = vyhodnoceni_45(a, b, c, d);
                  case 6
                     vargout = vyhodnoceni_46(a, b, c, d);
                  
               end       
           end   
                 
     end    
 end   
 
else helpdlg('Je potřeba spočítat EDT, C50, C80 i Center Time!'); 
end    
    
 
[b,c,g,lbs] = legend([lbs listbox1(Sel_lb1+1)]);



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


% ------------------------------------------- generace MLS
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global n;
global y;
global Fs;
global generovano;
global mls;
global row;
global col;

if get(handles.radiobutton1,'Value') == 1
% Fs = str2double(get(handles.edit9,'String')); 
 n = str2double(get(handles.edit1,'String'));
    if n>=2 & n<=32
        [mls,row,col] = generace(n);
        y=mls;
        %wavwrite(y,Fs,16,'mls_wav.wav')
        wavwrite(y,Fs,16,'generacni_signal.wav')
        generovano=1;
        helpdlg('Generacni signal bude ulozen jako "generacni_signal.wav". Tento signal pouzijte k vybuzeni odezvy mistnosti. Nahravku ulozte jako "zvuk1.wav".'); 
    else helpdlg('Hodnota n musi byt mezi 2 a 32.');
    end
  else helpdlg('Nebyla zvolena generace MLS.');  
  end

% --- Executes on selection change in listbox3.
function listbox3_Callback(hObject, eventdata, handles)
% hObject    handle to listbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox3

            



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

% Hint: listbox 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 selection change in listbox4.
function listbox4_Callback(hObject, eventdata, handles)
% hObject    handle to listbox4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox4


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

% Hint: listbox 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 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



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (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

% ---------------------------------------------- generace ESS
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Fs;
global f0;
global f1;
global tempo;

%global sweep_sig;
if get(handles.radiobutton2,'Value') == 1
Sel_lb4 = get(handles.listbox4,'Value');        % doba trvani impulsu
                 for i = 1:length(Sel_lb4)
                    switch Sel_lb4(i)
                        case 1
                            tempo = 0.341; 
                        case 2
                            tempo = 1.4;
                        case 3
                            tempo = 2.7;
                        case 4
                            tempo = 5.5;
                    end
                 end
                 
 Sel_lb3 = get(handles.listbox3,'Value');       % vzorkovaci kmitocet
                 for i = 1:length(Sel_lb3)
                    switch Sel_lb3(i)
                        case 1
                            Fs = 1000; 
                        case 2
                            Fs = 8000;
                        case 3
                            Fs = 44100;
                        case 4
                            Fs = 48000;
                    end
                 end 
 f0 = str2double(get(handles.edit10,'String'));
 f1 = str2double(get(handles.edit11,'String')); 
 
     if f0 >=0 & f0 <= Fs/2 & f1 >=0 & f1 <=Fs/2

         [c,B,A] = sweep_gen(Fs,tempo,f0,f1) ;
         wavwrite(c,Fs,16,'generacni_signal.wav');
         %wavwrite(c,Fs,16,'mls_wav.wav');
         helpdlg('Generacni signal bude ulozen jako "generacni_signal.wav". Tento signal pouzijte k vybuzeni odezvy mistnosti. Nahravku ulozte jako "zvuk1.wav".'); 
    else helpdlg('Mezní frekvence musejí být v rozmezí od 0 do Fs/2!');
     end
else helpdlg('Nebyla zvolena generace ESS.');      
end
 
