function [alpha,beta,gamma,interferenceFreq1,interferenceFreq2] = ...
                helperBLETestParamGenerate(rxPerformanceTest,Fc,phyMode)
%helperBLETestParamGenerate BLE test parameters generation
%   [ALPHA,BETA,GAMMA,INTERFERENCEFREQ1,INTERFERENCEFREQ2] =
%   helperBLETestParamGenerate(RXPERFORMANCETEST,FC,PHYMODE) returns the
%   test parameters used for receiver measurements.
%
%   ALPHA is a scaling factor for the wanted signal which varies depending
%   upon the PHY transmission mode and receiver performance test.
%
%   BETA is a vector containing scaling factors for interference signal #1,
%   which varies depending upon the PHY transmission mode and receiver
%   performance test.
%
%   GAMMA is a vector containing scaling factors for interference signal
%   #2, which varies depending upon the PHY transmission mode.
%
%   INTERFERENCEFREQ1 is a vector containing interference frequencies for
%   interference signal #1.
%
%   INTERFERENCEFREQ2 is a vector containing interference frequencies for
%   interference signal #2.
%
%   RXPERFORMANCETEST is a character vector or string specifying the
%   receiver performance test to be performed. It must be one of the
%   following: 'C/I', 'Blocking', 'Intermodulation'.
%
%   FC is the operating carrier frequency of the IUT in Hz, which varies
%   depending upon the performance test, GAP role.
%
%   PHYMODE is a character vector or string specifying the PHY on which
%   decoding is performed. It must be one of the following: 'LE1M','LE2M',
%   'LE500K','LE125K'.
%
%   Reference - Section-4.5, Bluetooth RF-PHY Test Specifications.

%   Copyright 2019 The MathWorks, Inc.

% Calculate scaling factor for wanted signal (alpha) based on PHY mode and
% receiver performance test as shown in the table below.
%-------------------------------------------------
% PHY Mode |      Signal level(dBm)              |
%          |-------------------------------------|
%          | C/I    | Blocking | Intermodulation |
%----------|-------------------------------------|
% LE1M     |  -67   |   -67    |      -64        |
% LE2M     |  -67   |   -67    |      -64        |
% LE500K   |  -72   |    -     |        -        |
% LE125K   |  -79   |    -     |        -        |
%-------------------------------------------------
sigLevel = -67; % in dBm
if strcmp(rxPerformanceTest,'Intermodulation')
    sigLevel = -64; % in dBm
elseif strcmp(phyMode,'LE500K')
   sigLevel = -72; % in dBm
elseif strcmp(phyMode,'LE125K')
    sigLevel = -79; % in dBm
end
dBm2dBWFactor = 30;
alpha = 10^((sigLevel-dBm2dBWFactor)/20); % Voltage gain (attenuation)

% Frequency factor for 1 Msps & 2 Msps modes
freqFactor = 1; % For 'LE1M' , 'LE500K' , 'LE125K'
if strcmp(phyMode,'LE2M')
    freqFactor = 2; % For 'LE2M'
end

% Calculate buffer size such that the all the interference parameters are
% covered for a selected receiver performance test.
if strcmp(rxPerformanceTest,'Blocking')
    maxInterferenceParams = 894;
elseif strcmp(rxPerformanceTest,'Intermodulation')
    maxInterferenceParams = 6;
elseif strcmp(rxPerformanceTest,'C/I') && strcmp(phyMode,'LE2M')
    maxInterferenceParams = 42;
else  % For rxPerformanceTest = 'C/I' && (phyMode = 'LE1M' || 'LE500K' || 'LE125K')
    maxInterferenceParams = 84;
end

% Initialize parameters for interfering signals
interferenceFreq1 = zeros(maxInterferenceParams,1);
interferenceFreq2 = zeros(maxInterferenceParams,1);
gamma = zeros(maxInterferenceParams,1);
beta = zeros(maxInterferenceParams,1);

% Compute scaling factors and frequencies for interfering signals based on
% receiver performance tests.

