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

% Last Modified by GUIDE v2.5 07-May-2012 16:08:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @simulace_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @simulace_gui_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 simulace_gui is made visible.
function simulace_gui_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 simulace_gui (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);
set(handles.PGZ,'Value',0);
set(handles.BM,'Value',0);
set(handles.Euclid,'Value',0);
global vybsimuluj;
global kolikkodu;
kolikkodu=1;
vybsimuluj=0;
set(handles.pro1,'Value',1);
set(handles.vyber_kod2,'Enable','off');
% set(handles.PGZ,    );
% UIWAIT makes simulace_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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


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

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


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

% Hint: popupmenu 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 simuluj.
function simuluj_Callback(hObject, eventdata, handles)
% hObject    handle to simuluj (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 k;
global m;
global t;
global pp;
global vstupnislovo;
global pocet_symbolu;
global odeslaneslovo;
global slovo;
global bch;
% global choice;
global vybsimuluj;
global kolikkodu;
    if ((get(handles.vyber_kod1,'Value')<7) & (get(handles.vyber_kod1,'Value')~=1)&(get(handles.Euclid,'Value') == 1))  
%     if  (get(handles.Euclid,'Value') == 1)
    msgbox ('Eukliduv algorimus neimplementován pro RS kody, simulace nebyla spuštěna','Warning','warn');
%     end
    else
clc;
 pocet_symbolu = str2num(get(handles.vspocet_symbolu,'String'));
    volba1= get(handles.vyber_kod1,'Value');
    [n, k , m ,pp , bch, popis]=vyberkod(volba1,1);
if (isempty(pocet_symbolu)|(pocet_symbolu<k))
    msgbox ('Počet vstupních symbolů musí být nejméně k','Help','help');
else
    if get(handles.vyber_kod1,'Value')==1
    msgbox ('Vyberte kód pro který chcete simulovat','Help','help');
    else
switch kolikkodu
case 1
    volba1= get(handles.vyber_kod1,'Value');
    [n, k , m ,pp , bch, popis]=vyberkod(volba1,kolikkodu);
% volba2= get(handles.vyber_kod2,'Value');
% [n, k , m ,pp , t, bch, popis]=vyberkod(volba2);


if ((get(handles.PGZ,'Value')=='Min')&(get(handles.PGZ,'Value')=='Min')&(get(handles.Euclid,'Value')=='Min'))
 msgbox ('Vyberte aspoń jednu metodu dekódování pro simulaci','Help','help');
  vybsimuluj=0;
else

ebn0=0;
ebN0max=get(handles.kanalEbN0,'Value');
ebN0min=get(handles.kanalEbN0min,'Value');
% SNR=[ebN0min:ebN0max];
opakovani = round(pocet_symbolu/k);
vystupkoder = gf(zeros(1,(opakovani*n)),m,pp);
vystupkanalu = gf(zeros(1,(opakovani*n)),m,pp);
prijate = gf(zeros(1,(opakovani*k)),m,pp);
prijate2 = gf(zeros(1,(opakovani*k)),m,pp);
prijate3 = gf(zeros(1,(opakovani*k)),m,pp);
pocetchyb=zeros(1,(opakovani));
% % % % % % % % % % % 


h = waitbar(0,'Please wait...','Name','Probíhá simulace...',...
            'CreateCancelBtn',...
            'setappdata(gcbf,''canceling'',1)');
setappdata(h,'canceling',0)
for j=ebN0min:ebN0max
if getappdata(h,'canceling')
   break
end
tic;
ebn0=j;
if bch==0 %  kodovani pro RS kody
% if vybsimuluj ~= 7
for i = 1:opakovani
vstupnislovo = round(rand(1,k)*((2^m)-1));
vstpom = gf(vstupnislovo,m,pp);           % převedení slova do prvků GF
[slovo, gpoly, parita, paritanul]= rsencpz(vstpom, n, k);
vystupkoder(((i-1)*(n))+1:(i*(n)))=slovo(1:(n));  % vlozi zakodovane slovo za slovo zakodovane v predchozim kroku
vstupkoderu(((i-1)*(k))+1:(i*(k)))=vstupnislovo;
end
% end
else    %  kodovani pro BCH kody
for i = 1:opakovani
vstupnislovo = round(rand(1,k));
vstpom = gf(vstupnislovo,m,pp);           % převedení slova do prvků GF
[slovo, gpoly, parita, paritanul] = bchenc2(vstpom,n,k);
vystupkoder(((i-1)*(n))+1:(i*(n)))=slovo(1:(n));  % vlozi zakodovane slovo za slovo zakodovane v predchozim kroku
vstupkoderu(((i-1)*(k))+1:(i*(k)))=vstupnislovo;
end
end
% disp('-------------- coding complete -------------')

%%KANAL
[vystupkanalu,pocetchyb(i)] = prenosovykanal(vystupkoder,ebn0,n,k,m,bch);

if getappdata(h,'canceling')
   break
end


% disp('-------------- transfering complete -------------')
h=waitbar((j-1+0.5) / ebN0max,h);

switch vybsimuluj 
    case 1                  %%%%%%%%%%%%%%%%%% PGZ
        if bch==0
        for i = 1:opakovani
    odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
    opraveno = pgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        end
        else
       for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        end
        end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x); 
        

        [~, ratio]=biterr(pomvskod,pomprij);

        BER(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BER
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
        
    case 5 %%%%%%%%%%%%%%%%%% BM
    if bch==0
    for i = 1:opakovani
    odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
    opraveno = bmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
    else
    for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
    end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 

        [~, ratio]=biterr(pomvskod,pomprij);

        BER(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BER
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
    case 6  %%%%%%%%%%%%%%%%%% PGZ + BM
        if bch==0
        for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = pgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
        end
        else
      for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
      end
        end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 
        pomprij2 = double(prijate2.x);  

        [~, ratioPGZ]=biterr(pomprij,pomvskod);
        [~, ratioBM]=biterr(pomvskod,pomprij2);
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        BERBM(j)=ratioBM 
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );

    case 7       %%%%%%%%%%%%%%%%%% Euklid
       if bch==1
    for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
            pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 

        [~, ratio]=biterr(pomvskod,pomprij);

        BER(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BER     
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
       end
    case 8  % PGZ + EU
     for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
     end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x);
        pomprij2 = double(prijate2.x); 
        [~, ratioEU]=biterr(pomvskod,pomprij2);
        [~, ratioPGZ]=biterr(pomvskod,pomprij);
        BEREU(j)=ratioEU 
   
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );        
    case 12   %BM + EU
             for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchbmdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
     end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x);
        pomprij2 = double(prijate2.x); 
        [~, ratioEU]=biterr(pomvskod,pomprij2);
        [~, ratioBM]=biterr(pomvskod,pomprij);
        BEREU(j)=ratioEU 
   
