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

% Last Modified by GUIDE v2.5 27-May-2014 16:20:04

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = decomposition_1D_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 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 N;
global signal_in_c;
global signal_in_t;

delka_signalu = cellstr(get(handles.edit_delka_signalu,'String'));

ridkost_k1 = str2double(get(handles.edit_ridkost_k1,'String'));
ridkost_k2 = str2double(get(handles.edit_ridkost_k2,'String'));

baze_1    = cellstr(get(handles.pop_baze_1,'String'));
baze_1_id = get(handles.pop_baze_1,'Value');
baze_2    = cellstr(get(handles.pop_baze_2,'String'));
baze_2_id = get(handles.pop_baze_2,'Value');

wavelet_1 = cellstr(get(handles.pop_wavelet_1,'String'));
wavelet_1_id = get(handles.pop_wavelet_1,'Value');
wavelet_2 = cellstr(get(handles.pop_wavelet_2,'String'));
wavelet_2_id = get(handles.pop_wavelet_2,'Value');

hloubka_decom_1 = str2double(get(handles.edit_decom_1,'String'));%handles    structure with handles and user data (see GUIDATA)
hloubka_decom_2 = str2double(get(handles.edit_decom_2,'String'));%handles    structure with handles and user data (see GUIDATA)

% volani funkce pro vypocet
[signal_in, signal_tex, signal_car, signal_out, psnr, psnr_t, psnr_c, koef1, koef2, koef3, koef4] = ... 
     decomposition_1D_impl(delka_signalu, ridkost_k1, ridkost_k2, baze_1{baze_1_id}, baze_2{baze_2_id},wavelet_1{wavelet_1_id}, wavelet_2{wavelet_2_id}, hloubka_decom_1, hloubka_decom_2);

% vypis do grafu
t = 0:1:str2double(delka_signalu{1})-1;

axes(handles.axes1);
plot(t,signal_in_c,'k'), title('puvodni_c slozka')
 
 
 axes(handles.axes2);
plot(t,signal_in_t,'k'), title('puvodni_t slozka')
 
 
 axes(handles.axes3);
plot(t,signal_in,'k'), title('Puvodni signal = puvodni_c + puvodni_t')

 

 axes(handles.axes4);
plot(t,signal_in,'b'), title('Zpetne slozeny signal')
hold on
plot(t,signal_out,'r')
hold off
legend('original', 'rekonstrukce')

 axes(handles.axes5);
plot(t,signal_in_c,'b')
hold on
plot(t,signal_car,'r'), title('Druha komponenta')
hold off
legend('original', 'rekonstrukce')
kontrola = signal_car - signal_tex;

 axes(handles.axes6);
 plot(t,signal_in_t,'b'), title('Prvni komponenta')
hold on 
plot(t,signal_tex,'r')
hold off
legend('original', 'rekonstrukce')




 axes(handles.axes7);
 stem(t,koef2,'b'), title('Porovnani koeficientu druhe slozky: original vs. dekompozice ')
hold on
stem(t,koef4,'r')
hold off
legend('original', 'rekonstrukce')


 axes(handles.axes8);
stem(t,koef1,'b'), title('Porovnani koeficientu prvni slozky: original vs. dekompozice ')
hold on
stem(t,koef3,'r')
hold off
legend('original', 'rekonstrukce')



 
 
 set(handles.text_psnr,'String', ['PSNR = ' num2str(psnr) 'dB']);
 set(handles.text_psnr_t,'String', ['PSNR_T = ' num2str(psnr_t) 'dB']);
 set(handles.text_psnr_c,'String', ['PSNR_C = ' num2str(psnr_c) 'dB']);
 
 




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


% --- Executes during object creation, after setting all properties.
function pop_wavelet_1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_1 (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 selection change in pop_baze_1.
function pop_baze_1_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze_1 (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 pop_baze_1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_baze_1
params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet_1,'Enable','off') ;
     set(handles.edit_decom_1,'Enable','off') ;
    
else
    set(handles.pop_wavelet_1,'Enable','on') ;
    set(handles.edit_decom_1,'Enable','on') ;
end

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


% --- Executes during object creation, after setting all properties.
function edit_decom_1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_decom_1 (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 pop_baze_2.
function pop_baze_2_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze_2 (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 pop_baze_2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_baze_2
params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet_2,'Enable','off') ;
     set(handles.edit_decom_2,'Enable','off') ;
    
else
    set(handles.pop_wavelet_2,'Enable','on') ;
    set(handles.edit_decom_2,'Enable','on') ;
end



% --- Executes during object creation, after setting all properties.
function pop_baze_2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_baze_2 (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 selection change in pop_wavelet_2.
function pop_wavelet_2_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_2 (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 pop_wavelet_2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet_2


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


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


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


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


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