% C/I performance test
if strcmp(rxPerformanceTest,'C/I')

    % Initialize signal levels for interference signal with '-40dBm', as
    % this is the signal level for maximum interference frequencies.
    sigLevel = -40*ones(maxInterferenceParams,1); % dBm

    % Depending on the interference frequency the signal level is varied
    interferenceFreq1 = (2400 + ((1:maxInterferenceParams)-1).'*freqFactor)*1e6; % Covers 2400-2483 MHz frequency range
    sigLevel (interferenceFreq1 == Fc) = -88; % For co-channel interference
    % For 1 MHz(1 Msps)/2 MHz(2 Msps) adjacent channel
    sigLevel (interferenceFreq1 == (Fc + freqFactor*1e6) | interferenceFreq1 == (Fc - freqFactor*1e6)) = -82;
    % For 2 MHz(1 Msps)/4 MHz(2Msps) adjacent channel
    sigLevel (interferenceFreq1 == (Fc + freqFactor*2e6) | interferenceFreq1 == (Fc - freqFactor*2e6)) = -50; 

    % Sensitivity factor is used to add the difference value of
    % interference signal level for different PHY modes.
    sensitivityFactor = 0;  % For LE1M and LE2M (dB)
    if strcmp(phyMode,'LE500K')
        sensitivityFactor = -1; % dB
    elseif strcmp(phyMode,'LE125K')
        sensitivityFactor = -3; % dB
    end

    % Calculate scaling factor for interference signal (beta)
    beta = 10.^((sigLevel + sensitivityFactor - dBm2dBWFactor)/20);  % Voltage gain (attenuation)

% Blocking performance test
elseif strcmp(rxPerformanceTest,'Blocking')

    % Generate interference frequencies and assign corresponding signal
    % levels as per the table below.
    %----------------------------------------------------------------------
    % Interference frequency | Blocking signal level | Frequency resolution
    %----------------------------------------------------------------------
    %     30 - 2000 MHz      |       -30 dBm         |        10 MHz
    %   2003 - 2399 MHz      |       -35 dBm         |         3 MHz
    %   2484 - 2997 MHz      |       -35 dBm         |         3 MHz
    %      3 - 12.75 GHz     |       -30 dBm         |        25 MHz
    %----------------------------------------------------------------------

    numFreqBand1 = 198; % Number of frequencies in band1 (30-2000) MHz
    numFreqBand2 = 133; % Number of frequencies in band2 (2003-2399) MHz
    numFreqBand3 = 172; % Number of frequencies in band3 (2484-2997) MHz

    % Initialize signal level & frequency resolution vectors with -35 dBm &
    % 3 MHz which corresponds to (2003-2399) MHz band & (2484-2997) MHz
    % band respectively.
    sigLevel = -35*ones(maxInterferenceParams,1); % dBm
    freqResolution = 3e6*ones(maxInterferenceParams,1); % Hz

    % For frequency range (30-2000) MHz, map the corresponding signal level
    % and frequency resolution.
    sigLevel(1:numFreqBand1) = -30; % dBm
    freqResolution(1:numFreqBand1) = 10e6; % Hz

    % For frequency range (3-12.75) GHz, map the corresponding signal level
    % and frequency resolution.
    sigLevel(numFreqBand1+numFreqBand2+numFreqBand3+1:maxInterferenceParams) = -30; % dBm
    freqResolution(numFreqBand1+numFreqBand2+numFreqBand3+1:maxInterferenceParams) = 25e6; % Hz

    % Generate interference frequencies as per Bluetooth RF-PHY Test
    % Specifications.
    interferenceFreq2 = freqResolution;
    interferenceFreq2(1) = 30e6;
    interferenceFreq2(numFreqBand1+numFreqBand2+1) = 2484e6;
    interferenceFreq2(numFreqBand1+numFreqBand2+numFreqBand3+1) = 3000e6;
    y1 = cumsum(interferenceFreq2(1:numFreqBand1+numFreqBand2));
    y2= cumsum(interferenceFreq2(numFreqBand1+numFreqBand2+1:numFreqBand1+numFreqBand2+numFreqBand3)); 
    y3 = cumsum(interferenceFreq2(numFreqBand1+numFreqBand2+numFreqBand3+1:end)); 
    interferenceFreq2 = [y1;y2;y3];
    % Calculate scaling factor for interference signal (gamma)
    gamma = 10.^((sigLevel-dBm2dBWFactor)/20);  % Voltage gain (attenuation)

% Intermodulation performance test
else
    % Generate interference frequencies as per Bluetooth RF-PHY Test
    % Specifications.
    interferenceFreq1(1:3) = Fc - 2*((1:3)+2)*freqFactor*1e6;
    interferenceFreq1(4:6) = Fc + 2*((4:6)-1)*freqFactor*1e6;
    interferenceFreq2(1:3) = Fc - ((1:3)+2)*freqFactor*1e6;
    interferenceFreq2(4:6) = Fc + ((4:6)-1)*freqFactor*1e6;

    % Signal level of interference signal is -50dBm
    sigLevel = -50*ones(maxInterferenceParams,1); % dBm
    beta = 10.^((sigLevel-dBm2dBWFactor)/20); % Voltage gain (attenuation)
    gamma = beta; % Voltage gain (attenuation)
end