MATLA 5G工具箱---5G NR链路通信链路模型
基于MATLAB R2022b版软件学习!
5G NR 通信链路模型
使用5G工具箱,可以对5G NR共享信道链路进行建模,包括从生成传输块到传输通道解码所有的步骤。下图为下行通信链路的主要元素。
这个示例展示了下行通信链路主要的元素怎么进行建模。上行通信链路的主要元素的建模也是类似的。
- Model 5G NR Transport Channels with HARQ 示例描述了如何使用下行链路共享信道 (DL-SCH) 编码器和解码器系统对象对具有多个混合自动重复请求 (hybrid automatic repeat-request,HARQ) 进程的 5G NR 传输信道进行建模;
- 将 5G 物理信道和信号映射到资源网格示例展示了如何生成、预编码 5G NR 物理信道和信号并将其映射到资源网格。
- DL-SCH 和 PDSCH 发送和接收处理链示例展示了如何对完整的物理下行链路共享信道链路进行建模,包括编码阶段、信道建模以及接收器和解码步骤。
Model 5G NR Transport Channels with HARQ - MATLAB & Simulink (mathworks.com)
Model 5G NR Transport Channels with HARQ 示例
下图显示了该示例在5G下行链路上下文中建模的链路元素,包括:
- DL-SCH编解码
- 物理下行共享信道(PDSCH)编解码
- HARQ管理
该示例中未对其他链路元素进行建模。
该示例还使用AWGN信道来测量误码率(block error rate,BLER),下图为进行误码率计算时建模时的所有链路元素。
下图为DL-SCH编码器使用内部缓冲区存储每个HARQ进程的传输块,并筛选活动的HARQ进程缓冲区内容进行编码。DL-SCH编码器使用类似的缓冲机制来存储和选择HARQ进程。
DL-SCH 编码器和解码器不在内部管理 HARQ 进程。该示例将 HARQ 实体对象 HARQEntity.m
用于HARQ 进程管理。下图显示了HARQ实体对象的结构。
仿真参数
指定要仿真的传输块数和信噪比(SNR)。
noTransportBlocks = 100;
SNRdB = 7; % SNR in dB
重置随机数生成器以实现可重复性。
rng("default");
DL-SCH配置
指定代码的速率、HARQ 进程数和冗余值 (RV) 序列。此序列控制在发生错误时重新传输冗余版本。
% DL-SCH 参数
codeRate = 490/1024;
NHARQProcesses = 16; % HARQ所使用的并行进程数
rvSeq = [0 2 3 1];
创建 DL-SCH 编码器和解码器对象。 要使用多个进程,请将两个对象的 MultipleHARQProcesses 属性设置为 true。 为了启用多个 HARQ 进程的重传,编码器缓冲输入位。 解码器需要类似的机制来为每个 HARQ 进程启用重传的软组合。
% Create DL-SCH encoder object 编码
encodeDLSCH = nrDLSCH;
encodeDLSCH.MultipleHARQProcesses = true;
encodeDLSCH.TargetCodeRate = codeRate;
% Create DL-SCH decoder object 解码
decodeDLSCH = nrDLSCHDecoder;
decodeDLSCH.MultipleHARQProcesses = true;
decodeDLSCH.TargetCodeRate = codeRate;
decodeDLSCH.LDPCDecodingAlgorithm = "Normalized min-sum";
decodeDLSCH.MaximumLDPCIterationCount = 6;
DL-SCH 编码器和解码器对象最多可以模拟 16 个 HARQ 进程。 在执行任何这些操作时,编码器和解码器对象使用 HARQ 实体对象的 HARQprocessID 属性来识别活动的 HARQ 进程。
- 设置需要传输的新传输块
- 编码数据
- 重置缓冲区
- 解码数据
载波和 PDSCH 配置
指定载波和PDSCH参数,用于PDSCH编解码和计算传输块的大小。
创建载波对象,指定子载波间隔(SCS)和带宽(BW)。
% Numerology
SCS = 15; % SCS: 15, 30, 60, 120 or 240 (kHz) 子载波
NRB = 52; % BW in number of RBs (52 RBs at 15 kHz SCS for 10 MHz BW) 带宽
carrier = nrCarrierConfig;
carrier.NSizeGrid = NRB;
carrier.SubcarrierSpacing = SCS;
carrier.CyclicPrefix = "Normal"; % "Normal" or "Extended"
创建 PDSCH 配置对象。PDSCH参数确定可用位容量和传输块大小。
modulation = "16QAM"; % Modulation scheme
pdsch = nrPDSCHConfig;
pdsch.Modulation = modulation;
pdsch.PRBSet = 0:NRB-1; % Assume full band allocation 假设全频带分配
pdsch.NumLayers = 1; % Assume only one layer and one codeword 假设只有一层和一个码字
HARQ 管理
创建HARQ实体对象来管理HARQ进程。对于每个HARQ进程,对象存储以下元素:
- HARQ ID 号
- RV
- 传输编号,指某个传输块已经传输的次数
- 指示是否需要更新数据的标志。当成功接收数据或者发生序列超时(所有RV传输失败)时,需要新数据。
- 指示是否已发生序列超时(所有RV传输失败)的标志。
harqEntity = HARQEntity(0:NHARQProcesses-1,rvSeq,pdsch.NumCodewords);
HARQ实体用来管理DL-SCH编码器和解码器的缓冲区。
误码率(BER)仿真
循环多个传输块。对于每个传输块:
- 以比特数计算传输块的大小
- 在解码器中生成新的数据块或者重置缓冲区
- 应用DL-SCH编码
- 将比特调制为符号
- 应用AWGN
- 解调软比特(符号到软比特)
- 解码DL-SCH
- 更新HARQ进程
% Initialize loop variables 初始化循环变量
noiseVar = 1./(10.^(SNRdB/10)); % Noise variance 噪声变量
numBlkErr = 0; % Number of block errors
numRxBits = []; % Number of successfully received bits per transmission
txedTrBlkSizes = []; % Number of transmitted info bits per transmission
for nTrBlk = 1:noTransportBlocks
% A transport block or transmission time interval (TTI) corresponds to 一个传输块或者传输间隔
% one slot 一个时隙
carrier.NSlot = carrier.NSlot+1;
传输块大小计算
% Generate PDSCH indices info, which is used to calculate the transport 生成PDSCH的索引信息用来计算传输块大小
% block size
[~,pdschInfo] = nrPDSCHIndices(carrier,pdsch);
% Calculate transport block sizes
Xoh_PDSCH = 0;
trBlkSizes = nrTBS(pdsch.Modulation,pdsch.NumLayers,numel(pdsch.PRBSet),pdschInfo.NREPerPRB,codeRate,Xoh_PDSCH);
由于以比特为单位的 PDSCH 容量 pdsch.G 是动态确定的,因此实际码率可能不完全等于 encodeDLSCH 对象的 TargetCodeRate 属性指定的目标码率。
HARQ处理(缓冲区管理)
本节介绍编码器和解码器中的缓冲区管理。
- DL-SCH编码区缓冲区:如果激活的HARQ进程需要更新数据,则生成新的传输块。将传输块存储在相应的缓冲区中。如果不需要新数据,则使用DL-SCH编码器中的缓冲位进行重传。
- DL-SCH解码器缓冲区:接收器中的软缓冲区存储以前接收到的同一传输块的版本。成功接收后,这些缓冲区将会自动清除(无CRC错误)。但是,如果RV序列在没有成功解码的情况下结束,则必须通过调用对象函数resetSoftBuffer手动刷新缓冲区。
% Get new transport blocks and flush decoder soft buffer, as required 根据需要获取新的传输块并刷新解码器软缓冲区
for cwIdx = 1:pdsch.NumCodewords
if harqEntity.NewData(cwIdx)
% Create and store a new transport block for transmission 创建并存储一个新的传输块用于传输
trBlk = randi([0 1],trBlkSizes(cwIdx),1);
setTransportBlock(encodeDLSCH,trBlk,cwIdx-1,harqEntity.HARQProcessID);
% If the previous RV sequence ends without successful decoding, 如果之前的 RV 序列没有成功解码就结束了,
% flush the soft buffer explicitly 刷新软缓冲区
if harqEntity.SequenceTimeout(cwIdx)
resetSoftBuffer(decodeDLSCH,cwIdx-1,harqEntity.HARQProcessID);
end
end
end
DL-SCH编码
对DL-SCH传输块进行编码
codedTrBlock = encodeDLSCH(pdsch.Modulation,pdsch.NumLayers,pdschInfo.G, ...
harqEntity.RedundancyVersion,harqEntity.HARQProcessID);
PDSCH编码
生成PDSCH符号
modOut = nrPDSCH(carrier,pdsch,codedTrBlock);
AWGN信道
添加高斯白噪声
rxSig = awgn(modOut,SNRdB);
PDSCH解调
软解调接收到的符号
rxLLR = nrPDSCHDecode(carrier,pdsch,rxSig,noiseVar);
DL-SCH解码
应用DL-SCH解码
decodeDLSCH.TransportBlockLength = trBlkSizes;
[decbits,blkerr] = decodeDLSCH(rxLLR,pdsch.Modulation,pdsch.NumLayers, ...
harqEntity.RedundancyVersion,harqEntity.HARQProcessID);
结果
存储结果计算BLER
% Store values to calculate throughput (only for active transport blocks)
if(any(trBlkSizes ~= 0))
numRxBits = [numRxBits trBlkSizes.*(1-blkerr)];
txedTrBlkSizes = [txedTrBlkSizes trBlkSizes];
end
if blkerr
numBlkErr = numBlkErr + 1;
end
HARQ进程更新
用CRC错误更新当前的HARQ进程,然后前进到下一个进程。 该步骤更新HARQ实体中与活动HARQ进程相关的信息。
statusReport = updateAndAdvance(harqEntity,blkerr,trBlkSizes,pdschInfo.G);
显示有关当前解码的尝试信息
disp("Slot "+(nTrBlk)+". "+statusReport);
end % for nTrBlk = 1:noTransportBlocks
Slot 1. HARQ Proc 0: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 2. HARQ Proc 1: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 3. HARQ Proc 2: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 4. HARQ Proc 3: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 5. HARQ Proc 4: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 6. HARQ Proc 5: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 7. HARQ Proc 6: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 8. HARQ Proc 7: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 9. HARQ Proc 8: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 10. HARQ Proc 9: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 11. HARQ Proc 10: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 12. HARQ Proc 11: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 13. HARQ Proc 12: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 14. HARQ Proc 13: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 15. HARQ Proc 14: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 16. HARQ Proc 15: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 17. HARQ Proc 0: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 18. HARQ Proc 1: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 19. HARQ Proc 2: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 20. HARQ Proc 3: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 21. HARQ Proc 4: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 22. HARQ Proc 5: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 23. HARQ Proc 6: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 24. HARQ Proc 7: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 25. HARQ Proc 8: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 26. HARQ Proc 9: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 27. HARQ Proc 10: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 28. HARQ Proc 11: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 29. HARQ Proc 12: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 30. HARQ Proc 13: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 31. HARQ Proc 14: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 32. HARQ Proc 15: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 33. HARQ Proc 0: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 34. HARQ Proc 1: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 35. HARQ Proc 2: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 36. HARQ Proc 3: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 37. HARQ Proc 4: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 38. HARQ Proc 5: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 39. HARQ Proc 6: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 40. HARQ Proc 7: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 41. HARQ Proc 8: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 42. HARQ Proc 9: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 43. HARQ Proc 10: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 44. HARQ Proc 11: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 45. HARQ Proc 12: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 46. HARQ Proc 13: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 47. HARQ Proc 14: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 48. HARQ Proc 15: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 49. HARQ Proc 0: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 50. HARQ Proc 1: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 51. HARQ Proc 2: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 52. HARQ Proc 3: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 53. HARQ Proc 4: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 54. HARQ Proc 5: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 55. HARQ Proc 6: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 56. HARQ Proc 7: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 57. HARQ Proc 8: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 58. HARQ Proc 9: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 59. HARQ Proc 10: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 60. HARQ Proc 11: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 61. HARQ Proc 12: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 62. HARQ Proc 13: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 63. HARQ Proc 14: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 64. HARQ Proc 15: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 65. HARQ Proc 0: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 66. HARQ Proc 1: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 67. HARQ Proc 2: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 68. HARQ Proc 3: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 69. HARQ Proc 4: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 70. HARQ Proc 5: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 71. HARQ Proc 6: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 72. HARQ Proc 7: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 73. HARQ Proc 8: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 74. HARQ Proc 9: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 75. HARQ Proc 10: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 76. HARQ Proc 11: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 77. HARQ Proc 12: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 78. HARQ Proc 13: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 79. HARQ Proc 14: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 80. HARQ Proc 15: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 81. HARQ Proc 0: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 82. HARQ Proc 1: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 83. HARQ Proc 2: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 84. HARQ Proc 3: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 85. HARQ Proc 4: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 86. HARQ Proc 5: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 87. HARQ Proc 6: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 88. HARQ Proc 7: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 89. HARQ Proc 8: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 90. HARQ Proc 9: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 91. HARQ Proc 10: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 92. HARQ Proc 11: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 93. HARQ Proc 12: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 94. HARQ Proc 13: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 95. HARQ Proc 14: CW0: Retransmission #1 passed (RV=2,CR=0.481509).
Slot 96. HARQ Proc 15: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 97. HARQ Proc 0: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 98. HARQ Proc 1: CW0: Initial transmission failed (RV=0,CR=0.481509).
Slot 99. HARQ Proc 2: CW0: Initial transmission passed (RV=0,CR=0.481509).
Slot 100. HARQ Proc 3: CW0: Initial transmission failed (RV=0,CR=0.481509).
BLER结果
计算BLER和吞吐量(成功接收传输块的百分比)。若需要提供具有统计意义的结果,请对更多传输块运行此模拟
maxThroughput = sum(txedTrBlkSizes); % Maximum possible throughput
totalNumRxBits = sum(numRxBits,2); % Number of successfully received bits
disp("Block Error Rate: "+string(numBlkErr/noTransportBlocks))
Block Error Rate: 0.42
disp("Throughput: " + string(totalNumRxBits*100/maxThroughput) + "%")
Throughput: 58%