Skip to content

Commit

Permalink
qcldpc
Browse files Browse the repository at this point in the history
  • Loading branch information
linkingmon committed Jun 4, 2019
1 parent 19fac96 commit 51049b4
Show file tree
Hide file tree
Showing 20 changed files with 363 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
verilog
test.m
.vscode
Binary file added BER/NMSqq51.mat
Binary file not shown.
Binary file added BER/NMSqq52.mat
Binary file not shown.
Binary file added BER/NMSqq53.mat
Binary file not shown.
11 changes: 6 additions & 5 deletions QCLDPC1.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
% QCLDPC performance analysis
% modify mydecldpc.decodeSP with mydecldpc.decodeMS or mydecldpc.decodeNMS to run other algorithm

% check the path of the Base graph:
clear all;
bspath = 'C:\Program Files\MATLAB\R2019a\toolbox\5g\5g\+nr5g\+internal\+ldpc\baseGraph';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters
Es = 1; % energy per symbol
max_iter = 15; % max iteration count
bgn = 1; % bbase graph number
C = 1000; % minimun simulation times per SNR
Zc = 32; % lifting size
K = 22*Zc; % message length
K = 22*32; % message length
thres = 100; % minimun error count per SNR
code_rate = 1/2; % code rate
snrdb = [0:0.2:2.6]; % SNR for simultion (in dB)
ber_res = zeros(2,length(snrdb)); % saving BER(bit error rate)
ber_res = zeros(1,length(snrdb)); % saving BER(bit error rate)
rng(0); % set random seed
err_limit = 10e-6; % minimun error rate
running = true;
Expand All @@ -24,7 +24,7 @@

% LDPC encode & decoder setting
encldpc = comm.LDPCEncoder(LDPCParityCheckMatrix);
mydecldpc = mydecoder(LDPCParityCheckMatrix, max_iter, Zc);
mydecldpc = mydecoder(LDPCParityCheckMatrix, max_iter, 32);

% simulate per SNR
for jj = 1:length(snrdb)
Expand Down Expand Up @@ -99,6 +99,7 @@
end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [PCM, P] = getPCM(bgn, info_length, code_rate, bspath)
% Check the size & calculate lifting size
Expand Down
12 changes: 8 additions & 4 deletions QCLDPC.m → QCLDPC2.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
% QCLDPC performance analysis
% modify mydecldpc.decodeSP_layer with mydecldpc.decodeMS_layer to run other algorithm

% check the path of the Base graph:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
bspath = 'C:\Program Files\MATLAB\R2019a\toolbox\5g\5g\+nr5g\+internal\+ldpc\baseGraph';

Expand All @@ -9,7 +11,8 @@
max_iter = 15; % max iteration count
bgn = 1; % bbase graph number
C = 1000; % minimun simulation times per SNR
K = 22*32; % message length
Zc = 32; % lifting size
K = 22*Zc; % message length
thres = 100; % minimun error count per SNR
code_rate = 1/2; % code rate
snrdb = [0:0.2:2.6]; % SNR for simultion (in dB)
Expand All @@ -23,7 +26,7 @@

% LDPC encode & decoder setting
encldpc = comm.LDPCEncoder(LDPCParityCheckMatrix);
mydecldpc = mydecoder(LDPCParityCheckMatrix, max_iter);
mydecldpc = mydecoder(LDPCParityCheckMatrix, max_iter, Zc);