%         disp('-------------- Decoding PGZ complete -------------')
        BERBM(j)=ratioBM
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );  
        
    case 13   %PGZ + BM + EU
      for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
        opraveno3 = bcheuklideksim(n, k, m, pp, odeslaneslovo);
        prijate3(((i-1)*(k))+1:(i*(k)))=opraveno3;
      end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 
        pomprij2 = double(prijate2.x);
        pomprij3=double(prijate3.x);

        [~, ratioPGZ]=biterr(pomprij,pomvskod);
        [~, ratioBM]=biterr(pomvskod,pomprij2);
        [~, ratioEU]=biterr(pomvskod,pomprij3);
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        BERBM(j)=ratioBM 
        BEREU(j)=ratioEU 
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );

    otherwise
   
end 
t=toc;
if j<ebN0max
caspopis=vypocticas(j,ebN0max,t);
% close(h)
h=waitbar(j / ebN0max,h,caspopis);
else
h=waitbar(j / ebN0max,h,'Zobrazuji grafy');
end
% waitbar(casaktualni/cascelkem)
end         %konec ebno foru
delete(h)
% close(h) 
    volba1= get(handles.vyber_kod1,'Value');
    [~,~,~,~ , ~, popis2]=vyberkod(volba1,2);

switch vybsimuluj 
    case 1
    figure(1)
     
   semilogy(SNR,BER,'xb-')
   grid on;
   hold on;
   semilogy(SNR,BERnekod,'xk-')
   xlabel('E_b/N_0 (dB)');
   ylabel('BER');
   title(sprintf('%s dekódovaný PGZ algoritmem',popis));   
   legend('PGZ algoritmus','Nekódováno');
   hold off;
   hgsave(sprintf('%d_PGZ_%s',pocet_symbolu,popis2))
   
    case 5
    figure(2)
        semilogy(SNR,BER,'xb-')
        grid on;
        hold on;
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný BM algoritmem',popis));
        legend('BM algoritmus','Nekódováno');
        hold off;
        hgsave(sprintf('%d_BM_%s',pocet_symbolu,popis2))
        
    case 6
     figure(3) 
        semilogy(SNR,BERPGZ,'xb-')
        grid on;
        hold on;
        semilogy(SNR,BERBM,'or-') 
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný PGZ a BM algoritmem',popis)); 
        legend('PGZ algoritmus','BM algoritmus','Nekódováno');
        hold off;
        hgsave(sprintf('%d_PGZ_a_BM_%s',pocet_symbolu,popis2))
        
    case 7
   figure(4)
        semilogy(SNR,BER,'xr-')
        grid on;
        hold on;
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný Euklidovým algoritmem',popis));  
        legend('Euklidův algoritmus','Nekódováno');
        hold off;
        hgsave(sprintf('%d_Euklid_%s',pocet_symbolu,popis2))

    case 8
      figure(5)
        semilogy(SNR,BERPGZ,'xb-')
        grid on;
        hold on;
        semilogy(SNR,BEREU,'or-') 
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný PGZ a Euklidovým algoritmem',popis));  
        legend('PGZ algoritmus','Euklidův algoritmus','Nekódováno');
        hold off;
        hgsave(sprintf('%d_PGZ_a_Euklid_%s',pocet_symbolu,popis2))
        
    case 12
        figure(6)
        semilogy(SNR,BERBM,'xb-')
        grid on;
        hold on;
        semilogy(SNR,BEREU,'or-') 
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný BM a Euklidovým algoritmem',popis));  
        legend('BM algoritmus','Euklidův algoritmus','Nekódováno');
        hold off;  
        hgsave(sprintf('%d_BM_a_Euklid%s',pocet_symbolu,popis2))
        
    case 13
    figure(7) 
        semilogy(SNR,BERPGZ,'xb-')
        grid on;
        hold on;
        semilogy(SNR,BERBM,'or-') 
        semilogy(SNR,BEREU,'*g-')
        semilogy(SNR,BERnekod,'xk-')
        xlabel('E_b/N_0 (dB)');
        ylabel('BER');
        title(sprintf('%s dekódovaný PGZ, BM a Euklidovým algoritmem',popis)); 
        legend('PGZ algoritmus','BM algoritmus','Euklidův algoritmus','Nekódováno');
        hold off; 
        hgsave(sprintf('%d_PGZ_BM_a_Euklid%s',pocet_symbolu,popis2))

    otherwise    
