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

% Last Modified by GUIDE v2.5 20-Sep-2005 13:47:49

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Res_Espctral_OpeningFcn, ...
                   'gui_OutputFcn',  @Res_Espctral_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 Res_Espctral is made visible.
function Res_Espctral_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 Res_Espctral (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);



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


% --- Outputs from this function are returned to the command line.
function varargout = Res_Espctral_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 during object creation, after setting all properties.
function sPicoVLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sPicoVLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




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


% --- Executes during object creation, after setting all properties.
function SPicoLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SPicoLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function SPicoHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SPicoHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PmsVLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PmsVLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PmsLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PmsLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PmsHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PmsHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PpcVLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PpcVLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PpcLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PpcLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PpcHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PpcHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function rLFHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rLFHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PnuVLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PnuVLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PnuLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PnuLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function PnuHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to PnuHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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



% --- 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 cVLF cLF cHF pVLF pLF pHF cLFnu cHFnu cVLFpc cLFpc cHFpc rLFHF

set(handles.sPicoVLF,'String',num2str(pVLF));
set(handles.sPicoLF,'String',num2str(pLF));
set(handles.sPicoHF,'String',num2str(pHF));
set(handles.PmsVLF,'String',num2str(cVLF));
set(handles.PmsLF,'String',num2str(cLF));
set(handles.PmsHF,'String',num2str(cHF));
set(handles.PnuLF,'String',num2str(cLFnu));
set(handles.PnuHF,'String',num2str(cHFnu));
set(handles.PpcVLF,'String',num2str(cVLFpc*100));
set(handles.PpcLF,'String',num2str(cLFpc*100));
set(handles.PpcHF,'String',num2str(cHFpc*100));
set(handles.rLFHF,'String',num2str(rLFHF));

fileID = fopen('Result - HRV Metrics.txt','at');

fprintf(fileID,['pVLF: ' num2str(pVLF) '\r\n']);
fprintf(fileID,['pLF: ' num2str(pLF) '\r\n']);
fprintf(fileID,['pHF: ' num2str(pHF),'\r\n']);
fprintf(fileID,['cVLF: ' num2str(cVLF),'\r\n']);
fprintf(fileID,['cLF: ' num2str(cLF),'\r\n']);
fprintf(fileID,['cHF: ' num2str(cHF),'\r\n']);
fprintf(fileID,['cLFnu: ' num2str(cLFnu),'\r\n']);
fprintf(fileID,['cHFnu: ' num2str(cHFnu),'\r\n']);
fprintf(fileID,['Percentual - VLF: ' num2str(cVLFpc*100),'\r\n']);
fprintf(fileID,['Percentual - LF: ' num2str(cLFpc*100),'\r\n']);
fprintf(fileID,['Percentual - HF: ' num2str(cHFpc*100),'\r\n']);
fprintf(fileID,['Relação LF/HF: ' num2str(rLFHF),'\r\n']);

fclose(fileID);
% --- Executes during object creation, after setting all properties.
function sPicoLF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sPicoLF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


% --- Executes during object creation, after setting all properties.
function sPicoHF_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sPicoHF (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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


