function [PRBSDataLength,PRBSFrequencies,DelayVector] = freblkUpdateVariant(blk,NumOfPRBSPeriod,PRBSSignalOrder,Ts)
%   Utility function of FRE block

%   Author: R. Chen
%   Copyright 2018 The MathWorks, Inc.

% Set default values of output arguments
PRBSDataLength = 2^12-1;
freq(1,1:2^12) = 2*(pi/Ts)*linspace(0,1,2^12);
PRBSFrequencies(1,1:2^11) = freq(1,1:2^11);
DelayVector = int32([1 3 2 6]);

IsOutputCD = strcmpi(get_param(blk,'OutputMode'),slsvInternal('slsvGetEnStringFromCatalog','Slcontrol:onlinefre:rbtnElementCplusD'));
if strcmpi(get_param(blk,'ExperimentMode'),slsvInternal('slsvGetEnStringFromCatalog','Slcontrol:onlinefre:rbtnElementSS'))
    InputSignalType = 'Sinestream';
elseif strcmpi(get_param(blk,'ExperimentMode'),slsvInternal('slsvGetEnStringFromCatalog','Slcontrol:onlinefre:rbtnElementSI'))
    InputSignalType = 'Superposition';
else
    InputSignalType = 'PRBS';
end
IsOnlineEstimation = strcmpi(get_param(blk,'EstimationMode'),slsvInternal('slsvGetEnStringFromCatalog','Slcontrol:onlinefre:rbtnElementOnline'));
UseBodePlot = strcmpi(get_param(blk,'UseBodePlot'),'on');
IsExternalCompiledTs = strcmpi(get_param(blk,'UseExternalTs'),'on');
% Select variant subsystem for Experiment/Estimation and BodePlot
if strcmp(InputSignalType,'Sinestream')
    if IsOnlineEstimation
        if UseBodePlot && Ts>0
            set_param(blk,'ExperimentChoice','VariantSS','BodePlotChoice','VariantBode');
        else
            set_param(blk,'ExperimentChoice','VariantSS','BodePlotChoice','VariantNull');
            if UseBodePlot && Ts==-1
                fprintf('%s\n',getString(message('Slcontrol:onlinefre:warnNoBodePlot')));
            end
        end
    else
        set_param(blk,'ExperimentChoice','VariantSSNoEst','BodePlotChoice','VariantNull');
    end
elseif strcmp(InputSignalType,'Superposition')
    if IsOnlineEstimation    
        if UseBodePlot && Ts>0
            set_param(blk,'ExperimentChoice','VariantSI','BodePlotChoice','VariantBode');
        else
            set_param(blk,'ExperimentChoice','VariantSI','BodePlotChoice','VariantNull');
            if UseBodePlot && Ts==-1
                fprintf('%s\n',getString(message('Slcontrol:onlinefre:warnNoBodePlot')));
            end
        end
    else
        set_param(blk,'ExperimentChoice','VariantSINoEst','BodePlotChoice','VariantNull');
    end
else
    PRBSDataLength = (2^PRBSSignalOrder-1)*NumOfPRBSPeriod;
    PRBSFrequencies = [];
    DelayVector = [];
    
    % Delay matrix
    D = int32([1 0 0 0;
             1 1 0 0;
             2 1 0 0;
             3 1 0 0;
             3 2 0 0;
             5 1 0 0;
             6 1 0 0;
             4 1 1 2;
             5 4 0 0;
             7 3 0 0;
             9 2 0 0;
             1 3 2 6;
             1 2 1 9;
             1 2 2 9;
             14 1 0 0;
             4 9 2 1;
             14 3 0 0;
             11 7 0 0;
             1 1 4 13;
             17 3 0 0;
             19 2 0 0;
             21 1 0 0;
             18 5 0 0;
             17 5 1 1;
             22 3 0 0;
             1 1 4 20;
             1 1 3 22;
             25 3 0 0;
             27 2 0 0;
             1 3 2 24;
             28 3 0 0;
             1 1 20 10]);
    DelayVector = D(PRBSSignalOrder,:);
    
    if rem(PRBSDataLength,2)
        % Odd Length
        freq(1,1:PRBSDataLength+1) = 2*(pi/Ts)*linspace(0,1,PRBSDataLength+1);
        PRBSFrequencies(1,1:(PRBSDataLength+1)/2) = freq(1,1:(PRBSDataLength+1)/2);
    else
        % Even Length
        PRBSFrequencies(1,1:PRBSDataLength/2+1) = (pi/Ts)*linspace(0,1,PRBSDataLength/2+1);
    end

    if IsOnlineEstimation    
        if UseBodePlot && Ts>0
            set_param(blk,'ExperimentChoice','VariantPRBS','BodePlotChoice','VariantBode');
        else
            set_param(blk,'ExperimentChoice','VariantPRBS','BodePlotChoice','VariantNull');
            if UseBodePlot && Ts==-1
                fprintf('%s\n',getString(message('Slcontrol:onlinefre:warnNoBodePlot')));
            end
        end
    else
        set_param(blk,'ExperimentChoice','VariantPRBSNoEst','BodePlotChoice','VariantNull');
    end
end
if IsOutputCD
    set_param(blk,'OutputChoice','VariantCandD');
else
    set_param(blk,'OutputChoice','VariantDonly');
end
if IsExternalCompiledTs
    set_param(blk,'CompiledTsChoice','ExternalTs');
else
    set_param(blk,'CompiledTsChoice','InternalTs');
end