end
end

case 2              %%%%% pro dva kody simulace
  if (((get(handles.vyber_kod1,'Value')<7) & (get(handles.vyber_kod1,'Value')~=1)&(get(handles.Euclid,'Value') == 1))|((get(handles.vyber_kod2,'Value')<7) & (get(handles.vyber_kod2,'Value')~=1)&(get(handles.Euclid,'Value') == 1)))  
%     if  (get(handles.Euclid,'Value') == 1)
    msgbox ('Eukliduv algorimus neimplementován pro RS kody simulace nebyla spuštěna','Error','error');
%     end
  else
       if ((get(handles.vyber_kod1,'Value')==1)|(get(handles.vyber_kod2,'Value')==1))
                 msgbox ('Vyberte kódy pro které chcete simulovat','Help','help');
       else
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
    prokody=zeros(1,5*kolikkodu);
    volba1= get(handles.vyber_kod1,'Value');
    [n, k , m ,pp , bch, popis]=vyberkod(volba1,kolikkodu);
    prokody(1:5)=[bch n k  m pp];
    volba2= get(handles.vyber_kod2,'Value');
    [n, k , m ,pp , bch, popis2]=vyberkod(volba2,kolikkodu);
    prokody(6:5*kolikkodu)=[bch, n, k , m ,pp];
    if ((pocet_symbolu< prokody(3))|(pocet_symbolu< prokody(8)))
    msgbox ('Počet vstupních symbolů musí být nejméně k','Help','help');
