function GUI()
    %% Variables
    figSize = [650, 550];
    selectedCamera = 'rearCam';
    InDataFileName = [];
    InDataPathName = [];
    InVideoFileName = [];
    InVideoPathName = [];
    OutVideoFileName = 'myVideo';
    OutVideoPathName = pwd;
    CamSpinner = [];
    MCC = [];
    Checked = [];
    resultAngle = [];
    rangeBins = [];
    
    %% Main window
    screenSize = get(groot, 'ScreenSize');

    hFig = uifigure('Position', [(screenSize(3:4) - figSize)/2 figSize],...
                    'Name', 'FMCW Analysis','Resize',false);

    %% Structures
    hInputDataPanel = uipanel(hFig, 'Position', [10, 490, 305, 50],...
        'Title', 'Select input data file');
    hInputVideoPanel = uipanel(hFig, 'Position', [10, 435, 305, 50],...
        'Title','Select input video file');
    hOutputVideoPanel = uipanel(hFig, 'Position', [320, 490, 305, 50],...
        'Title','Select output video file');
    hInputParamsPanel = uipanel(hFig, 'Position', [320, 365, 305, 120],...
        'Title', 'Input parameters');

    hRadioButtonGroup = uibuttongroup(hFig,'Position',[20 370 300 40],...
        'BorderType','none');

    hAx = uiaxes(hFig, 'Position', [80, 5, 461, 357], 'XLim', [0 461],...
        'YLim', [0 357], 'XColor', 'none', 'YColor', 'none');

    %% Elements
    hInputDataEdit = uieditfield(hInputDataPanel, 'Position',...
        [2, 2, 250, 25],'FontSize', 15, 'HorizontalAlignment', 'center');
    hInputVideoEdit = uieditfield(hInputVideoPanel, 'Position',...
        [2, 2, 250, 25],'FontSize', 15, 'HorizontalAlignment', 'center');
    hOutputVideoEdit = uieditfield(hOutputVideoPanel, 'Position',...
        [2, 2, 250, 25],'FontSize', 15, 'Value', 'myVideo',...
        'HorizontalAlignment', 'center');
    hMCCEdit = uieditfield(hInputParamsPanel, 'numeric', 'Position',...
        [55, 70, 75, 25],'Value', 84712, 'ValueDisplayFormat', '%d',...
        'HorizontalAlignment', 'center','ToolTip', 'starting MCC in video');
    hNEdit = uieditfield(hInputParamsPanel, 'numeric', 'Position',...
        [200, 70, 75, 25],'Value', 1024, 'ValueDisplayFormat', '%d',...
        'HorizontalAlignment', 'center','ToolTip', 'number of samples');
    hKEdit = uieditfield(hInputParamsPanel, 'numeric', 'Position',...
        [200, 40, 75, 25],'Value', 128, 'ValueDisplayFormat', '%d',...
        'HorizontalAlignment', 'center','ToolTip', 'number of chirps');

    hInDataButt = uibutton(hInputDataPanel, 'Text', 'Select',...
        'Position', [252, 2, 50, 25]);
    hOutVidButt = uibutton(hOutputVideoPanel, 'Text', 'Select',...
        'Position', [252, 2, 50, 25]);
    hCalcButt = uibutton(hFig, 'Text', 'Calculate', 'Position',...
        [35, 400, 60, 25]);
    hShowButt = uibutton(hFig, 'Text', 'Show', 'Position',...
        [110, 400, 60, 25],'Enable','off');
    hInVidButt = uibutton(hInputVideoPanel, 'Text', 'Select',...
        'Position', [252, 2, 50, 25]);

    hCheck = uicheckbox(hFig,'Value', false,'Text', 'Export video',...
        'FontSize', 15,'Position', [190,397, 180, 30]);

    hCamSpinner = uispinner(hInputParamsPanel,'Position',[55, 40, 75, 25],...
        'Value',66,'Limits',[0 180],'ToolTip',...
        'angle of camera view [0°-180°]','ValueDisplayFormat','%d°');
    
    hMCCLabel = uilabel(hInputParamsPanel, 'Text', 'MCC',...
        'HorizontalAlignment', 'Center', 'Position', [5, 73, 50, 20],...
        'FontSize', 12);
    hNLabel = uilabel(hInputParamsPanel, 'Text', 'N',...
        'HorizontalAlignment', 'Center', 'Position', [160, 73, 50, 20],...
        'FontSize', 12);
    hKLabel = uilabel(hInputParamsPanel, 'Text', 'K',...
        'HorizontalAlignment', 'Center', 'Position', [160, 42, 50, 20],...
        'FontSize', 12);
    hCamSpinnerLabel = uilabel(hInputParamsPanel, 'Text', 'Camera',...
        'HorizontalAlignment', 'Center', 'Position', [5, 42, 50, 20],...
        'FontSize', 12);
    
    hRearCam = uiradiobutton(hRadioButtonGroup,'Position',[1 2 100 20],...
        'Text','rearCam');
    hFrontCam = uiradiobutton(hRadioButtonGroup,'Position',[76 2 100 20],...
        'Text','frontCam');
    hLeftCam = uiradiobutton(hRadioButtonGroup,'Position',[153 2 100 20],...
        'Text','leftCam');
    hRightCam = uiradiobutton(hRadioButtonGroup,'Position',[221 2 100 20],...
        'Text','rightCam');

    %% Callbacks
    hInDataButt.ButtonPushedFcn = @(src, event)pressInDataButt();
    hInVidButt.ButtonPushedFcn = @(src, event)pressInVidButt();
    hOutVidButt.ButtonPushedFcn = @(src, event)pressOutVid();
    hCalcButt.ButtonPushedFcn = @(src, event)pressCalcButt();
    hShowButt.ButtonPushedFcn = @(src, event)pressShowButt();
    hCheck.ValueChangedFcn = @(src, event)checkCheckbox();
    hCamSpinner.ValueChangedFcn = @(src, event)changeCamSpinner();
    hMCCEdit.ValueChangedFcn = @(src, event)changeButtColor();
    hNEdit.ValueChangedFcn = @(src, event)changeButtColor();
    hKEdit.ValueChangedFcn = @(src, event)changeButtColor();
    hRadioButtonGroup.SelectionChangedFcn = @(src, event)changeRadioButt(event);

    %% Functions
    function pressInDataButt()
        [fileName, pathName] = uigetfile('*.hdf5', 'Select the hdf5-file');
        if fileName
            set(hInputDataEdit, 'Value', fileName);
            InDataFileName = fileName;
            InDataPathName = pathName;
            set(hCalcButt,'BackgroundColor',[0.96 0.96 0.96]);
            set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
        else
            set(hInputDataEdit, 'Value', '');
            InDataFileName = 0;
            InDataPathName = 0;
        end
    end

    function pressInVidButt()
        [fileName, pathName] = uigetfile('*.mp4', 'Select the video file');
        if fileName
            set(hInputVideoEdit, 'Value', fileName);
            InVideoFileName = fileName;
            InVideoPathName = pathName;
            set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
        else
            set(hInputVideoEdit, 'Value', '');
            InVideoFileName = 0;
            InVideoPathName = 0;
            set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
        end
    end

    function pressOutVid()
        [fileName, pathName] = uiputfile('*.mp4', 'Select output file');
        if fileName
            OutVideoFileName = fileName;
            OutVideoPathName = pathName;
            set(hOutputVideoEdit, 'Value', fileName);
            set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
            
        else
            OutVideoFileName = 0;
            OutVideoPathName = 0;
            set(hOutputVideoEdit, 'Value', '');
            set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
        end
    end

    function pressCalcButt()
        set(hCalcButt,'BackgroundColor',[0.96 0.96 0.96]);
        if InDataPathName
            progress = uiprogressdlg(hFig,'Title','Please Wait', 'Message',...
                'Calculating DOA from input data');
            progress.Value = 0;

            fullHDF5 = fullfile(InDataPathName,InDataFileName);
            
            K = get(hKEdit,'Value');
            N = get(hNEdit,'Value');
            
            CamSpinner = hCamSpinner.Value;
           
            [resultAngle, MCC, rangeBins] = Calculation(progress,fullHDF5,...
                K, N,selectedCamera);
            close(progress)
            
            set(hShowButt,'Enable','on');
            set(hCalcButt,'BackgroundColor','g');
        else
            uialert(hFig,'Please specify input data file','Invalid File');
        end
    end

    function pressShowButt()
        set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
        set(hShowButt,'Enable','off');
        if InVideoPathName
            videoFileReader = VideoReader(fullfile(InVideoPathName,...
                InVideoFileName));
            
            myMCC = get(hMCCEdit,'Value');
            
            fullOutVideo = fullfile(OutVideoPathName,OutVideoFileName);

            Show(resultAngle,rangeBins,MCC,hAx,videoFileReader,...
                fullOutVideo,myMCC,CamSpinner,selectedCamera,Checked);

            set(hShowButt,'BackgroundColor','g');
            set(hCalcButt,'BackgroundColor','g');
        else
            uialert(hFig,'Please specify input video file','Invalid File');
        end
        set(hShowButt,'Enable','on');
    end

    function checkCheckbox()
        if hCheck.Value
            if OutVideoFileName
                Checked = true;
            else
                uialert(hFig,'Please specify output video filename',...
                    'Invalid File');
                hCheck.Value = 0;
            end
        else
            Checked = false;
        end
    end

    function changeCamSpinner()
        CamSpinner = hCamSpinner.Value;
        changeButtColor()
    end
    
    function changeRadioButt(event)
        changeButtColor()
        selectedCamera = event.NewValue.Text;
    end

    function changeButtColor()
        set(hCalcButt,'BackgroundColor',[0.96 0.96 0.96]);
        set(hShowButt,'BackgroundColor',[0.96 0.96 0.96]);
    end

end
