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

% Last Modified by GUIDE v2.5 29-May-2009 10:47:37

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = gui_rozhrani_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 button press in open_show.
function open_show_Callback(hObject, eventdata, handles)
% hObject    handle to open_show (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
format_cislo = get(handles.popupformat,'value');

switch format_cislo
    case 1
    form = '*.txt'; 
    case 2
    form = '*.xls';
    case 3
    form = '*.dat';   
end;

[FileName,PathName] = uigetfile(form,'Vyber zdrojovy soubor(form)');
b = load (FileName);
num = length(b)
       
    fvz = 200;
celk = b(1:num,2);
N = length(celk);
t = 0:1/fvz:(N-1)/fvz;
f = 1/N:fvz/N:fvz;
    
axes(handles.kolac_graf);
    plot([0]);
     pie([sum(b(8:13)), sum(b(15:20)), sum(b(1:4)), sum(b(4:7))],{'Alfa','Beta','Delta','Theta'});
     

EEG_graph = b(1:num,2);
axes(handles.EEG_graph)
    prikaz = ['h = plot(t,EEG_graph);'];    
    eval(prikaz)
    xlabel('t[s]'); ylabel('A[uV]');
    
alfa = b(1:num,3);
axes(handles.alfa)
    prikaz = ['h = plot(alfa);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
beta = b(1:num,4);
axes(handles.beta)
    prikaz = ['h = plot(beta);'];
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
delta = b(1:num,5);
axes(handles.delta)
    prikaz = ['h = plot(delta);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
theta = b(1:num,6);
axes(handles.theta)
    prikaz = ['h = plot(theta);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
     

b = fir1(301,[49*2/fvz 51*2/fvz],'stop');   %odfiltrovani 50Hz
celk = filter(b,1,celk);
clear b;

for m = 151:1:N                               %zpetne posunuti signalu po filtraci
    celk(m-150) = celk(m);
end

dd = fft(celk);
dd(1,1) = 0;

 EEG_spect = (abs(dd));
 axes(handles.EEG_spect)
     prikaz = ['h = plot(f,EEG_spect);'];    
     eval(prikaz)
     xlabel('frekvence[Hz]'); ylabel('Sf[-]');

alfa = zeros(N,1);
alfa(8*200:13*200,1) = 1;
alfa(N-13*200:N-8*200,1) = 1;

alfa = dd.*alfa;
yy = ifft(alfa);
alfa2 = (real(yy(1:100,1)));
axes(handles.alfa2)
    prikaz = ['h = plot(alfa2);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');

beta = zeros(N,1);
beta(15*200:20*200,1) = 1;
beta(N-20*200:N-15*200,1) = 1;

beta = dd.*beta;
xx = ifft(beta);
beta2 = (real(xx(1:100,1)));
axes(handles.beta2)
    prikaz = ['h = plot(beta2);'];
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
    
delta = zeros(N,1);
delta(1*200:4*200,1) = 1;
delta(N-4*200:N-1*200,1) = 1;

delta = dd.*delta;
zz = ifft(delta);
delta2 = (real(zz(1:100,1)));
axes(handles.delta2)
    prikaz = ['h = plot(delta2);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
theta = zeros(N,1);
theta(4*200:7*200,1) = 1;
theta(N-7*200:N-4*200,1) = 1;

theta = dd.*theta;
aa = ifft(theta);
theta2 = (real(aa(1:100,1)));
axes(handles.theta2)
    prikaz = ['h = plot(theta2);'];    
    eval(prikaz)
    xlabel('n[-]'); ylabel('A[uV]');
    
    
    


% --- Executes on selection change in popupformat.
function popupformat_Callback(hObject, eventdata, handles)
% hObject    handle to popupformat (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 popupformat contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupformat


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


