classdef Preferences < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        PreferencesUIFigure           matlab.ui.Figure
        Tree                          matlab.ui.container.Tree
        PreprocessingNode             matlab.ui.container.TreeNode
        WelchperiodogramNode          matlab.ui.container.TreeNode
        FilterNode                    matlab.ui.container.TreeNode
        RpeakdetectionNode            matlab.ui.container.TreeNode
        OKButton                      matlab.ui.control.Button
        CancelButton                  matlab.ui.control.Button
        TabGroup                      matlab.ui.container.TabGroup
        TabEmpty                      matlab.ui.container.Tab
        TabFilter                     matlab.ui.container.Tab
        HighPassPanel                 matlab.ui.container.Panel
        LowPassPanel                  matlab.ui.container.Panel
        OrderEditField_2Label_2       matlab.ui.control.Label
        LowPassOrderEditField         matlab.ui.control.NumericEditField
        OrderEditFieldLabel           matlab.ui.control.Label
        HighPassOrderEditField        matlab.ui.control.NumericEditField
        TabPeakDetection              matlab.ui.container.Tab
        PeakDetectionPanel            matlab.ui.container.Panel
        EnvelopeSizeLabel             matlab.ui.control.Label
        AverageHRLabel                matlab.ui.control.Label
        PostprocessingLabel           matlab.ui.control.Label
        EctopicremovalLabel           matlab.ui.control.Label
        PostProcessingButtonGroup     matlab.ui.container.ButtonGroup
        YesButton                     matlab.ui.control.RadioButton
        NoButton                      matlab.ui.control.RadioButton
        EctopicRemovalButtonGroup     matlab.ui.container.ButtonGroup
        YesButton_2                   matlab.ui.control.RadioButton
        NoButton_2                    matlab.ui.control.RadioButton
        EnvelopeSizeEditField_2Label  matlab.ui.control.Label
        EnvelopeSizeEditField         matlab.ui.control.NumericEditField
        AverageHREditFieldLabel       matlab.ui.control.Label
        AverageHREditField            matlab.ui.control.NumericEditField
        TabWelch                      matlab.ui.container.Tab
        WelchPanel                    matlab.ui.container.Panel
        OverlapLabel                  matlab.ui.control.Label
        OverlapEditFieldLabel         matlab.ui.control.Label
        OverlapEditField              matlab.ui.control.NumericEditField
        WindowWidthEditFieldLabel     matlab.ui.control.Label
        WindowWidthEditField          matlab.ui.control.NumericEditField
        WindowWidthButtonGroup        matlab.ui.container.ButtonGroup
        WindowWidthDefaultButton      matlab.ui.control.RadioButton
        WindowWidthButton             matlab.ui.control.RadioButton
        WindowWidthLabel              matlab.ui.control.Label
        OverlapButtonGroup            matlab.ui.container.ButtonGroup
        OverlapDefaultButton          matlab.ui.control.RadioButton
        OverlapButton                 matlab.ui.control.RadioButton
        NfftButtonGroup               matlab.ui.container.ButtonGroup
        NfftDefaultButton             matlab.ui.control.RadioButton
        NfftButton                    matlab.ui.control.RadioButton
        NfftLabel                     matlab.ui.control.Label
        NfftEditFieldLabel            matlab.ui.control.Label
        NfftEditField                 matlab.ui.control.NumericEditField
        RDecoPreferencesLabel         matlab.ui.control.Label
        DefaultButton                 matlab.ui.control.Button
    end

    properties (Access = public)
        Parameters % Description
    end
    

    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app, parameters)

            % Set up the Welch tab
            if isempty(parameters.Welch{1})
                % Disable the settings
                app.WindowWidthEditField.Enable = 'off';
                app.WindowWidthEditField.Editable = 'off';
                app.WindowWidthLabel.Enable = 'off';
                
                % Select the default button
                app.WindowWidthDefaultButton.Value = 1;
            else
                % Enable the settings
                app.WindowWidthEditField.Enable = 'on';
                app.WindowWidthEditField.Editable = 'on';
                app.WindowWidthLabel.Enable = 'on';
                
                % Select the other button
                app.WindowWidthButton.Value = 1;
                
                % Set the window width
                app.WindowWidthEditField.Value = parameters.Welch{1};
            end
            
            if isempty(parameters.Welch{2})
                % Disable the settings
                app.OverlapEditField.Enable = 'off';
                app.OverlapEditField.Editable = 'off';
                app.OverlapLabel.Enable = 'off';
                
                % Select the default button
                app.OverlapDefaultButton.Value = 1;
            else
                % Enable the settings
                app.OverlapEditField.Enable = 'on';
                app.OverlapEditField.Editable = 'on';
                app.OverlapLabel.Enable = 'on';
                
                % Select the other button
                app.OverlapButton.Value = 1;
                
                % Set the overlap
                app.OverlapEditField.Value = parameters.Welch{2};
            end
            
            if isempty(parameters.Welch{3})
                % Disable the settings
                app.NfftEditField.Enable = 'off';
                app.NfftEditField.Editable = 'off';
                app.NfftLabel.Enable = 'off';
                
                % Select the default button
                app.NfftDefaultButton.Value = 1;
            else
                % Enable the settings
                app.NfftEditField.Enable = 'on';
                app.NfftEditField.Editable = 'on';
                app.NfftLabel.Enable = 'on';
                
                % Select the other button
                app.NfftButton.Value = 1;
                
                % Set the nfft
                app.NfftEditField.Value = parameters.Welch{3};
            end
            
            % Set up the Filter tab
            app.HighPassOrderEditField.Value = parameters.Filter{1};
            app.LowPassOrderEditField.Value = parameters.Filter{2};
            
            % Set up the R-peak detection tab
            app.EnvelopeSizeEditField.Value = parameters.Rpeak{1};
            app.AverageHREditField.Value = parameters.Rpeak{2};
            app.YesButton.Value = parameters.Rpeak{3};
            app.NoButton.Value = ~parameters.Rpeak{3};
            app.YesButton_2.Value = parameters.Rpeak{4};
            app.NoButton_2.Value = ~parameters.Rpeak{4};
            
            % Store the parameters
            app.Parameters = parameters;
            
        end

        % Selection changed function: Tree
        function TreeSelectionChanged(app, event)
            % Get the selected nodes
            selectedNodes = app.Tree.SelectedNodes;
            
            switch selectedNodes.Text
                case 'Pre-processing'
                    app.TabGroup.SelectedTab = app.TabEmpty;
                    
                    % Disable the default button
                    app.DefaultButton.Enable = 'off';
                case 'Welch periodogram'
                    app.TabGroup.SelectedTab = app.TabWelch;
                    
                    % Enable the default button
                    app.DefaultButton.Enable = 'on';
                case 'Filter'
                    app.TabGroup.SelectedTab = app.TabFilter;
                    
                    % Enable the default button
                    app.DefaultButton.Enable = 'on';
                case 'R-peak detection'
                    app.TabGroup.SelectedTab = app.TabPeakDetection;
                    
                    % Enable the default button
                    app.DefaultButton.Enable = 'on';
            end
        end

        % Button pushed function: OKButton
        function OKButtonPushed(app, event)
            % Store the Welch parameters
            if app.WindowWidthDefaultButton.Value == 0
                app.Parameters.Welch{1} = app.WindowWidthEditField.Value;
            else
                app.Parameters.Welch{1} = [];
            end
            if app.OverlapDefaultButton.Value == 0
                app.Parameters.Welch{2} = app.OverlapEditField.Value;
            else
                app.Parameters.Welch{2} = [];
            end
            if app.NfftDefaultButton.Value == 0
                app.Parameters.Welch{3} = app.NfftEditField.Value;
            else
                app.Parameters.Welch{3} = [];
            end
            
            % Store the Filter parameters
            app.Parameters.Filter{1} = app.HighPassOrderEditField.Value;
            app.Parameters.Filter{2} = app.LowPassOrderEditField.Value;
            
            % Store the R-peak parameters
            app.Parameters.Rpeak{1} = app.EnvelopeSizeEditField.Value;
            app.Parameters.Rpeak{2} = app.AverageHREditField.Value;
            app.Parameters.Rpeak{3} = app.YesButton.Value;
            app.Parameters.Rpeak{4} = app.YesButton_2.Value;
            
            % Resume GUI
            uiresume(app.PreferencesUIFigure)
        end

        % Button pushed function: CancelButton
        function CancelButtonPushed(app, event)
            % Delete UIFigure when app is deleted
            delete(app.PreferencesUIFigure)
        end

        % Selection changed function: WindowWidthButtonGroup
        function WindowWidthButtonGroupSelectionChanged(app, event)
    
            switch app.WindowWidthDefaultButton.Value
                case 1
                    app.WindowWidthEditField.Enable = 'off';
                    app.WindowWidthEditField.Editable = 'off';
                    app.WindowWidthLabel.Enable = 'off';
                otherwise 
                    app.WindowWidthEditField.Enable = 'on';
                    app.WindowWidthEditField.Editable = 'on';
                    app.WindowWidthLabel.Enable = 'on';
            end
        end

        % Selection changed function: OverlapButtonGroup
        function OverlapButtonGroupSelectionChanged(app, event)
       
            switch app.OverlapDefaultButton.Value
                case 1
                    app.OverlapEditField.Enable = 'off';
                    app.OverlapEditField.Editable = 'off';
                    app.OverlapLabel.Enable = 'off';
                otherwise 
                    app.OverlapEditField.Enable = 'on';
                    app.OverlapEditField.Editable = 'on';
                    app.OverlapLabel.Enable = 'on';
            end
        end

        % Selection changed function: NfftButtonGroup
        function NfftButtonGroupSelectionChanged(app, event)

            switch app.NfftDefaultButton.Value
                case 1
                    app.NfftEditField.Enable = 'off';
                    app.NfftEditField.Editable = 'off';
                    app.NfftLabel.Enable = 'off';
                otherwise 
                    app.NfftEditField.Enable = 'on';
                    app.NfftEditField.Editable = 'on';
                    app.NfftLabel.Enable = 'on';
            end
        end

        % Button pushed function: DefaultButton
        function DefaultButtonPushed(app, event)
            % Get the selected nodes
            selectedNodes = app.Tree.SelectedNodes;
            
            switch selectedNodes.Text
                case 'Pre-processing'
                    
                case 'Welch periodogram'
                    % Disable the settings
                    app.WindowWidthEditField.Enable = 'off';
                    app.WindowWidthEditField.Editable = 'off';
                    app.WindowWidthLabel.Enable = 'off';
                    app.OverlapEditField.Enable = 'off';
                    app.OverlapEditField.Editable = 'off';
                    app.OverlapLabel.Enable = 'off';
                    app.NfftEditField.Enable = 'off';
                    app.NfftEditField.Editable = 'off';
                    app.NfftLabel.Enable = 'off';
                    
                    % Select the default buttons
                    app.WindowWidthDefaultButton.Value = 1;
                    app.OverlapDefaultButton.Value = 1;
                    app.NfftDefaultButton.Value = 1;
                case 'Filter'
                    app.HighPassOrderEditField.Value = 2;
                    app.LowPassOrderEditField.Value = 4;
                case 'R-peak detection'
                    app.EnvelopeSizeEditField.Value = 300;
                    app.AverageHREditField.Value = 100;
                    app.YesButton.Value = 1;
                    app.NoButton.Value = 0;
                    app.YesButton_2.Value = 0;
                    app.NoButton_2.Value = 1;
            end
        end
    end

    % App initialization and construction
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create PreferencesUIFigure
            app.PreferencesUIFigure = uifigure;
            app.PreferencesUIFigure.Position = [100 100 483 279];
            app.PreferencesUIFigure.Name = 'Preferences';
            app.PreferencesUIFigure.Resize = 'off';

            % Create Tree
            app.Tree = uitree(app.PreferencesUIFigure);
            app.Tree.SelectionChangedFcn = createCallbackFcn(app, @TreeSelectionChanged, true);
            app.Tree.Position = [5 39 158 233];

            % Create PreprocessingNode
            app.PreprocessingNode = uitreenode(app.Tree);
            app.PreprocessingNode.Text = 'Pre-processing';

            % Create WelchperiodogramNode
            app.WelchperiodogramNode = uitreenode(app.PreprocessingNode);
            app.WelchperiodogramNode.Text = 'Welch periodogram';

            % Create FilterNode
            app.FilterNode = uitreenode(app.PreprocessingNode);
            app.FilterNode.Text = 'Filter';

            % Create RpeakdetectionNode
            app.RpeakdetectionNode = uitreenode(app.Tree);
            app.RpeakdetectionNode.Text = 'R-peak detection';

            % Create OKButton
            app.OKButton = uibutton(app.PreferencesUIFigure, 'push');
            app.OKButton.ButtonPushedFcn = createCallbackFcn(app, @OKButtonPushed, true);
            app.OKButton.Position = [168 10 100 22];
            app.OKButton.Text = 'OK';

            % Create CancelButton
            app.CancelButton = uibutton(app.PreferencesUIFigure, 'push');
            app.CancelButton.ButtonPushedFcn = createCallbackFcn(app, @CancelButtonPushed, true);
            app.CancelButton.Position = [274 10 100 22];
            app.CancelButton.Text = 'Cancel';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.PreferencesUIFigure);
            app.TabGroup.Position = [167 39 312 233];

            % Create TabEmpty
            app.TabEmpty = uitab(app.TabGroup);
            app.TabEmpty.Title = 'Tab_empty';

            % Create TabFilter
            app.TabFilter = uitab(app.TabGroup);
            app.TabFilter.Title = 'Tab_Filter';

            % Create HighPassPanel
            app.HighPassPanel = uipanel(app.TabFilter);
            app.HighPassPanel.Title = 'High Pass';
            app.HighPassPanel.Position = [2 149 309 55];

            % Create LowPassPanel
            app.LowPassPanel = uipanel(app.TabFilter);
            app.LowPassPanel.Title = 'Low Pass';
            app.LowPassPanel.Position = [2 91 309 55];

            % Create OrderEditField_2Label_2
            app.OrderEditField_2Label_2 = uilabel(app.LowPassPanel);
            app.OrderEditField_2Label_2.Position = [6 7 36 22];
            app.OrderEditField_2Label_2.Text = 'Order';

            % Create LowPassOrderEditField
            app.LowPassOrderEditField = uieditfield(app.LowPassPanel, 'numeric');
            app.LowPassOrderEditField.Limits = [1 10];
            app.LowPassOrderEditField.Position = [102 7 41 22];
            app.LowPassOrderEditField.Value = 1;

            % Create OrderEditFieldLabel
            app.OrderEditFieldLabel = uilabel(app.TabFilter);
            app.OrderEditFieldLabel.Position = [8 157 36 22];
            app.OrderEditFieldLabel.Text = 'Order';

            % Create HighPassOrderEditField
            app.HighPassOrderEditField = uieditfield(app.TabFilter, 'numeric');
            app.HighPassOrderEditField.Limits = [1 10];
            app.HighPassOrderEditField.Position = [104 157 41 22];
            app.HighPassOrderEditField.Value = 1;

            % Create TabPeakDetection
            app.TabPeakDetection = uitab(app.TabGroup);
            app.TabPeakDetection.Title = 'Tab_peak_detection';

            % Create PeakDetectionPanel
            app.PeakDetectionPanel = uipanel(app.TabPeakDetection);
            app.PeakDetectionPanel.Position = [2 88 309 116];

            % Create EnvelopeSizeLabel
            app.EnvelopeSizeLabel = uilabel(app.PeakDetectionPanel);
            app.EnvelopeSizeLabel.Position = [148 84 25 22];
            app.EnvelopeSizeLabel.Text = 'ms';

            % Create AverageHRLabel
            app.AverageHRLabel = uilabel(app.PeakDetectionPanel);
            app.AverageHRLabel.Position = [148 55 29 22];
            app.AverageHRLabel.Text = 'bpm';

            % Create PostprocessingLabel
            app.PostprocessingLabel = uilabel(app.PeakDetectionPanel);
            app.PostprocessingLabel.Position = [8 28 91 22];
            app.PostprocessingLabel.Text = 'Post processing';

            % Create EctopicremovalLabel
            app.EctopicremovalLabel = uilabel(app.PeakDetectionPanel);
            app.EctopicremovalLabel.Position = [8 2 91 22];
            app.EctopicremovalLabel.Text = 'Ectopic removal';

            % Create PostProcessingButtonGroup
            app.PostProcessingButtonGroup = uibuttongroup(app.PeakDetectionPanel);
            app.PostProcessingButtonGroup.Position = [104 28 100 20];

            % Create YesButton
            app.YesButton = uiradiobutton(app.PostProcessingButtonGroup);
            app.YesButton.Text = 'Yes';
            app.YesButton.Position = [3 3 58 15];

            % Create NoButton
            app.NoButton = uiradiobutton(app.PostProcessingButtonGroup);
            app.NoButton.Text = 'No';
            app.NoButton.Position = [58 3 40 15];
            app.NoButton.Value = true;

            % Create EctopicRemovalButtonGroup
            app.EctopicRemovalButtonGroup = uibuttongroup(app.PeakDetectionPanel);
            app.EctopicRemovalButtonGroup.Position = [104 2 100 20];

            % Create YesButton_2
            app.YesButton_2 = uiradiobutton(app.EctopicRemovalButtonGroup);
            app.YesButton_2.Text = 'Yes';
            app.YesButton_2.Position = [3 3 58 15];

            % Create NoButton_2
            app.NoButton_2 = uiradiobutton(app.EctopicRemovalButtonGroup);
            app.NoButton_2.Text = 'No';
            app.NoButton_2.Position = [58 3 40 15];
            app.NoButton_2.Value = true;

            % Create EnvelopeSizeEditField_2Label
            app.EnvelopeSizeEditField_2Label = uilabel(app.PeakDetectionPanel);
            app.EnvelopeSizeEditField_2Label.Position = [8 84 82 22];
            app.EnvelopeSizeEditField_2Label.Text = 'Envelope Size';

            % Create EnvelopeSizeEditField
            app.EnvelopeSizeEditField = uieditfield(app.PeakDetectionPanel, 'numeric');
            app.EnvelopeSizeEditField.Limits = [1 600];
            app.EnvelopeSizeEditField.Position = [104 84 41 22];
            app.EnvelopeSizeEditField.Value = 1;

            % Create AverageHREditFieldLabel
            app.AverageHREditFieldLabel = uilabel(app.PeakDetectionPanel);
            app.AverageHREditFieldLabel.Position = [8 55 71 22];
            app.AverageHREditFieldLabel.Text = 'Average HR';

            % Create AverageHREditField
            app.AverageHREditField = uieditfield(app.PeakDetectionPanel, 'numeric');
            app.AverageHREditField.Limits = [30 200];
            app.AverageHREditField.Position = [104 55 41 22];
            app.AverageHREditField.Value = 30;

            % Create TabWelch
            app.TabWelch = uitab(app.TabGroup);
            app.TabWelch.Title = 'Tab_Welch';

            % Create WelchPanel
            app.WelchPanel = uipanel(app.TabWelch);
            app.WelchPanel.Position = [2 107 309 97];

            % Create OverlapLabel
            app.OverlapLabel = uilabel(app.WelchPanel);
            app.OverlapLabel.Enable = 'off';
            app.OverlapLabel.Position = [237 36 25 22];
            app.OverlapLabel.Text = '%';

            % Create OverlapEditFieldLabel
            app.OverlapEditFieldLabel = uilabel(app.WelchPanel);
            app.OverlapEditFieldLabel.Position = [8 36 79 22];
            app.OverlapEditFieldLabel.Text = 'Overlap';

            % Create OverlapEditField
            app.OverlapEditField = uieditfield(app.WelchPanel, 'numeric');
            app.OverlapEditField.LowerLimitInclusive = 'off';
            app.OverlapEditField.UpperLimitInclusive = 'off';
            app.OverlapEditField.Limits = [0 100];
            app.OverlapEditField.Editable = 'off';
            app.OverlapEditField.Enable = 'off';
            app.OverlapEditField.Position = [196 36 41 22];
            app.OverlapEditField.Value = 50;

            % Create WindowWidthEditFieldLabel
            app.WindowWidthEditFieldLabel = uilabel(app.WelchPanel);
            app.WindowWidthEditFieldLabel.Position = [8 65 82 22];
            app.WindowWidthEditFieldLabel.Text = 'Window Width';

            % Create WindowWidthEditField
            app.WindowWidthEditField = uieditfield(app.WelchPanel, 'numeric');
            app.WindowWidthEditField.LowerLimitInclusive = 'off';
            app.WindowWidthEditField.UpperLimitInclusive = 'off';
            app.WindowWidthEditField.Limits = [0 Inf];
            app.WindowWidthEditField.Editable = 'off';
            app.WindowWidthEditField.Enable = 'off';
            app.WindowWidthEditField.Position = [196 65 41 22];
            app.WindowWidthEditField.Value = 1;

            % Create WindowWidthButtonGroup
            app.WindowWidthButtonGroup = uibuttongroup(app.WelchPanel);
            app.WindowWidthButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @WindowWidthButtonGroupSelectionChanged, true);
            app.WindowWidthButtonGroup.Position = [94 65 100 22];

            % Create WindowWidthDefaultButton
            app.WindowWidthDefaultButton = uiradiobutton(app.WindowWidthButtonGroup);
            app.WindowWidthDefaultButton.Tooltip = {'By default the signal is divided into the longest possible sements to obtain as close to but not exceed 8 segments with 50% overlap.'};
            app.WindowWidthDefaultButton.Text = 'Default';
            app.WindowWidthDefaultButton.Position = [3 -1 60 22];
            app.WindowWidthDefaultButton.Value = true;

            % Create WindowWidthButton
            app.WindowWidthButton = uiradiobutton(app.WindowWidthButtonGroup);
            app.WindowWidthButton.Text = '';
            app.WindowWidthButton.Position = [77 -1 25 22];

            % Create WindowWidthLabel
            app.WindowWidthLabel = uilabel(app.WelchPanel);
            app.WindowWidthLabel.Enable = 'off';
            app.WindowWidthLabel.Position = [238 66 25 22];
            app.WindowWidthLabel.Text = 's';

            % Create OverlapButtonGroup
            app.OverlapButtonGroup = uibuttongroup(app.WelchPanel);
            app.OverlapButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @OverlapButtonGroupSelectionChanged, true);
            app.OverlapButtonGroup.Position = [94 36 100 22];

            % Create OverlapDefaultButton
            app.OverlapDefaultButton = uiradiobutton(app.OverlapButtonGroup);
            app.OverlapDefaultButton.Tooltip = {'The default number of overlapped samples is 50% of the window length.'};
            app.OverlapDefaultButton.Text = 'Default';
            app.OverlapDefaultButton.Position = [3 -1 60 22];
            app.OverlapDefaultButton.Value = true;

            % Create OverlapButton
            app.OverlapButton = uiradiobutton(app.OverlapButtonGroup);
            app.OverlapButton.Text = {''; ''};
            app.OverlapButton.Position = [77 -1 20 22];

            % Create NfftButtonGroup
            app.NfftButtonGroup = uibuttongroup(app.WelchPanel);
            app.NfftButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @NfftButtonGroupSelectionChanged, true);
            app.NfftButtonGroup.Position = [94 8 100 22];

            % Create NfftDefaultButton
            app.NfftDefaultButton = uiradiobutton(app.NfftButtonGroup);
            app.NfftDefaultButton.Tooltip = {'The default nfft is the greater of 256 or the next power of 2 greater than the length of the segments.'};
            app.NfftDefaultButton.Text = 'Default';
            app.NfftDefaultButton.Position = [3 -1 60 22];
            app.NfftDefaultButton.Value = true;

            % Create NfftButton
            app.NfftButton = uiradiobutton(app.NfftButtonGroup);
            app.NfftButton.Text = {''; ''};
            app.NfftButton.Position = [77 -1 20 22];

            % Create NfftLabel
            app.NfftLabel = uilabel(app.WelchPanel);
            app.NfftLabel.Enable = 'off';
            app.NfftLabel.Position = [239 9 25 22];
            app.NfftLabel.Text = 's';

            % Create NfftEditFieldLabel
            app.NfftEditFieldLabel = uilabel(app.TabWelch);
            app.NfftEditFieldLabel.Position = [10 115 79 22];
            app.NfftEditFieldLabel.Text = 'Nfft';

            % Create NfftEditField
            app.NfftEditField = uieditfield(app.TabWelch, 'numeric');
            app.NfftEditField.LowerLimitInclusive = 'off';
            app.NfftEditField.Limits = [0 Inf];
            app.NfftEditField.Editable = 'off';
            app.NfftEditField.Enable = 'off';
            app.NfftEditField.Tooltip = {'The number of discrete Fourier transform (DFT) points to use.'};
            app.NfftEditField.Position = [198 115 41 22];
            app.NfftEditField.Value = 1;

            % Create RDecoPreferencesLabel
            app.RDecoPreferencesLabel = uilabel(app.PreferencesUIFigure);
            app.RDecoPreferencesLabel.BackgroundColor = [0.651 0.651 0.651];
            app.RDecoPreferencesLabel.FontColor = [1 1 1];
            app.RDecoPreferencesLabel.Position = [167 246 311 26];
            app.RDecoPreferencesLabel.Text = ' R-Deco Preferences';

            % Create DefaultButton
            app.DefaultButton = uibutton(app.PreferencesUIFigure, 'push');
            app.DefaultButton.ButtonPushedFcn = createCallbackFcn(app, @DefaultButtonPushed, true);
            app.DefaultButton.Enable = 'off';
            app.DefaultButton.Position = [379 10 100 22];
            app.DefaultButton.Text = 'Default';
        end
    end

    methods (Access = public)

        % Construct app
        function app = Preferences(varargin)

            % Create and configure components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.PreferencesUIFigure)

            % Execute the startup function
            runStartupFcn(app, @(app)startupFcn(app, varargin{:}))

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.PreferencesUIFigure)
        end
    end
end