% pdsch test cases config
clear all
clc


common_TVSetting = [
    ...%仿真参数设置
    'simu_params.nBS = 2;',...
    'simu_params.BS{1}.nUE = 1;', ...
    'simu_params.BS{1}.UE{1}.type = ''active'';',...
    'simu_params.nSlot = 100;', ...
    'simu_params.firstSlotIdx = 1;', ...
    'MAC_params.BS{1}.Bandwidth = 100;', ...
    'MAC_params.BS{1}.allocatedVRB_index = [1:273];', ...%[1:273]
    'MAC_params.BS{1}.nBWP = 1;',...
    'MAC_params.BS{1}.BWP{1}.frame_struct.cyclicPrefix = ''Normal'';', ...
    'MAC_params.BS{1}.BWP{1}.subcarrierSpacing = ''kHz30'';',...
    'MAC_params.BS{1}.BWP{1}.BWPallocatedPRB_index = [1:273];',...
    'MAC_params.BS{1}.UE{1}.ActiveBWP_ID = 1;', ...
    'MAC_params.BS{1}.mu = 1;', ...
    'MAC_params.BS{1}.cellID = 100;',...
    'MAC_params.BS{1}.oversamplingTimes = 1;', ...
    'MAC_params.constant.nMaxHARQRetransmission = 4;', ...
    ...% 各信道开关
    'simu_params.BS{1}.is_DL= ''True'';',...
    'simu_params.BS{1}.is_SSB = ''False'';', ...
    'simu_params.BS{1}.is_CSIRS  = ''False'';', ...%用来测量下行的SINR,并进行上报
    'simu_params.BS{1}.UE{1}.is_PDCCH = ''False'';', ...
    'simu_params.BS{1}.UE{1}.is_PDSCH = ''True'';', ...
    ...%下行接收开关
    'simu_params.BS{1}.UE{1}.DL_Rx_process = ''DISABLED'';'...
    ...% 定点化开关
    'simu_params.fixedPoint.is_SSB = ''True''; ' , ...% PDCCH Tx定点化开关True/False, by QY
    'simu_params.fixedPoint.is_PDCCH = ''True''; ', ... % PDCCH Tx定点化开关True/False, by QY
    'simu_params.fixedPoint.is_PDSCH = ''True'';' , ... % PDSCH Tx定点化开关True/False, by QY
    'simu_params.fixedPoint.is_CSIRS = ''True'';' , ... % CSIRS Tx定点化开关True/False, by QY
    'simu_params.fixedPoint.moduleSqnrsw = ''False''; ', ... % 定点化SQNR统计True/False, by QY
    ...%上行开关
    'simu_params.BS{1}.is_UL = ''False'';',...
    'simu_params.BS{1}.UE{1}.is_PRACH = ''False'';', ...
    'simu_params.BS{1}.UE{1}.is_PUSCH = ''False'';' ,...
    'simu_params.BS{1}.UE{1}.is_PUCCH = ''False'';' ,...
    ...% 信道相关参数
    'simu_params.SNR_Range = 50;', ...
    'simu_params.BS{1}.CorfileTx = ''cor_low_tx1'';',...% 系统参数配置
    'simu_params.BS{1}.UE{1}.CorfileRx = ''cor_low_rx4'';',...
     'MAC_params.BS{1}.nAntenna = 1;', ...
    'MAC_params.BS{1}.nAntennaForPDSCH = 1;', ...
    'MAC_params.BS{1}.nAntennaForPDCCH = 1;', ...
    'MAC_params.BS{1}.nAntennaForCSIRS = 1;',...
    'MAC_params.BS{1}.UE{1}.nAntenna = 4;', ...
    'simu_params.channel.type = ''TDL-A'';',...
    'simu_params.channel.new_channel = 1;', ...
    'simu_params.BS{1}.UE{1}.channel.Fading_sw = +1;', ...% -1:直通信道, +1:多径信道
    'simu_params.BS{1}.UE{1}.chmodel = ''chmodel_TDLA30'';',...
    'simu_params.BS{1}.UE{1}.channel.Fd = 10;',...  % maximum Dopplar freq.
    ...% 仿真参数配置
    'simu_params.BS{1}.UE{1}.cpri_compressed_sw = 0;'...
    'simu_params.window = 0;', ...
    'simu_params.window_rx = 0;', ...
    'simu_params.deltaf_comp_sw = ''True'';',... % 'True'  'False'
    'simu_params.TA = 0;',...
    'simu_params.ADC = 0;',...
    ];

%% 单UEcase0
case0_UE0_PDSCH = ...
    ['simu_params.iTC = -1;', ...
    'MAC_params.BS{1}.UE{1}.nPortForPDSCH = 1;', ...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.isTransmissionPTRS = 0;',...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.Beta_PDSCHDATA = 0;',... % -3000 -- -3dB
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.Beta_PDSCHDDMRS = 0;',...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.RNTI = 267;', ...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.BWPstart = 1;',...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.BWPsize = 273;',...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.mu = MAC_params.BS{1}.mu;',... % subcarrier spacing
    'MAC_params.BS{1}.UE{1}.BWP{1}.frame_struct.cyclicPrefix = MAC_params.BS{1}.BWP{1}.frame_struct.cyclicPrefix;',...
    ...% 参数配置
    'MAC_params.BS{1}.UE{1}.nCodeWord = 1;',...             %单流/双流
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.I_MCS = 27;', ...   %确定目标码率和调制阶数I_MCS=1--》Qm=2,
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.mcs_Table = ''qam256'';', ... %'qam256' / 'qam64LowSE'
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.RVid = 0;',...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.dmrsAntennaPort_index = [0];', ... %对应layer=4数与Port Index
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.iBS = MAC_params.BS{1}.cellID;', ... % nIdPdsch
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.PRGsize = 0;',... % 0/2/4, 0-wideband
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.VRB_to_PRBmappingType = 0;', ...%1/0：交织/不交织
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.RBG_BundleSize = 4;', ... % Li 2/4
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.Interleaver_size = 2;',... % 交织行数R
    ... % PDSCH时频资源设置
    'simu_params.BS{1}.UE{1}.symbol_pattern = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];', ...  % PDSCH时域资源映射
    'MAC_params.BS{1}.UE{1}.allocatedVRB_index = [109:273];', ...% PDSCH频域资源映射%%真正生效的RB配置
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.PDSCHmapType = ''A'';'...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.ResourceAllocateType = 1;'... % type 1
    ... % DMRS时频资源设置
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.TPMI = 0;', ...% Transmission Precoding Matrix indicator index 
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.DMRSConfigType = ''1'';', ... % dmrsConfigType = 0
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.dmrsTypeAPos = 2;',...   % l_0 = 2 dlDmrsSymbPos = 0x4
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.DMRSAddPos = 0;', ...%pos0,1,2,3对应不配置后置DMRS,符号11，符号7+11，符号5+8+11
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.NumCDMGroupsWithoutData = 2;'...%1: DMRS符号上同时放DATA, 2: DMRS符号上不放DATA
    'MAC_params.BS{1}.UE{1}.PDCCH_Config.LdpcToolbox = 0;'... % 0不调用toolbox，1调用toolbox
    'MAC_params.BS{1}.nSCID = 0;'... % nSCID
    'MAC_params.BS{1}.UE{1}.N_nSCID_ID = 100;'...% dlDmrsScramblingId
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.nSymbolDMRS = 1;'... % maxlength = 1, 1/2,1 is single-symbol case, 2 is double-symbol case, never modify except for test, since the demod module of double-symbol case is not developed yet, though other modules are already
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.isDigitalBeamforming = 0;'...
    'MAC_params.BS{1}.UE{1}.PDSCH_Config.DBindex = [1];',...%维度与nAntennaForPDSCH匹配
    ];


test_cases = {[common_TVSetting,case0_UE0_PDSCH,...
    'simu_params.BS{1}.UE{1}.DL_Rx_process = ''ENABLED'';', ...
    'simu_params.TwoCell_flag = ''True'';',...% 一体化两小区模式
    'simu_params.BS{2} = simu_params.BS{1};',...
    'MAC_params.BS{2} = MAC_params.BS{1};',...
    'MAC_params.BS{2}.UE{1}.allocatedVRB_index = [1:164];', ...% PDSCH频域资源映射%%真正生效的RB配置
    'simu_params.DFE_flag =  ''False'';'...  % True  %False  如果TwoCell_flag = ''True''且 DFE_flag =  ''False''，则使用8192点FFT模式，两小区的中心频点间隔必须满足30k的整数倍
    'simu_params.BS{1}.baseband_f0 = -50.01e06;',...
    'simu_params.BS{2}.baseband_f0 = 49.98e06;'...
    'MAC_params.BS{1}.PointAFrequency = 2493850e3;', ...% 通过pointA和Bandwidth计算CenterFrequency PointAFrequency = 2493850e3 对应小区1中心频点2542990e3
    'MAC_params.BS{1}.UE{1}.PointAFrequency = MAC_params.BS{1}.PointAFrequency;', ...
    'MAC_params.BS{2}.PointAFrequency = MAC_params.BS{1}.PointAFrequency+99.99e6;', ...   % 两个小区的中心频点间隔99.99M
    'MAC_params.BS{2}.UE{1}.PointAFrequency = MAC_params.BS{2}.PointAFrequency;', ...
    'simu_params.dBfs = -15;', ...
    ]};

% call 'NR_simu_main' to simulate the test cases
[simu_result_all] = NR_simu_main(test_cases);


