Skip to content

Code runs much faster now. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.m~
.DS_Store
*.bak
*.asv
36 changes: 21 additions & 15 deletions NRDemodulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,35 @@
end

function ModulationOrder = get.ModulationOrder(obj)
if strcmp(obj.Modulation, 'BPSK')
Modulation_ = obj.Modulation;

if strcmp(Modulation_, 'BPSK')
ModulationOrder = 2;
elseif strcmp(obj.Modulation, 'QPSK')
elseif strcmp(Modulation_, 'QPSK')
ModulationOrder = 4;
elseif strcmp(obj.Modulation, '16QAM')
elseif strcmp(Modulation_, '16QAM')
ModulationOrder = 16;
elseif strcmp(obj.Modulation, '64QAM')
elseif strcmp(Modulation_, '64QAM')
ModulationOrder = 64;
elseif strcmp(obj.Modulation, '256QAM')
elseif strcmp(Modulation_, '256QAM')
ModulationOrder = 256;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Unsupported modulation');
end
end

function Q_m = get.Q_m(obj)
if strcmp(obj.Modulation, 'BPSK')
Modulation_ = obj.Modulation;

if strcmp(Modulation_, 'BPSK')
Q_m = 1;
elseif strcmp(obj.Modulation, 'QPSK')
elseif strcmp(Modulation_, 'QPSK')
Q_m = 2;
elseif strcmp(obj.Modulation, '16QAM')
elseif strcmp(Modulation_, '16QAM')
Q_m = 4;
elseif strcmp(obj.Modulation, '64QAM')
elseif strcmp(Modulation_, '64QAM')
Q_m = 6;
elseif strcmp(obj.Modulation, '256QAM')
elseif strcmp(Modulation_, '256QAM')
Q_m = 8;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Unsupported modulation');
Expand All @@ -66,15 +70,17 @@
methods(Access = protected)

function setupImpl(obj)
if strcmp(obj.Modulation, 'BPSK')
Modulation_ = obj.Modulation;

if strcmp(Modulation_, 'BPSK')
obj.hMod = comm.PSKDemodulator('ModulationOrder',2,'PhaseOffset',pi/4,'BitOutput',true,'DecisionMethod',obj.DecisionMethod,'Variance',obj.Variance);
elseif strcmp(obj.Modulation, 'QPSK')
elseif strcmp(Modulation_, 'QPSK')
obj.hMod = comm.PSKDemodulator('ModulationOrder',4,'PhaseOffset',pi/4,'BitOutput',true,'DecisionMethod',obj.DecisionMethod,'Variance',obj.Variance,'SymbolMapping','Custom','CustomSymbolMapping',[0 2 3 1]);
elseif strcmp(obj.Modulation, '16QAM')
elseif strcmp(Modulation_, '16QAM')
obj.hMod = comm.RectangularQAMDemodulator('ModulationOrder',16,'BitOutput',true,'NormalizationMethod','Average power','DecisionMethod',obj.DecisionMethod,'Variance',obj.Variance,'SymbolMapping','Custom','CustomSymbolMapping',[11,10,14,15,9,8,12,13,1,0,4,5,3,2,6,7]);
elseif strcmp(obj.Modulation, '64QAM')
elseif strcmp(Modulation_, '64QAM')
obj.hMod = comm.RectangularQAMDemodulator('ModulationOrder',64,'BitOutput',true,'NormalizationMethod','Average power','DecisionMethod',obj.DecisionMethod,'Variance',obj.Variance,'SymbolMapping','Custom','CustomSymbolMapping',[47,46,42,43,59,58,62,63,45,44,40,41,57,56,60,61,37,36,32,33,49,48,52,53,39,38,34,35,51,50,54,55,7,6,2,3,19,18,22,23,5,4,0,1,17,16,20,21,13,12,8,9,25,24,28,29,15,14,10,11,27,26,30,31]);
elseif strcmp(obj.Modulation, '256QAM')
elseif strcmp(Modulation_, '256QAM')
obj.hMod = comm.RectangularQAMDemodulator('ModulationOrder',256,'BitOutput',true,'NormalizationMethod','Average power','DecisionMethod',obj.DecisionMethod,'Variance',obj.Variance,'SymbolMapping','Custom','CustomSymbolMapping',[191,190,186,187,171,170,174,175,239,238,234,235,251,250,254,255,189,188,184,185,169,168,172,173,237,236,232,233,249,248,252,253,181,180,176,177,161,160,164,165,229,228,224,225,241,240,244,245,183,182,178,179,163,162,166,167,231,230,226,227,243,242,246,247,151,150,146,147,131,130,134,135,199,198,194,195,211,210,214,215,149,148,144,145,129,128,132,133,197,196,192,193,209,208,212,213,157,156,152,153,137,136,140,141,205,204,200,201,217,216,220,221,159,158,154,155,139,138,142,143,207,206,202,203,219,218,222,223,31,30,26,27,11,10,14,15,79,78,74,75,91,90,94,95,29,28,24,25,9,8,12,13,77,76,72,73,89,88,92,93,21,20,16,17,1,0,4,5,69,68,64,65,81,80,84,85,23,22,18,19,3,2,6,7,71,70,66,67,83,82,86,87,55,54,50,51,35,34,38,39,103,102,98,99,115,114,118,119,53,52,48,49,33,32,36,37,101,100,96,97,113,112,116,117,61,60,56,57,41,40,44,45,109,108,104,105,121,120,124,125,63,62,58,59,43,42,46,47,111,110,106,107,123,122,126,127]);
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Unsupported modulation');
Expand Down
123 changes: 79 additions & 44 deletions NRLDPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@

