Comparing the LDPC results with NeoRadium

% To save a new set of files, you need to set the saveFiles to true.
 
saveFiles = true;
outPath = fileparts(matlab.desktop.editor.getActiveFilename);
disp(outPath);
/Users/shahab/code/Fireball/OpenSource/onGithub/Tests/Wireless/NewProject/OnGit/neoradium/Playground/CompareWithMatlab/LDPC/MatlabFiles
rng(210); % Set RNG state for repeatability
 
A = 10000; % Transport block length, positive integer
rate = 449/1024; % Target code rate, 0<R<1
rv = 0; % Redundancy version, 0-3
modulation = 'QPSK'; % Modulation scheme, QPSK, 16QAM, 64QAM, 256QAM
nlayers = 1; % Number of layers, 1-4 for a transport block
% Based on the selected transport block length and target coding rate,
% DL-SCH coding parameters are determined using the
% <docid:5g_ref#mw_function_nrDLSCHInfo nrDLSCHInfo> function.
 
% DL-SCH coding parameters
cbsInfo = nrDLSCHInfo(A,rate);
disp('DL-SCH coding parameters')
DL-SCH coding parameters
disp(cbsInfo)
CRC: '24A' L: 24 BGN: 1 C: 2 Lcb: 24 F: 244 Zc: 240 K: 5280 N: 15840
if saveFiles
% Random transport block data generation
 
% Use the following to create random input instead
% in = randi([0 1],A,1,'int8');
% save(strcat(outPath,'/in.mat'),'in');
else
in=load(strcat(outPath,'/in.mat')).in;
end
size(in)
ans = 1×2
10000 1
% Transport block CRC attachment
tbIn = nrCRCEncode(in,cbsInfo.CRC);
size(tbIn)
ans = 1×2
10024 1
% Code block segmentation and CRC attachment
cbsIn = nrCodeBlockSegmentLDPC(tbIn,cbsInfo.BGN);
if saveFiles
save(strcat(outPath,'/cbsIn.mat'),'cbsIn');
end
size(cbsIn)
ans = 1×2
5280 2
% LDPC encoding
enc = nrLDPCEncode(cbsIn,cbsInfo.BGN);
if saveFiles
save(strcat(outPath,'/enc.mat'),'enc');
end
size(enc)
ans = 1×2
15840 2
% Rate matching and code block concatenation
outlen = ceil(A/rate);
chIn = nrRateMatchLDPC(enc,outlen,rv,modulation,nlayers);
if saveFiles
save(strcat(outPath,'/chIn.mat'),'chIn');
end
size(chIn)
ans = 1×2
22808 1
%% Channel
%
% A simple bipolar channel with no noise is used for this example.
% With the full PDSCH or PUSCH processing, one can consider fading
% channels, AWGN and other RF impairments as well.
 
chOut = double(1-2*(chIn));
size(chIn)
ans = 1×2
22808 1
%% Receive Processing using LDPC Decoding
%
% The receive end processing for the DL-SCH channel comprises of
% the corresponding dual operations to the transmit end that include
%
% * Rate recovery
% * LDPC decoding
% * Code block desegmentation and CRC decoding
% * Transport block CRC decoding
%
% Each of these stages is performed by a function as shown next.
 
% Rate recovery
raterec = nrRateRecoverLDPC(chOut,A,rate,rv,modulation,nlayers);
if saveFiles
save(strcat(outPath,'/raterec.mat'),'raterec');
end
size(raterec)
ans = 1×2
15840 2
% LDPC decoding
decBits = nrLDPCDecode(raterec,cbsInfo.BGN,25);
if saveFiles
save(strcat(outPath,'/decBits.mat'),'decBits');
end
size(decBits)
ans = 1×2
5280 2
% Code block desegmentation and CRC decoding
[decBlk,blkErr] = nrCodeBlockDesegmentLDPC(decBits,cbsInfo.BGN,A+cbsInfo.L);
if saveFiles
save(strcat(outPath,'/decBlk.mat'),'decBlk');
end
size(decBlk)
ans = 1×2
10024 1
disp(['CRC error per code-block: [' num2str(blkErr) ']'])
CRC error per code-block: [0 0]
 
% Transport block CRC decoding
[out,tbErr] = nrCRCDecode(decBlk,cbsInfo.CRC);
size(out)
ans = 1×2
10000 1
 
disp(['Transport block CRC error: ' num2str(tbErr)])
Transport block CRC error: 0
disp(['Recovered transport block with no error: ' num2str(isequal(out,in))])
Recovered transport block with no error: 1