else

if ((get(handles.PGZ,'Value')=='Min')&(get(handles.PGZ,'Value')=='Min')&(get(handles.Euclid,'Value')=='Min'))
 msgbox ('Vyberte aspoń jednu metodu dekódování pro simulaci','Help','help');
  vybsimuluj=0;
else 
    ebN0max=get(handles.kanalEbN0,'Value');
ebN0min=get(handles.kanalEbN0min,'Value');
% SNR=[ebN0min:ebN0max];

switch vybsimuluj
    case 1
     pocet=1;           % pocet je pocet dekodovacich metod pro ktere se bude simulovat
    case 5
    pocet=1;
    case 6
    pocet=2;
    case 7
    pocet=1;  
    case 8 
    pocet=2;  
    case 12
    pocet=2;
    case 13
    pocet=3;

    otherwise    
end  
vysledkykodu=zeros(1,kolikkodu*pocet*(ebN0max-ebN0min+1));  % nejdelsi muze byt 36 hodnot pro 2 ruzne kody
 

for ind=0:(kolikkodu-1)
    bch=prokody(1+5*ind);
    n=prokody(2+5*ind);
    k=prokody(3+5*ind);
    m=prokody(4+5*ind);
    pp=prokody(5+5*ind);
ebn0=0;
opakovani = round(pocet_symbolu/k);

vystupkoder = gf(zeros(1,(opakovani*n)),m,pp);
vstupkoderu = zeros(1,(opakovani*k));
vystupkanalu = gf(zeros(1,(opakovani*n)),m,pp);

prijate = gf(zeros(1,(opakovani*k)),m,pp);
prijate2 = gf(zeros(1,(opakovani*k)),m,pp);
prijate3 = gf(zeros(1,(opakovani*k)),m,pp);
pocetchyb=zeros(1,(opakovani));

% % % % % % % % % % % 
prosim=sprintf('Probíhá %d/%d simulace...',ind+1,kolikkodu)

h = waitbar(0,'Please wait...','Name',prosim,...
            'CreateCancelBtn',...
            'setappdata(gcbf,''canceling'',1)');
setappdata(h,'canceling',0)
for j=ebN0min:ebN0max
if getappdata(h,'canceling')
   break
end
tic;
ebn0=j;
if bch==0
for i = 1:opakovani
vstupnislovo = round(rand(1,k)*((2^m)-1));
vstpom = gf(vstupnislovo,m,pp);           % převedení slova do prvků GF
[slovo, gpoly, parita, paritanul]= rsencpz(vstpom, n, k);
vystupkoder(((i-1)*(n))+1:(i*(n)))=slovo(1:(n));  % vlozi zakodovane slovo za slovo zakodovane v predchozim kroku
vstupkoderu(((i-1)*(k))+1:(i*(k)))=vstupnislovo;
end
else
for i = 1:opakovani
vstupnislovo = round(rand(1,k));
vstpom = gf(vstupnislovo,m,pp);           % převedení slova do prvků GF
[slovo, gpoly, parita, paritanul] = bchenc2(vstpom,n,k);
vystupkoder(((i-1)*(n))+1:(i*(n)))=slovo(1:(n));  % vlozi zakodovane slovo za slovo zakodovane v predchozim kroku
vstupkoderu(((i-1)*(k))+1:(i*(k)))=vstupnislovo;
end
end
disp('-------------- coding complete -------------')

%%KANAL

[vystupkanalu,pocetchyb(i)] = prenosovykanal(vystupkoder,ebn0,n,k,m,bch);
if getappdata(h,'canceling')
   break
end


disp('-------------- transfering complete -------------')
h=waitbar((j-1+0.5) / ebN0max,h);