% K_cb is calculated in Section 5.2.2 of TS38.212
function K_cb = get.K_cb(obj)
if obj.BG == 1
BG_ = obj.BG;

if BG_ == 1
K_cb = 8448;
elseif obj.BG == 2
elseif BG_ == 2
K_cb = 3840;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','BG must be 1 or 2');
Expand All @@ -330,10 +332,14 @@

% C is calculated in Section 5.2.2 of TS38.212
function C = get.C(obj)
if obj.B <= obj.K_cb
B_ = obj.B;
K_cb_ = obj.K_cb;
code_block_L_ = obj.code_block_L;

if B_ <= K_cb_
C = 1;
else
C = ceil(obj.B/(obj.K_cb-obj.code_block_L));
C = ceil(B_/(K_cb_-code_block_L_));
end
end

Expand All @@ -358,10 +364,15 @@

% B_prime is calculated in Section 5.2.2 of TS38.212
function B_prime = get.B_prime(obj)
if obj.B <= obj.K_cb
B_prime = obj.B;
B_ = obj.B;
K_cb_ = obj.K_cb;
C_ = obj.C;
code_block_L_ = obj.code_block_L;

if B_ <= K_cb_
B_prime = B_;
else
B_prime = obj.B + obj.C*obj.code_block_L;
B_prime = B_ + C_*code_block_L_;
end
end

Expand All @@ -372,16 +383,19 @@

% The calculation of K_b is given in Section 5.2.2 of TS38.212.
function K_b = get.K_b(obj)
if obj.BG == 1
BG_ = obj.BG;
K_prime_ = obj.K_prime;

if BG_ == 1
K_b = 22;
elseif obj.BG == 2
elseif BG_ == 2
% TS38.212 uses B rather than K_prime for the comparisons
% below, but both ways give the same answer in all cases
if obj.K_prime > 640
if K_prime_ > 640
K_b = 10;
elseif obj.K_prime > 560
elseif K_prime_ > 560
K_b = 9;
elseif obj.K_prime > 192
elseif K_prime_ > 192
K_b = 8;
else
K_b = 6;
Expand All @@ -398,10 +412,13 @@

% The calculation of K is given in Section 5.2.2 of TS38.212.
function K = get.K(obj)
if obj.BG == 1
K = obj.Z_c*22;
elseif obj.BG == 2
K = obj.Z_c*10;
BG_ = obj.BG;
Z_c_ = obj.Z_c;

if BG_ == 1
K = Z_c_*22;
elseif BG_ == 2
K = Z_c_*10;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Valid values of BG are 1 and 2.');
end
Expand All @@ -424,10 +441,13 @@

% The calculation of N is given in Section 5.3.2 of TS38.212.
function N = get.N(obj)
if obj.BG == 1
N = obj.Z_c*66;
elseif obj.BG == 2
N = obj.Z_c*50;
BG_ = obj.BG;
Z_c_ = obj.Z_c;

if BG_ == 1
N = Z_c_*66;
elseif BG_ == 2
N = Z_c_*50;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Valid values of BG are 1 and 2.');
end
Expand All @@ -449,8 +469,11 @@
end