% simulate per SNR
for jj = 1:length(snrdb)
Expand Down Expand Up @@ -67,7 +70,7 @@
chanOut = chan(modOut);
demodOut = pskDemodulator(chanOut);
tic;
ldpcDecOut = mydecldpc.decodeSP(demodOut')';
ldpcDecOut = mydecldpc.decodeSP_layer(demodOut')';
time_cnt = time_cnt + toc;
error_cnt = error_cnt + sum(message ~= ldpcDecOut, 'all');
end
Expand All @@ -81,7 +84,7 @@
modOut = pskModulator(ldpcEncOut);
chanOut = chan(modOut);
demodOut = pskDemodulator(chanOut);
ldpcDecOut = mydecldpc.decodeSP(demodOut')';
ldpcDecOut = mydecldpc.decodeSP_layer(demodOut')';
error_cnt = error_cnt + sum(message ~= ldpcDecOut, 'all');
if error_cnt / K / (C+num) < err_limit
running = false;
Expand All @@ -98,6 +101,7 @@
end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [PCM, P] = getPCM(bgn, info_length, code_rate, bspath)
% Check the size & calculate lifting size
Expand Down
227 changes: 227 additions & 0 deletions QCLDPC4.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
% QCLDPC performance analysis

% check the path of the Base graph:
clear all;
bspath = 'C:\Program Files\MATLAB\R2019a\toolbox\5g\5g\+nr5g\+internal\+ldpc\baseGraph';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters
Es = 1; % energy per symbol
max_iter = 15; % max iteration count
bgn = 1; % bbase graph number
C = 1000; % minimun simulation times per SNR
K = 22*32; % message length
thres = 100; % minimun error count per SNR
code_rate = 1/2; % code rate
snrdb = [0:0.2:2.4]; % SNR for simultion (in dB)
ber_res = zeros(1,length(snrdb)); % saving BER(bit error rate)
rng(0); % set random seed
err_limit = 10e-6; % minimun error rate
running = true;
s = 1; w = 7; f = 2;
ep = 2^(w - s - f) - 1;
ntBP = numerictype(s,w,f); % numeric type

% initailize QCLDPC PCM(partiy check matrix)
[LDPCParityCheckMatrix, B] = getPCM(bgn, K, code_rate, bspath);

% LDPC encode & decoder setting
encldpc = comm.LDPCEncoder(LDPCParityCheckMatrix);
mydecldpc = mydecoder(LDPCParityCheckMatrix, max_iter, 32);

% simulate per SNR
for jj = 1:length(snrdb)

snr = 10^(snrdb(jj)/10);

% apply PSK modulator and demodulator
pskModulator = comm.PSKModulator(...
'ModulationOrder', 4,...
'BitInput', true, ...
'PhaseOffset', pi / 4, ...
'SymbolMapping', 'Custom', ...
'CustomSymbolMapping', [0 2 3 1]);
pskDemodulator = comm.PSKDemodulator(...
'ModulationOrder', 4, ...
'BitOutput', true, ...
'PhaseOffset', pi /4 , ...
'SymbolMapping', 'Custom', ...
'CustomSymbolMapping', [0 2 3 1], ...
'DecisionMethod', 'Approximate log-likelihood ratio', ...
'Variance', Es/snr);
chan = comm.AWGNChannel(...
'NoiseMethod', 'Variance',...
'Variance', Es/snr);

% Get the constellation
cacheBitInput = pskModulator.BitInput;
pskModulator.BitInput = false;
constellation = pskModulator((0:pskModulator.ModulationOrder-1)');
release(pskModulator);
pskModulator.BitInput = cacheBitInput;

error_cnt_quan = 0;
time_cnt = 0;

% iterate C times
for ii = 1:C
message = randi([0, 1], K, 1);
ldpcEncOut = encldpc(message);
modOut = pskModulator(ldpcEncOut);
chanOut = chan(modOut);
demodOut = pskDemodulator(chanOut);
tic;
ldpcDecOut_quan = mydecldpc.decodeNMSq(demodOut', 0.75, ntBP)';
time_cnt = time_cnt + toc;
error_cnt_quan = error_cnt_quan + sum(message ~= ldpcDecOut_quan, 'all');
end

% iterate to minimun error count
num = 0;
while error_cnt_quan < thres
num = num + 1;
message = randi([0, 1], K, 1);
ldpcEncOut = encldpc(message);
modOut = pskModulator(ldpcEncOut);
chanOut = chan(modOut);
demodOut = pskDemodulator(chanOut);
tic;
ldpcDecOut_quan = mydecldpc.decodeNMSq(demodOut', 0.75, ntBP)';
time_cnt = time_cnt + toc;
error_cnt_quan = error_cnt_quan + sum(message ~= ldpcDecOut_quan, 'all');
end

% calculate BER & show
ber_res(1,jj) = error_cnt_quan / K / (C+num);
fprintf("(MAT) BER is %.5f at snr %0.1fdB spending %03.2fs\n", ber_res(1,jj), snrdb(jj), time_cnt);

if ~running
break;
end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [PCM, P] = getPCM(bgn, info_length, code_rate, bspath)
% Check the size & calculate lifting size
% Base graph 1 is 46 * 68
% Base graph 2 is 42 * 52
if bgn == 1
if mod(info_length, 22) ~= 0
error("InValid data length %d, it must be mutiple of 22 for base graph 1", info_length)
end
Zc = info_length / 22;
elseif bgn == 2
if mod(info_length, 10) ~= 0
error("InValid data length %d, it must be mutiple of 10 for base graph 2", info_length)
end
Zc = info_length / 10;
else
error("InValid index: No base graph number %d", bgn)
end

% load base graph
persistent bgs
if isempty(bgs)
bgs = coder.load(bspath);
end

% Get lifting set number
ZSets = {[2 4 8 16 32 64 128 256],... % Set 1
[3 6 12 24 48 96 192 384],... % Set 2
[5 10 20 40 80 160 320],... % Set 3
[7 14 28 56 112 224],... % Set 4
[9 18 36 72 144 288],... % Set 5
[11 22 44 88 176 352],... % Set 6
[13 26 52 104 208],... % Set 7
[15 30 60 120 240]}; % Set 8

for setIdx = 1:8
if any(Zc==ZSets{setIdx})
break;
end
end

switch bgn
case 1
switch setIdx
case 1
V = bgs.BG1S1;
case 2
V = bgs.BG1S2;
case 3
V = bgs.BG1S3;
case 4
V = bgs.BG1S4;
case 5
V = bgs.BG1S5;
case 6
V = bgs.BG1S6;
case 7
V = bgs.BG1S7;
otherwise % 8
V = bgs.BG1S8;
end
switch code_rate
case 1/2
V = V(1:24, 1:46);
case 2/3
V = V(1:13, 1:35);
case 2/5
V = V(1:35, 1:57);
case 1/3
V = V;
otherwise
error("Not supporting code rate")
end
otherwise % bgn = 2
switch setIdx
case 1
V = bgs.BG2S1;
case 2
V = bgs.BG2S2;
case 3
V = bgs.BG2S3;
case 4
V = bgs.BG2S4;
case 5
V = bgs.BG2S5;
case 6
V = bgs.BG2S6;
case 7
V = bgs.BG2S7;
otherwise % 8
V = bgs.BG2S8;
end
switch code_rate
case 1/2
V = V(1:12, 1:22);
case 1/3
V = V(1:22, 1:32);
case 1/5
V = V;
otherwise
error("Not supporting code rate")
end
end

% Get shift values matrix & construct PCM
P = nr5g.internal.ldpc.calcShiftValues(V,Zc);

% construct Full PCM
[row, col] = size(P);
PCM = zeros(row*Zc, col*Zc);
for ii = 1 : row
for jj = 1 : col
if P(ii,jj) ~= -1
row_from = (ii-1)*Zc + 1;
row_to = ii*Zc;
col_from = (jj-1)*Zc + 1;
col_to = jj*Zc;
PCM(row_from:row_to, col_from:col_to) = circshift(eye(Zc), P(ii,jj), 2);
end
end
end

PCM = sparse(PCM);
end

12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#### Simple simulation over QCLDPC decoding
#### Simulation over QCLDPC decoding

1. Sum-product & Min-sum & Normalize-MS<br>
![alt text](https://github.com/linkingmon/QCLDPC-analysis-MATLAB-/blob/master/figure/myplot.PNG)
2. Layered-MS & MS<br>
![alt text](https://github.com/linkingmon/QCLDPC-analysis-MATLAB-/blob/master/figure/myplot2.PNG)
3. Layered-SP & SP<br>
![alt text](https://github.com/linkingmon/QCLDPC-analysis-MATLAB-/blob/master/figure/myplot3.PNG)
1. (QCLDPC1/myplot1) 'Sum product' & 'Min sum' & 'Normalize MS'<br>
2. (QCLDPC2/myplot2) 'Layered MS' & 'Flooded MS'<br>
3. (QCLDPC2/myplot3) 'Layered SP' & 'Flooded SP'<br>
4. (QCLDPC4/myplot4) 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) double'<br>
4 changes: 4 additions & 0 deletions figure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1. BER-SNR of 'Sum product' & 'Min sum' & 'Normalize MS'<br>
2. BER-SNR of 'Layered MS' & 'Flooded MS'<br>
3. BER-SNR of 'Layered SP' & 'Flooded SP'<br>
4. BER-SNR of 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) fixed-point(5,1)' & 'NMS(0.75) double'<br>
Binary file removed figure/myplot.PNG
Binary file not shown.
Binary file added figure/myplot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figure/myplot2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figure/myplot3.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figure/myplot4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 51049b4

Please sign in to comment.