switch vybsimuluj 
    case 1  %%%%%%%%%%%%%%%%%% PGZ
        if bch==0
        for i = 1:opakovani
    odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
    opraveno = pgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        end
        else
       for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        end
        end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x); 
        

        [~, ratio]=biterr(pomvskod,pomprij);

        BERPGZ(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BERPGZ
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
        
    case 5  %%%%%%%%%%%%%%%%%% BM
    if bch==0
    for i = 1:opakovani
    odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
    opraveno = bmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
    else
    for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
    end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 

        [~, ratio]=biterr(pomvskod,pomprij);

        BERBM(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BERBM
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
    case 6  %%%%%%%%%%%%%%%%%% PGZ + BM
        if bch==0
        for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = pgzdeksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
        end
        else
      for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
      end
        end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 
        pomprij2 = double(prijate2.x);  

        [~, ratioPGZ]=biterr(pomvskod,pomprij);
        [~, ratioBM]=biterr(pomvskod,pomprij2);
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        BERBM(j)=ratioBM 
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
        
    case 7
    for i = 1:opakovani
     odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
     opraveno = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
    end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 

        [~, ratio]=biterr(pomvskod,pomprij);

        BEREU(j)=ratio;
        SNR(j)=ebn0;
        ebn0aktu=j
        BEREU
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );
    case 8  % PGZ + EU
     for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
     end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x);
        pomprij2 = double(prijate2.x); 
        [~, ratioEU]=biterr(pomvskod,pomprij2);
        [~, ratioPGZ]=biterr(pomvskod,pomprij);
        BEREU(j)=ratioEU 
   
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );         
        
    case 12   %BM + EU
             for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchbmdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bcheuklideksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
     end
        pomvskod = vstupkoderu;
        pomprij = double(prijate.x);
        pomprij2 = double(prijate2.x); 
        [~, ratioEU]=biterr(pomvskod,pomprij2);
        [~, ratioBM]=biterr(pomvskod,pomprij);
        BEREU(j)=ratioEU 
   
%         disp('-------------- Decoding PGZ complete -------------')
        BERBM(j)=ratioBM
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );  
        
    case 13   %PGZ + BM + EU
      for i = 1:opakovani
        odeslaneslovo = vystupkanalu(((i-1)*n)+1:(i*n));
        opraveno = bchpgzdeksim(n, k, m, pp, odeslaneslovo);
        prijate(((i-1)*(k))+1:(i*(k)))=opraveno;
        opraveno2 = bchbmdeksim(n, k, m, pp, odeslaneslovo);  
        prijate2(((i-1)*(k))+1:(i*(k)))=opraveno2;
        opraveno3 = bcheuklideksim(n, k, m, pp, odeslaneslovo);
        prijate3(((i-1)*(k))+1:(i*(k)))=opraveno3;
      end
        pomprij = double(prijate.x);  
        pomvskod = vstupkoderu; 
        pomprij2 = double(prijate2.x); 
        pomprij3=double(prijate3.x);

        [~, ratioPGZ]=biterr(pomvskod,pomprij);
        [~, ratioBM]=biterr(pomvskod,pomprij2);
        [~, ratioEU]=biterr(pomvskod,pomprij3);
%         disp('-------------- Decoding PGZ complete -------------')
        BERPGZ(j)=ratioPGZ
        BERBM(j)=ratioBM 
        BEREU(j)=ratioEU 
        SNR(j)=ebn0;
        BERnekod(j) = berawgn(j, 'psk', 2, 'nondif' );

    otherwise
   
end 
t=toc;
if j<ebN0max
caspopis=vypocticas(j,ebN0max,t);
% close(h)
h=waitbar(j / ebN0max,h,caspopis);
else
h=waitbar(j / ebN0max,h,'Zobrazuji grafy');
end
% waitbar(casaktualni/cascelkem)
end         %konec ebno foru

