function configParams = helperBLEModulationTestConfig(testID,sps)
%helperBLEModulationTestConfig returns BLE test parameters for each BLE
%transmitter test corresponding to modulation characteristics, carrier
%frequency offset and drift.
%   CONFIGPARAMS = helperBLEModulationTestConfig(TESTID,SPS) returns BLE
%   transmitter test parameters, CONFIGPARAMS.
%   
%   TESTID is a character vector or string specifying the transmitter test
%   ID. It must be one of the following:
%   {'RF-PHY/TRM/BV-09-C','RF-PHY/TRM/BV-11-C',
%    'RF-PHY/TRM/BV-13-C','RF-PHY/TRM/BV-06-C',
%    'RF-PHY/TRM/BV-12-C','RF-PHY/TRM/BV-14-C'}.
%   
%   SPS represents the number of samples per symbol.
%
%   CONFIGPARAMS, a structure containing the following test parameters:
%   SPS             - Samples per symbol
%   SYMBOLRATE      - Symbol rate
%   BITSPERBYTE     - Bits per byte
%   PHYMODE         - Physical layer transmission mode
%   TESTSEQIDS      - Type of test sequence(s)
%   TESTSEQID       - Test sequence
%   NONPDULEN       - Length of BLE packet excluding PDU
%   DISCARDSTARTLEN - Number of bits to discard at the start of the packet
%   DISCARDENDLEN   - Number of bits to discard at the end of the packet
%   PREAMBLELEN     - Length of the preamble
%   CODINGFACTOR    - FEC Coding scheme
%   NUMOFTESTSEQS   - Number of test sequence
%   SAMPLERATE      - Sampling rate

%   Copyright 2019-2020 The MathWorks, Inc.

% Get test parameters based on test ID  
configParams.sps = sps;
configParams.symbolRate = 1e6; % In Hz
configParams.bitsPerByte = 8;    % Number of bits per byte
crcLen = 24;
accessAddLen = 32;
headerLen = 16;
termField1Len = 0;
termField2Len = 0;
codedFieldLen = 0;
codingFactor = 1;
switch testID
    case 'RF-PHY/TRM/BV-06-C'  % Offset and Drift Test
        configParams.phyMode = 'LE1M';
        configParams.testSeqIds = 2;
        configParams.testSeqId(1,:) = '10101010';
        preambleLen = 8;
        bitOffset1 = 1; % Number of bits to be discarded from the start of the payload
        bitOffset2 = 0; % Number of bits to be discarded from the end of the payload, 0 value indicates no need to discard
        configParams.intervalDuration = 10; 
    case 'RF-PHY/TRM/BV-09-C'   % Modulation Test
        configParams.phyMode = 'LE1M';
        configParams.testSeqIds = [1,2];
        configParams.testSeqId(1,:) = '00001111';
        configParams.testSeqId(2,:) = '10101010';
        preambleLen = 8;
        bitOffset1 = 4; % Number of bits to be discarded from the start of the payload
        bitOffset2 = 4; % Number of bits to be discarded from the end of the payload
    case 'RF-PHY/TRM/BV-11-C'   % Modulation Test
        configParams.phyMode = 'LE2M';
        configParams.symbolRate = 2e6; 
        configParams.testSeqIds = [1,2];
        configParams.testSeqId(1,:) = '00001111';
        configParams.testSeqId(2,:) = '10101010';
        preambleLen = 16;
        bitOffset1 = 4; % Number of bits to be discarded from the start of the payload
        bitOffset2 = 4; % Number of bits to be discarded from the end of the payload          
    case 'RF-PHY/TRM/BV-12-C'   % Offset and Drift Test
        configParams.phyMode = 'LE2M';
        configParams.testSeqId(1,:) = '10101010';
        configParams.symbolRate = 2e6;
        configParams.testSeqIds = 2;
        preambleLen = 16;
        bitOffset1 = 1; % Number of bits to be discarded from the start of the payload
        bitOffset2 = 0; % Number of bits to be discarded from the end of the payload, 0 value indicates no need to discard
        configParams.intervalDuration = 20; 
    otherwise%'LE125K'
        configParams.phyMode = 'LE125K';
        configParams.testSeqIds = 4;
        preambleLen = 80;
        termField1Len = 3;
        termField2Len = 3;
        codedFieldLen = 2;
        codingFactor = 8;
        configParams.testSeqId(1,:) = '11111111';
        if(strcmp(testID,'RF-PHY/TRM/BV-13-C')) % Modulation Test 
            bitOffset1 = 30.25; % Discard 30 bits from the start of the payload
                                % as per the test procedure and discard 0.25
                                % bits inorder to start from 11110000 sequence
            bitOffset2 = 34.75; % Discard 34 bits from the end of the payload
                                % as per the test procedure and discard 0.75 bits
                                % inorder to remove one complete bit from the measurement
        else % Offset and Drift Test
            bitOffset1 = 26; % Number of bits to be discarded from the start of the payload
            bitOffset2 = -3; % Number of bits to be discarded from the end of the payload
            configParams.intervalDuration = 16; 
        end
end
configParams.nonPDULen = preambleLen+(accessAddLen+headerLen+crcLen+termField1Len+termField2Len+codedFieldLen)*codingFactor;
configParams.discardStartLen = preambleLen+(accessAddLen+headerLen+termField1Len+codedFieldLen+bitOffset1)*codingFactor;
configParams.discardEndLen = (bitOffset2+crcLen+termField2Len)*codingFactor;
configParams.preambleLen = preambleLen;
configParams.codingFactor = codingFactor;
configParams.numOfTestSeqs = length(configParams.testSeqIds);
configParams.sampleRate = configParams.symbolRate*sps;
end