-
Notifications
You must be signed in to change notification settings - Fork 5
/
ldpcencode.m
33 lines (26 loc) · 890 Bytes
/
ldpcencode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%- Coded By,
%Ganeshaanand (Rishi) Balasubramanian
%MASc. Electrical and Computer Engineering
%Dalhousie University
%2018 - 2022
%------------------------------%----------------------------------%-----------------------------------%
%------------------------------Linear Encoder for LDPC-----------------------%
function p=ldpcencode(H,msg)
[m, n] = size(H);
% Find the 'gap' length
g = m - find(H(:,end),1, 'first');
% Extracting the submatrices A, B, C, D, E and T
A = H(1:m-g,1:n-m);
B = H(1:m-g,n-m+1:n-m+g);
T = H(1:m-g,n-m+g+1:end);
C = H(m-g+1:end,1:n-m);
D = H(m-g+1:end,n-m+1:n-m+g);
E = H(m-g+1:end,n-m+g+1:end);
invT = inv(T);
invD = inv(D);
%From Cu + Dp1 + 0p2 = 0
p1 = mod((-invD * C * msg'), 2);
%p1 = mod((C*msg'), 2);
%From Au + Bp1 + Tp2 = 0
p2 = mod(-invT * (A * (msg') + B * (p1)),2)';
p = [p1' p2];