%%%%%%%%%%%%% dodelat podminku pro prirazeni vysledku
switch vybsimuluj
    case 1          %%%%PGZ BERPGZ
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERPGZ]
    case 5          %%%%BM BERBM
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERBM]
    case 6          %%%%PGZ+BM BERPGZ BERBM
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERPGZ BERBM]
    case 7          %%%%Euklid BEREU
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BEREU]
    case 8          %%%%PGZ+Euklid
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERPGZ BEREU]
    case 12         %%%%BM+Euklid
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERBM BEREU]
    case 13         %%%%PGZ+BM+Euklid  BERPGZ BERBM BEREU
    vysledkykodu((1+ind*pocet*length(SNR)):(ind+1)*pocet*length(SNR)) = [BERPGZ BERBM BEREU]

    otherwise    
end 
delete(h)
end

% % % % % % %  vyuzit vybsimuluj k urceni ukladani vysledku
% delete(h)
                             %konec kolikkodu foru
% delete(h)
% close(h) 
     volba1= get(handles.vyber_kod1,'Value');
    [~,~,~,~ , ~, popis3]=vyberkod(volba1,2);
     volba2= get(handles.vyber_kod2,'Value');
    [~,~,~,~ , ~, popis4]=vyberkod(volba2,2);