function CBGTI_flags = get.CBGTI_flags(obj)
CBGTI_flags = ones(1,obj.C);
CBGTI_flags(obj.CBGTI(obj.CBGTI<obj.C)+1) = 0;
C_ = obj.C;
CBGTI_ = obj.CBGTI;

CBGTI_flags = ones(1,C_);
CBGTI_flags(CBGTI_(CBGTI_<C_)+1) = 0;
end

% The calculation of C_prime is given in Section 5.4.2.1 of TS38.212.
Expand All @@ -460,16 +483,23 @@

% The calculation of E_r is given in Section 5.4.2.1 of TS38.212.
function E_r = get.E_r(obj)
C_ = obj.C;
C_prime_ = obj.C_prime;
CBGTI_flags_ = obj.CBGTI_flags;
G_ = obj.G;
N_L_ = obj.N_L;
Q_m_ = obj.Q_m;

j=0;
E_r = zeros(1,obj.C);
for r = 0:obj.C-1
if obj.CBGTI_flags(r+1) == 0
E_r = zeros(1,C_);
for r = 0:C_-1
if CBGTI_flags_(r+1) == 0
E_r(r+1) = 0;
else
if j <= obj.C_prime-mod(obj.G/(obj.N_L*obj.Q_m),obj.C_prime)-1
E_r(r+1) = obj.N_L*obj.Q_m*floor(obj.G/(obj.N_L*obj.Q_m*obj.C_prime));
if j <= C_prime_-mod(G_/(N_L_*Q_m_),C_prime_)-1
E_r(r+1) = N_L_*Q_m_*floor(G_/(N_L_*Q_m_*C_prime_));
else
E_r(r+1) = obj.N_L*obj.Q_m*ceil(obj.G/(obj.N_L*obj.Q_m*obj.C_prime));
E_r(r+1) = N_L_*Q_m_*ceil(G_/(N_L_*Q_m_*C_prime_));
end
j = j + 1;
end
Expand All @@ -478,27 +508,32 @@

% The calculation of k_0 is given in Table 5.4.2.1-2 of TS38.212.
function k_0 = get.k_0(obj)
if obj.BG == 1
if obj.rv_id == 0
BG_ = obj.BG;
rv_id_ = obj.rv_id;
N_cb_ = obj.N_cb;
Z_c_ = obj.Z_c;

if BG_ == 1
if rv_id_ == 0
k_0 = 0;
elseif obj.rv_id == 1
k_0 = floor((17*obj.N_cb)/(66*obj.Z_c))*obj.Z_c;
elseif obj.rv_id == 2
k_0 = floor((33*obj.N_cb)/(66*obj.Z_c))*obj.Z_c;
elseif obj.rv_id == 3
k_0 = floor((56*obj.N_cb)/(66*obj.Z_c))*obj.Z_c;
elseif rv_id_ == 1
k_0 = floor((17*N_cb_)/(66*Z_c_))*Z_c_;
elseif rv_id_ == 2
k_0 = floor((33*N_cb_)/(66*Z_c_))*Z_c_;
elseif rv_id_ == 3
k_0 = floor((56*N_cb_)/(66*Z_c_))*Z_c_;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Valid values of rv_id are 0, 1, 2 and 3.')
end
elseif obj.BG == 2
if obj.rv_id == 0
elseif BG_ == 2
if rv_id_ == 0
k_0 = 0;
elseif obj.rv_id == 1
k_0 = floor((13*obj.N_cb)/(50*obj.Z_c))*obj.Z_c;
elseif obj.rv_id == 2
k_0 = floor((25*obj.N_cb)/(50*obj.Z_c))*obj.Z_c;
elseif obj.rv_id == 3
k_0 = floor((43*obj.N_cb)/(50*obj.Z_c))*obj.Z_c;
elseif rv_id_ == 1
k_0 = floor((13*N_cb_)/(50*Z_c_))*Z_c_;
elseif rv_id_ == 2
k_0 = floor((25*N_cb_)/(50*Z_c_))*Z_c_;
elseif rv_id_ == 3
k_0 = floor((43*N_cb_)/(50*Z_c_))*Z_c_;
else
error('ldpc_3gpp_matlab:UnsupportedParameters','Valid values of rv_id are 0, 1, 2 and 3.')
end
Expand Down
Loading