📄 ldpcencode.m
字号:
% LDPC encoder.
% Prasanna Sethuraman, March-2004
function x = ldpcEncode(u, H, B, L, U) % matlab passes these arguments by reference.
% u : input vector L x 1
% x : code word N x 1
% H : Parity Check matrix LxN / (N-L)xN
if u==0
[dummy,N] = size(H);
x=zeros(1,N);
return;
end;
[M,N] = size(H);
K = N-M;
% Generate Code word
% x = [c s] s : 1 x K and c : 1 x (N-K)
% H = [A B] H : (N-K) x N
% Hx' = Ac' + Bs' A : (N-K) x (N-K) and B : (N-K) x K
% c = inv(A)*Bs' since Hx' is zero for a code vector x
% A = gf(full(H(:,1:N-K)),1);
% c = inv(A) * H(:,N-K+1:N)*u'; % No check is made to avoid the problem of non existence of inv(B)
%
% x=[s c'];
% Method below is not used due to problems with matlab's Gaussian Elimination
% Encoding: H = [I P] I : (N-L)x(N-L) and P: (N-L)xL
% G = [P' I] P': Lx(N-L) and I: LxL
% x = G'u
% Parity Chk: Hx = 0
% x = mod(G'*u,2);
% Method described in Neal's documentation
% U = sparse(M,M); L = sparse(M,M);
%
% F = H;
% for i=1:M
% j=i;
% while(H(j,j)==0 & j<=M)
% j=j+1;
% end;
% F(:,[i j])=F(:,[j i]); % Swap columns
% F([i j],:)=F([j i],:); % Swap rows
% H(:,[i j])=H(:,[j i]); % Swap columns
% H([i j],:)=H([j i],:); % Swap rows
% U(1:i,i)=F(1:i,i);
% L(i+1:M,i)=F(i+1:M,i);
% end;
%
% B = H(:,M+1:N);
z = B*u;
y=lsolve(L,z);
c=usolve(U,y);
% c=Ainv*z;
% a nasty trick
str = struct(c); % column vector
x = [u; double(str.x)];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -