clear clc % lab 5 2026 tbs=56; %transport block size 56 txdata1=ones(tbs,1); % input data of UE %% Add CRC poly='24A'; % CRC polynom 6, 11, 16, 24A, 24B, 24C txdata1CRC=nrCRCEncode(txdata1,poly,0); %% Encode E=1000; %864 %rate matching sequence length txdata1CRCpolar=nrPolarEncode(txdata1CRC,E); bgn=2; %Base graph number, specified as 1 or 2. The values correspond to the two base graphs defined in TS 38.212 Section 5.3.2 txdata1CRCLDPC=nrLDPCEncode(txdata1CRC,bgn); %% Rate match txdata1CRCpolarRM=nrRateMatchPolar(txdata1CRCpolar,tbs,E); rv=1; %Redundancy version, specified as an integer from 0 to 3. mod="QPSK"; %modulation: 'pi/2-BPSK', 'QPSK', '16QAM', '64QAM', '256QAM', or '1024QAM' nLayers=1; %Number of transmission layers associated with the transport block, % specified as an integer from 1 to 4. Nref=1; %Limited buffer rate matching, specified as a positive integer. % Nref is defined in TS 38.212 Section 5.4.2.1. txdata1CRCLDPCRM=nrRateMatchLDPC(txdata1CRCLDPC,E,rv,mod,nLayers,Nref); %% Modulate txdata1CRCpolarRMmod=nrSymbolModulate(txdata1CRCpolarRM,mod); txdata1CRCLDPCRMmod=nrSymbolModulate(txdata1CRCLDPCRM,mod); %% Channel K=length(txdata1CRC); EbNo=16; %dB % Parameters R = K/E; % Effective code rate switch mod case 'pi/2-BPSK' bps=1; %bits per symbol, 1 for BPSK, 2 for QPSK, ... case 'QPSK' bps=2; case '16QAM' bps=4; case '64QAM' bps=6; case '256QAM' bps=8; case '1024QAM' bps=10; end EsNo = EbNo + 10*log10(bps); snrdB = EsNo + 10*log10(R); % in dB noiseVar = 1./(10.^(snrdB/10)); % Channel spec chan = comm.AWGNChannel('NoiseMethod','Variance','Variance',noiseVar); % processing rxdata1CRCpolarRMmod=chan(txdata1CRCpolarRMmod); rxdata1CRCLDPCRMmod=chan(txdata1CRCLDPCRMmod); %% Demodulate rxdata1CRCpolarRM=nrSymbolDemodulate(rxdata1CRCpolarRMmod, mod); rxdata1CRCLDPCRM=nrSymbolDemodulate(rxdata1CRCLDPCRMmod,mod); %% Rate recover N=512; %length of polar-encoded msg in bits, as power of 2 rxdata1CRCpolar=nrRateRecoverPolar(rxdata1CRCpolarRM,K,N); R=7/8;% target code rate numCB=1; %Number of scheduled code block segments, specified as a positive % integer. numCB is less than or equal to the number of code block segments % for a transport block. rxdata1CRCLDPC=nrRateRecoverLDPC(rxdata1CRCLDPCRM,tbs,R,rv,mod,nLayers,numCB,Nref); %% Decode L=8; % successive-cancellation list decoder of length L rxdata1CRCp=nrPolarDecode(rxdata1CRCpolar,K,E,L); rxdata1CRCL=nrLDPCDecode(rxdata1CRCLDPC,bgn,1); %% Remove CRC [rxdata1p,errp]=nrCRCDecode(rxdata1CRCp,poly); [rxdata1L,errL]=nrCRCDecode(rxdata1CRCL,poly); %%