switch vybsimuluj 
    case 1
    figure(1)
    
    for ind=0:(kolikkodu-1)
     BERPGZ =vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
   semilogy(SNR,BERPGZ,'xb-')
   hold on
   grid on;
   xlabel('E_b/N_0 (dB)');
   ylabel('BER');
     else
        semilogy(SNR,BERPGZ,'+g-') 
     end
    end
    semilogy(SNR,BERnekod,'xk-')
    
    legend(popis,popis2,'Nekódovano');
    hold off  
    title(sprintf('Pro algoritmus PGZ srovnání BER v závislosti na E_b/N_0 pro kódy'));
    hgsave(sprintf('%d_PGZ_%s_%s',pocet_symbolu,popis3,popis4))
    
    case 5
    figure(2)
    for ind=0:(kolikkodu-1)
     BERBM =vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
   semilogy(SNR,BERBM,'xb-')
   hold on
   grid on;
   xlabel('E_b/N_0 (dB)');
   ylabel('BER');
     else
        semilogy(SNR,BERBM,'+g-') 
     end
    end
    semilogy(SNR,BERnekod,'xk-')
    legend(popis,popis2,'Nekódovano');
    hold off   
    title(sprintf('Pro algoritmus BM srovnání BER v závislosti na E_b/N_0 pro kódy'));
    hgsave(sprintf('%d_BM_%s_%s',pocet_symbolu,popis3,popis4))
    
    case 6
     figure(3) 
     
     for ind=0:(kolikkodu-1)
     BERPGZ = vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
      BERBM = vysledkykodu((1+length(SNR)+(ind*pocet*length(SNR))):(pocet*length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
            semilogy(SNR,BERPGZ,'xb--')
            hold on
            grid on;
            xlabel('E_b/N_0 (dB)');
            ylabel('BER');
            semilogy(SNR,BERBM,'+r--')
     else
            semilogy(SNR,BERPGZ,'xb-')
            semilogy(SNR,BERBM,'+r-') 
     end
     end
    semilogy(SNR,BERnekod,'xk-')
    legend(sprintf('PGZ, %s',popis),sprintf('BM, %s',popis),sprintf('PGZ, %s',popis2),sprintf('BM, %s',popis2),'Nekódovano');
    hold off 
    title(sprintf('Pro algoritmus PGZ a BM srovnání BER v závislosti na E_b/N_0 pro kódy'));
    hgsave(sprintf('%d_PGZ_a_BM_%s_%s',pocet_symbolu,popis3,popis4))
    
    case 7
     figure(4)
    for ind=0:(kolikkodu-1)
     BEREU =vysledkykodu((1+ind*pocet*(ebN0max-ebN0min+1)):(ind+1)*pocet*(ebN0max-ebN0min+1))
     if ind==0
   semilogy(SNR,BEREU,'xb-')
   hold on
   grid on;
   xlabel('E_b/N_0 (dB)');
   ylabel('BER');
     else
        semilogy(SNR,BEREU,'+g-') 
     end
    end
    semilogy(SNR,BERnekod,'xk-')
    legend(popis,popis2,'Nekódovano');
    hold off 
        title(sprintf('Pro algoritmus Euklidem srovnání BER v závislosti na E_b/N_0 pro kódy'));
        hgsave(sprintf('%d_Euklid_%s_%s',pocet_symbolu,popis3,popis4))
        
    case 8
        figure(5)  
     for ind=0:(kolikkodu-1)
     BERPGZ = vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
      BEREU = vysledkykodu((1+length(SNR)+(ind*pocet*length(SNR))):(pocet*length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
            semilogy(SNR,BERPGZ,'xb--')
            hold on
            grid on;
            xlabel('E_b/N_0 (dB)');
            ylabel('BER');
            semilogy(SNR,BEREU,'+r--')
     else
            semilogy(SNR,BERPGZ,'xb-')
            semilogy(SNR,BEREU,'+r-') 
     end
     end
    semilogy(SNR,BERnekod,'xk-')
    legend(sprintf('PGZ, %s',popis),sprintf('EU, %s',popis),sprintf('PGZ, %s',popis2),sprintf('EU, %s',popis2),'Nekódovano');
    hold off 
    title(sprintf('Pro algoritmus PGZ a Euklidův srovnání BER v závislosti na E_b/N_0 pro kódy'));
    
    case 12
     figure(6)  
     for ind=0:(kolikkodu-1)
     BERBM = vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
      BEREU = vysledkykodu((1+length(SNR)+(ind*pocet*length(SNR))):(pocet*length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
            semilogy(SNR,BERBM,'xb--')
            hold on
            grid on;
            xlabel('E_b/N_0 (dB)');
            ylabel('BER');
            semilogy(SNR,BEREU,'+r--')
     else
            semilogy(SNR,BERBM,'xb-')
            semilogy(SNR,BEREU,'+r-') 
     end
     end
    semilogy(SNR,BERnekod,'xk-')
    legend(sprintf('BM, %s',popis),sprintf('EU, %s',popis),sprintf('BM, %s',popis2),sprintf('EU, %s',popis2),'Nekódovano');
    hold off 
    title(sprintf('Pro algoritmus BM a Euklidův srovnání BER v závislosti na E_b/N_0 pro kódy'));
    hgsave(sprintf('%d_BM_a_Euklid_%s_%s',pocet_symbolu,popis3,popis4))
        
    case 13
    figure(7) 
    
     for ind=0:(kolikkodu-1)
     BERPGZ = vysledkykodu((1+(ind*pocet*length(SNR))):(length(SNR)+(ind*pocet*length(SNR))))
     BERBM = vysledkykodu((1+length(SNR)+(ind*pocet*length(SNR))):((pocet-1)*length(SNR)+(ind*pocet*length(SNR))))
     BEREU = vysledkykodu(((1+2*length(SNR))+(ind*pocet*length(SNR))):(pocet*length(SNR)+(ind*pocet*length(SNR))))
     if ind==0
            semilogy(SNR,BERPGZ,'xb--')
            hold on
            grid on;
            xlabel('E_b/N_0 (dB)');
            ylabel('BER');
            semilogy(SNR,BERBM,'+r--')
            semilogy(SNR,BEREU,'+g--')
     else
            semilogy(SNR,BERPGZ,'xb-')
            semilogy(SNR,BERBM,'+r-')
            semilogy(SNR,BEREU,'+g-')
     end
     end
    semilogy(SNR,BERnekod,'xk-')
    legend(sprintf('PGZ, %s',popis),sprintf('BM, %s',popis),sprintf('Euklid, %s',popis),sprintf('PGZ, %s',popis2),sprintf('BM, %s',popis2),sprintf('Euklid, %s',popis2),'Nekódovano');
    hold off 
    title(sprintf('Pro algoritmus PGZ a BM a Euklid srovnání BER v závislosti na E_b/N_0 pro kódy'));
    hgsave(sprintf('%d_PGZ_BM_a_Euklid%s_%s',pocet_symbolu,popis3,popis4))

    otherwise    
end
end 
                           end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
       end
  end
    otherwise 
    end
    end
disp('-------------- simulation complete -------------')
end
    end
% --- Executes on selection change in kanalEbN0.
function kanalEbN0_Callback(hObject, eventdata, handles)
% hObject    handle to kanalEbN0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


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

% Hint: popupmenu 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 vspocet_symbolu_Callback(hObject, eventdata, handles)
% hObject    handle to vspocet_symbolu (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 vspocet_symbolu as text
%        str2double(get(hObject,'String')) returns contents of vspocet_symbolu as a double


% --- Executes during object creation, after setting all properties.
function vspocet_symbolu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vspocet_symbolu (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 selection change in kanalEbN0min.
function kanalEbN0min_Callback(hObject, eventdata, handles)
% hObject    handle to kanalEbN0min (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


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

% Hint: popupmenu 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 during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% --- Executes on button press in PGZ.
function PGZ_Callback(hObject, eventdata, handles)
% hObject    handle to PGZ (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global vybsimuluj;
if (get(hObject,'Value') == get(hObject,'Max'))
   vybsimuluj=vybsimuluj+1;
else
    if ((get(hObject,'Value') == get(hObject,'Min'))& (vybsimuluj>=1))
    vybsimuluj=vybsimuluj-1;
    end
end
% Hint: get(hObject,'Value') returns toggle state of PGZ


% --- Executes on button press in BM.
function BM_Callback(hObject, eventdata, handles)
% hObject    handle to BM (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global vybsimuluj;
if (get(hObject,'Value') == get(hObject,'Max'))
   vybsimuluj=vybsimuluj+5;
   else
    if ((get(hObject,'Value') == get(hObject,'Min'))& (vybsimuluj>=5))
    vybsimuluj=vybsimuluj-5;
    end
end
% Hint: get(hObject,'Value') returns toggle state of BM


% --- Executes on button press in Euclid.
function Euclid_Callback(hObject, eventdata, handles)
% hObject    handle to Euclid (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global vybsimuluj;
if (get(hObject,'Value') == get(hObject,'Max'))
   vybsimuluj=vybsimuluj+7;
      else
    if ((get(hObject,'Value') == get(hObject,'Min'))& (vybsimuluj>=7))
    vybsimuluj=vybsimuluj-7;
    end
end
%     end
% Hint: get(hObject,'Value') returns toggle state of Euclid

% --- Executes on button press in pro1.
function pro1_Callback(hObject, eventdata, handles)
% hObject    handle to pro1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kolikkodu;
set(handles.pro2,'Value',0);
set(handles.pro1,'Value',1);
kolikkodu=1;
set(handles.vyber_kod2,'Enable','off');
% Hint: get(hObject,'Value') returns toggle state of pro1


% --- Executes on button press in pro2.
function pro2_Callback(hObject, eventdata, handles)
% hObject    handle to pro2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kolikkodu;
set(handles.pro1,'Value',0);
set(handles.pro2,'Value',1);
kolikkodu=2;
set(handles.vyber_kod2,'Enable','on');
% Hint: get(hObject,'Value') returns toggle state of pro2


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

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


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

% Hint: popupmenu 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 when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
cd ..
main_gui
% cd simulace
delete(hObject);


% --- Executes on button press in help_dekod.
function help_dekod_Callback(hObject, eventdata, handles)
% hObject    handle to help_dekod (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Výběr dekódovacích metod pro simulace, pro RS kódy nebyla implementována Euklidova metoda','Help','help');

% --- Executes on button press in help_kanal.
function help_kanal_Callback(hObject, eventdata, handles)
% hObject    handle to help_kanal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Zadejte rozmezí hodnot Eb/N0 pro které bude simulace provedena','Help','help');

% --- Executes on button press in help_vstup_symboly.
function help_vstup_symboly_Callback(hObject, eventdata, handles)
% hObject    handle to help_vstup_symboly (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Zadejte počet vstupních symbolů pro který bude prováděna simulace, pro RS kódy je symbol integer, pro BCH kódy je symbol bit. Počet musí být nejméně k symbolů','Help','help');

% --- Executes on button press in help_volba_kolikkodu.
function help_volba_kolikkodu_Callback(hObject, eventdata, handles)
% hObject    handle to help_volba_kolikkodu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Vyběr pro kolik kodů se bude simulovat','Help','help');
