% To save a new set of files, you need to set the saveFiles to 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')
disp(cbsInfo)
CRC: '24A'
L: 24
BGN: 1
C: 2
Lcb: 24
F: 244
Zc: 240
K: 5280
N: 15840
% 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');
in=load(strcat(outPath,'/in.mat')).in;
% Transport block CRC attachment
tbIn = nrCRCEncode(in,cbsInfo.CRC);
% Code block segmentation and CRC attachment
cbsIn = nrCodeBlockSegmentLDPC(tbIn,cbsInfo.BGN);
save(strcat(outPath,'/cbsIn.mat'),'cbsIn');
enc = nrLDPCEncode(cbsIn,cbsInfo.BGN);
save(strcat(outPath,'/enc.mat'),'enc');
% Rate matching and code block concatenation
chIn = nrRateMatchLDPC(enc,outlen,rv,modulation,nlayers);
save(strcat(outPath,'/chIn.mat'),'chIn');
% 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));
%% 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
% * Code block desegmentation and CRC decoding
% * Transport block CRC decoding
% Each of these stages is performed by a function as shown next.
raterec = nrRateRecoverLDPC(chOut,A,rate,rv,modulation,nlayers);
save(strcat(outPath,'/raterec.mat'),'raterec');
decBits = nrLDPCDecode(raterec,cbsInfo.BGN,25);
save(strcat(outPath,'/decBits.mat'),'decBits');
% Code block desegmentation and CRC decoding
[decBlk,blkErr] = nrCodeBlockDesegmentLDPC(decBits,cbsInfo.BGN,A+cbsInfo.L);
save(strcat(outPath,'/decBlk.mat'),'decBlk');
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);
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