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

% Last Modified by GUIDE v2.5 28-May-2014 09:48:54

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

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

% Update handles structure
guidata(hObject, handles);



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


% --- Outputs from this function are returned to the command line.
function varargout = signal_denoising_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 pop_wavelet.
function pop_wavelet_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet (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 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet


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



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


% --- Executes during object creation, after setting all properties.
function edit_ridkost_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ridkost (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.
function pop_baze_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze (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 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_baze

params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet,'Enable','off') ;
else
    set(handles.pop_wavelet,'Enable','on') ;
end


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


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


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

% Ziskani dat z prvku GUI
delka_signalu = str2double(get(handles.edit_delka_signalu,'String'));
ridkost = str2double(get(handles.edit_ridkost,'String'));
input_snr = str2double(get(handles.edit_snr,'String'));
hloubka_dekompozice = str2double(get(handles.edit_decom,'String'));

baze    = cellstr(get(handles.pop_baze,'String'));
baze_id = get(handles.pop_baze,'Value');
wavelet = cellstr(get(handles.pop_wavelet,'String'));
wavelet_id = get(handles.pop_wavelet,'Value');

% volani funkce pro vypocet
[signal_in, signal_noised, signal_out, koef_in, koef_out, psnr, psnr_sr] = ...
    signal_denoising_impl(delka_signalu, ridkost, baze{baze_id}, wavelet{wavelet_id}, input_snr,  hloubka_dekompozice);

% vypis do grafu
t = 0:1:delka_signalu-1;

axes(handles.axes1);
plot(t,signal_in,'b'), title('Puvodni signal')

axes(handles.axes2);
plot(t,signal_noised-signal_in,'b'), title('Sum')
hold on
plot(t,signal_noised-signal_out,'r'),
legend('pridany','odstraneny')
hold off

axes(handles.axes3);
plot(t,signal_noised,'k'), title('Zasumeny signal')
hold on
plot(t,signal_in,'b')
legend('zasumeny','original')
hold off

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

axes(handles.axes5);
stem(t,koef_in,'b'), title('Koeficienty')
hold on
stem(t,koef_out,'r')
legend('original', 'rekonstrukce')
hold off


% vypis vysledku

set(handles.text_psnr,'String', ['PSNR = ' num2str(psnr) 'dB']);
set(handles.text_psnr_sr,'String', ['PSNR_SR = ' num2str(psnr_sr) 'dB']);


% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



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


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