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

% Last Modified by GUIDE v2.5 28-Nov-2006 18:28:44

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

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

% Update handles structure
guidata(hObject, handles);

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

global y s fs n F;
global Y S;

[y,Y]=ordena2(y,Y,s);

tiempo=(1/fs)*[1:length(y(1,:))];
if n==3
    set(handles.grafica_y3,'Visible','on');
    axes(handles.grafica_y3);
    plot(tiempo,y(3,:));axis tight;
    set(handles.reproducir_y3,'Enable','on');
    set(handles.specgram_y3,'Enable','on');
end
axes(handles.grafica_y1);
plot(tiempo,y(1,:));axis tight;
axes(handles.grafica_y2);
plot(tiempo,y(2,:));axis tight;

set(handles.texto,'String',['Introduce una subbanda (entre 1 y ',int2str(length(F)),'):']);


% --- Outputs from this function are returned to the command line.
function varargout = resultados_subbandas_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 reproducir_y2.
function reproducir_y2_Callback(hObject, eventdata, handles)
% hObject    handle to reproducir_y2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global y fs;
wavplay(y(2,:),fs);

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

global y;
specgramdemo(y(2,:));

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

global y fs;
wavplay(y(3,:),fs);

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

global y;
specgramdemo(y(3,:));

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

global y fs;
wavplay(y(1,:),fs);

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

global y;
specgramdemo(y(1,:));

% --- Executes during object creation, after setting all properties.
function edit_subband_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_subband (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 edit_subband_Callback(hObject, eventdata, handles)
% hObject    handle to edit_subband (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 edit_subband as text
%        str2double(get(hObject,'String')) returns contents of edit_subband as a double

global subbanda;
subbanda=str2double(get(gcbo,'String'));


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


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

global k;
k=get(handles.popupmenu1,'Value');
k=k-1;


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

global subbanda k Y S T;
set(handles.text5,'Visible','on');
set(handles.text6,'Visible','on');
set(handles.text7,'Visible','on');
set(handles.text8,'Visible','on');
set(handles.graficaModulo,'Visible','on');
set(handles.graficaFase,'Visible','on');
axes(handles.graficaModulo);
hold off;
plot(T,abs(S(subbanda,:,k)),'r');axis tight;
hold on;
plot(T,abs(Y(subbanda,:,k)),'b');axis tight;
axes(handles.graficaFase);
hold off;
plot(T,phase(S(subbanda,:,k)),'r');axis tight;
hold on;
plot(T,phase(Y(subbanda,:,k)),'b');axis tight;

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


close(gcbf);