📄 ldpc_encode.m
字号:
function [out] = ldpc_encode(in,G,q)
[k,n] = size(G);
if q==2 % binary case
out = mod((in)*G,2);
else
M=log2(q); % GFq exponent
[tuple power] = gftuple([-1:2^M-2]', M, 2);
alpha = tuple * 2.^[0 : M - 1]';
beta(alpha + 1) = 0 : 2^M - 1;
ll = ones(1,n)*(-Inf); % will store results here, initialize with all zeros (exp form)
ll = ll';
for i=1:k % multiply each row of G by the input symbol in GFq
ii = power(beta(in(i)+1)+1); % get expon. representation of in(i)
ii = repmat(ii,[length(ll),1]);
jj = power(beta(G(i,:)+1)+1);% same for the row of G
kk = gfmul(ii,jj,tuple); % this is exponential representation of the product
ll = gfadd(ll,kk,tuple);
end
out=zeros(size(ll));
nzindx = find(isfinite(ll));
out(nzindx) = alpha(ll(nzindx)+2);
out = out(:);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -